Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit bced2a9

Browse files
cwlbraamatt-royal
andcommitted
clean up some dependency injection cruft
- make k8s-client get_custom_builder return a complete when when we need it - otherwise lean on the fact that the kpack lifecycle message only calls k8s client you ask for buildpack_infos, obviating a lot of sprawl [#171029528] Co-authored-by: Connor Braa <cbraa@pivotal.io> Co-authored-by: Matt Royal <mroyal@pivotal.io>
1 parent 497126d commit bced2a9

4 files changed

Lines changed: 38 additions & 37 deletions

File tree

lib/cloud_controller/kpack/stager.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ def stage(staging_details)
1818
builder_spec = get_or_create_builder_spec(staging_details)
1919

2020
existing_image = client.get_image(staging_details.package.app.guid, builder_namespace)
21-
if existing_image.nil?
22-
client.create_image(image_resource(staging_details, builder_spec))
23-
else
21+
if existing_image.present?
2422
client.update_image(update_image_resource(existing_image, staging_details, builder_spec))
23+
else
24+
client.create_image(image_resource(staging_details, builder_spec))
2525
end
2626
rescue CloudController::Errors::ApiError => e
2727
build = VCAP::CloudController::BuildModel.find(guid: staging_details.staging_guid)

spec/request/builds_spec.rb

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@
134134
[
135135
OpenStruct.new(name: 'paketo-buildpacks/java'),
136136
OpenStruct.new(name: 'paketo-community/ruby'),
137-
OpenStruct.new(name: 'paketo-buildpacks/httpd'),
138137
]
139138
end
140139
let(:k8s_api_client) { instance_double(Kubernetes::ApiClient) }
@@ -145,13 +144,35 @@
145144
allow(k8s_api_client).to receive(:create_custom_builder)
146145
allow(k8s_api_client).to receive(:get_image)
147146
allow(k8s_api_client).to receive(:get_custom_builder).and_return(Kubeclient::Resource.new({
147+
metadata: {
148+
creationTimestamp: '1/1',
149+
},
148150
spec: {
149151
stack: 'cflinuxfs3-stack',
150152
store: 'cf-buildpack-store',
151-
serviceAccount: 'gcr-service-account'
152-
}
153+
serviceAccount: 'gcr-service-account',
154+
order: [
155+
{ group: [{ id: 'paketo-buildpacks/java' }] },
156+
{ group: [{ id: 'paketo-community/ruby' }] },
157+
],
158+
},
159+
status: {
160+
builderMetadata: [
161+
{ id: 'paketo-buildpacks/java', version: '1.14.0' },
162+
{ id: 'paketo-community/ruby', version: '0.0.11' },
163+
],
164+
stack: {
165+
id: 'org.cloudfoundry.stacks.cflinuxfs3'
166+
},
167+
conditions: [
168+
{
169+
lastTransitionTime: '1/1',
170+
status: 'True',
171+
type: 'Ready',
172+
}
173+
],
174+
},
153175
}))
154-
allow_any_instance_of(VCAP::CloudController::KpackBuildpackListFetcher).to receive(:fetch_all).and_return(k8s_buildpacks)
155176
end
156177

157178
it 'succeeds' do

spec/unit/lib/cloud_controller/diego/lifecycles/lifecycle_provider_spec.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ module VCAP::CloudController
2626

2727
context 'kpack type' do
2828
let(:type) { 'kpack' }
29-
before do
30-
allow_any_instance_of(KpackBuildpackListFetcher).to receive(:fetch_all).and_return([])
31-
end
3229

3330
it 'returns a KpackLifecycle' do
3431
expect(LifecycleProvider.provide(package, message)).to be_a(KpackLifecycle)
@@ -58,9 +55,6 @@ module VCAP::CloudController
5855

5956
context 'kpack type' do
6057
let(:app) { AppModel.make(:kpack) }
61-
before do
62-
allow_any_instance_of(KpackBuildpackListFetcher).to receive(:fetch_all).and_return([])
63-
end
6458

6559
it 'returns a KpackLifecycle' do
6660
expect(LifecycleProvider.provide(package, message)).to be_a(KpackLifecycle)

