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

Commit b0761a9

Browse files
committed
kpack lifecycle test fixups
[#171029528] Authored-by: Connor Braa <cbraa@pivotal.io>
1 parent 66cf968 commit b0761a9

6 files changed

Lines changed: 42 additions & 55 deletions

File tree

app/fetchers/kpack_buildpack_list_fetcher.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
require 'cloud_controller/paging/sequel_paginator'
22
require 'cloud_controller/paging/paginated_result'
33
require 'fetchers/null_filter_query_generator'
4+
require 'messages/buildpacks_list_message'
45

56
module VCAP::CloudController
67
class KpackBuildpackListFetcher
7-
def fetch_all(message)
8+
def fetch_all(message=EmptyBuildpackListMessage)
89
staging_namespace = VCAP::CloudController::Config.config.kpack_builder_namespace
910
default_builder = k8s_api_client.get_custom_builder('cf-default-builder', staging_namespace)
1011

app/messages/buildpacks_list_message.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ def valid_order_by_values
2626
super << :position
2727
end
2828
end
29+
30+
EmptyBuildpackListMessage = BuildpacksListMessage.from_params({}).freeze
2931
end

app/messages/list_message.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'active_model'
22
require 'messages/validators'
33
require 'messages/base_message'
4+
require 'cloud_controller/paging/pagination_options'
45

56
module VCAP::CloudController
67
class ListMessage < BaseMessage

lib/cloud_controller/diego/lifecycles/kpack_lifecycle.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def buildpacks_to_use
5151
def requested_and_available_buildpacks(buildpacks_to_use)
5252
# TODO: extract a common way to get the unfiltered list of buildpacks that can then have filters applied if needed?
5353
# TODO: Don't reach out to k8s unless buildpacks are requested
54-
available_buildpack_names = KpackBuildpackListFetcher.new.fetch_all(BuildpacksListMessage.from_params({})).map(&:name)
54+
available_buildpack_names = KpackBuildpackListFetcher.new.fetch_all.map(&:name)
5555

5656
buildpacks_to_use & available_buildpack_names
5757
end

spec/request/builds_spec.rb

Lines changed: 26 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,6 @@
5858
}
5959

6060
before do
61-
stack_name = create_request[:lifecycle][:data][:stack] || VCAP::CloudController::Stack.default.name
62-
stack = VCAP::CloudController::Stack.find(name: stack_name) ||
63-
VCAP::CloudController::Stack.make(name: stack_name)
64-
# putting stack in the App.make call leads to an "App doesn't have a primary key" error
65-
# message from sequel.
66-
process = VCAP::CloudController::ProcessModel.make(app: app_model, memory: 1024, disk_quota: 1536)
67-
process.stack = stack
68-
process.save
6961
allow_any_instance_of(CloudController::Blobstore::UrlGenerator).to receive(:package_download_url).and_return('some-string')
7062
allow_any_instance_of(CloudController::Blobstore::UrlGenerator).to receive(:package_droplet_upload_url).and_return('some-string')
7163
CloudController::DependencyLocator.instance.register(:bbs_stager_client, bbs_stager_client)
@@ -168,6 +160,8 @@
168160
expect(last_response.status).to(eq(201), last_response.body)
169161
expect(parsed_response['lifecycle']['type']).to eq 'kpack'
170162
expect(parsed_response['state']).to eq 'STAGING'
163+
164+
expect(k8s_api_client).to have_received(:create_image)
171165
end
172166

173167
context 'with buildpacks specified' do
@@ -192,57 +186,36 @@
192186
expect(parsed_response['lifecycle']['type']).to eq 'kpack'
193187
expect(parsed_response['lifecycle']['data']['buildpacks']).to eq ['paketo-buildpacks/java', 'paketo-community/ruby']
194188
expect(parsed_response['state']).to eq 'STAGING'
195-
end
196-
end
197-
end
198189