spec/unit/lib/cloud_controller/kpack/stager_spec.rb

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ module Kpack
2929
creationTimestamp: '2020-06-27T03:13:07Z',
3030
},
3131
spec: {
32+
stack: 'cflinuxfs3-stack',
33+
store: 'cf-buildpack-store',
34+
serviceAccount: 'gcr-service-account',
3235
order: [
3336
{ group: [{ id: 'paketo-community/ruby' }] },
3437
{ group: [{ id: 'paketo-buildpacks/java' }] },
3538
],
36-
stack: 'cflinuxfs3-stack',
3739
},
3840
status: {
3941
builderMetadata: [
@@ -45,6 +47,9 @@ module Kpack
4547
{ id: 'paketo-buildpacks/java', version: '1.14.0' },
4648
{ id: 'paketo-community/ruby', version: '0.0.11' },
4749
],
50+
stack: {
51+
id: 'org.cloudfoundry.stacks.cflinuxfs3'
52+
},
4853
conditions: [
4954
{
5055
lastTransitionTime: '2020-06-27T03:15:46Z',
@@ -76,21 +81,14 @@ module Kpack
7681
details.lifecycle = lifecycle
7782
details
7883
end
79-
let(:staging_message) do
80-
VCAP::CloudController::BuildCreateMessage.new(lifecycle: { data: { buildpacks: [] }, type: 'kpack' })
81-
end
8284
let(:lifecycle) do
83-
VCAP::CloudController::KpackLifecycle.new(package, staging_message)
85+
instance_double(VCAP::CloudController::KpackLifecycle, buildpack_infos: [])
8486
end
8587
let(:package) do
8688
VCAP::CloudController::PackageModel.make(app: VCAP::CloudController::AppModel.make(:kpack))
8789
end
8890
let(:build) { VCAP::CloudController::BuildModel.make(:kpack) }
8991

90-
before do
91-
allow_any_instance_of(::VCAP::CloudController::KpackBuildpackListFetcher).to receive(:fetch_all).and_return([])
92-
end
93-
9492
it 'checks if the image exists' do
9593
allow(client).to receive(:create_image)
9694
expect(client).to receive(:get_image).with(package.app.guid, 'namespace').and_return(nil)
@@ -140,26 +138,13 @@ module Kpack
140138

141139
context 'when specifying buildpacks for a build' do
142140
let(:staging_message) do
143-
VCAP::CloudController::BuildCreateMessage.new(lifecycle: { data: { buildpacks: ['paketo/java'] }, type: 'kpack' })
141+
VCAP::CloudController::BuildCreateMessage.new(lifecycle: { data: { buildpacks: ['paketo-buildpacks/java'] }, type: 'kpack' })
144142
end
145143
let(:lifecycle) do
146144
VCAP::CloudController::KpackLifecycle.new(package, staging_message)
147145
end
148146
let(:package) { VCAP::CloudController::PackageModel.make(app: VCAP::CloudController::AppModel.make(:kpack)) }
149147

150-
before do
151-
allow_any_instance_of(::VCAP::CloudController::KpackBuildpackListFetcher).to receive(:fetch_all).
152-
and_return([OpenStruct.new(name: 'paketo/java')])
153-
allow(client).to receive(:get_custom_builder).with('cf-default-builder', 'namespace').
154-
and_return(Kubeclient::Resource.new({
155-
spec: {
156-
stack: 'cflinuxfs3-stack',
157-
store: 'cf-buildpack-store',
158-
serviceAccount: 'gcr-service-account'
159-
}
160-
}))
161-
end
162-
163148
it 'creates a custom builder' do
164149
expect(client).to receive(:create_custom_builder).with(Kubeclient::Resource.new({
165150
metadata: {
@@ -177,11 +162,12 @@ module Kpack
177162
stack: 'cflinuxfs3-stack',
178163
store: 'cf-buildpack-store',
179164
order: [
180-
{ group: [{ id: 'paketo/java' }] },
165+
{ group: [{ id: 'paketo-buildpacks/java' }] },
181166
],
182167
}
183168
}))
184169
expect(client).to receive(:create_image)
170+
185171
stager.stage(staging_details)
186172
end
187173

0 commit comments

Comments
 (0)