199-
describe 'app kpack lifecycle' do
200-
let(:kpack_app_model) { VCAP::CloudController::AppModel.make(:kpack, space: space) }
201-
let(:package) do
202-
VCAP::CloudController::PackageModel.make(
203-
app_guid: kpack_app_model.guid,
204-
type: VCAP::CloudController::PackageModel::BITS_TYPE,
205-
state: VCAP::CloudController::PackageModel::READY_STATE
206-
)
207-
end
208-
let(:request) do
209-
{
210-
package: {
211-
guid: package.guid
212-
},
213-
}
214-
end
215-
let(:k8s_buildpacks) do
216-
[
217-
OpenStruct.new(name: 'paketo-buildpacks/java'),
218-
OpenStruct.new(name: 'paketo-community/ruby'),
219-
OpenStruct.new(name: 'paketo-buildpacks/httpd'),
220-
]
190+
expect(k8s_api_client).to have_received(:create_custom_builder)
191+
end
221192
end
222-
let(:k8s_api_client) { instance_double(Kubernetes::ApiClient) }
223193

224-
before do
225-
allow(CloudController::DependencyLocator.instance).to receive(:k8s_api_client).and_return(k8s_api_client)
226-
allow(k8s_api_client).to receive(:create_image)
227-
allow(k8s_api_client).to receive(:create_custom_builder)
228-
allow(k8s_api_client).to receive(:get_image)
229-
allow(k8s_api_client).to receive(:get_custom_builder).and_return(Kubeclient::Resource.new({
230-
spec: {
231-
stack: 'cflinuxfs3-stack',
232-
store: 'cf-buildpack-store',
233-
serviceAccount: 'gcr-service-account'
194+
context 'inheriting lifecycle from app' do
195+
let(:app_model) { VCAP::CloudController::AppModel.make(:kpack, space_guid: space.guid, name: 'my-app') }
196+
let(:package) do
197+
VCAP::CloudController::PackageModel.make(
198+
app_guid: app_model.guid,
199+
type: VCAP::CloudController::PackageModel::BITS_TYPE,
200+
state: VCAP::CloudController::PackageModel::READY_STATE
201+
)
202+
end
203+
let(:create_request) do
204+
{
205+
package: {
206+
guid: package.guid
207+
},
234208
}
235-
}))
236-
allow_any_instance_of(VCAP::CloudController::KpackBuildpackListFetcher).to receive(:fetch_all).and_return(k8s_buildpacks)
237-
end
209+
end
238210

239-
context 'when build has no lifecycle specified' do
240-
context 'when app has kpack lifecycle' do
241-
it 'uses the kpack lifecycle' do
242-
post 'v3/builds', request.to_json, developer_headers
211+
context 'when build has no lifecycle specified' do
212+
context 'when app has kpack lifecycle' do
213+
it 'uses the kpack lifecycle' do
214+
post 'v3/builds', create_request.to_json, developer_headers
243215

244-
expect(last_response.status).to eq(201)
245-
expect(parsed_response['lifecycle']['type']).to eq 'kpack'
216+
expect(last_response.status).to eq(201)
217+
expect(parsed_response['lifecycle']['type']).to eq 'kpack'
218+
end
246219
end
247220
end
248221
end

spec/unit/fetchers/kpack_buildpack_list_fetcher_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ module VCAP::CloudController
100100
expect(client).to have_received(:get_custom_builder).with('cf-default-builder', builder_namespace)
101101
end
102102

103+
context 'without a message' do
104+
let(:message) { nil }
105+
subject(:result) { fetcher.fetch_all }
106+
107+
it 'can be called without a message' do
108+
expect(result.length).to(eq(2))
109+
expect(client).to have_received(:get_custom_builder).with('cf-default-builder', builder_namespace)
110+
end
111+
end
112+
103113
context 'when there are no status conditions' do
104114
before do
105115
default_builder_obj.status.conditions = []

0 commit comments

Comments
 (0)