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

Commit 030a8aa

Browse files
cwlbraamatt-royal
andcommitted
clean up kpack_lifecycle and get k8s client calls out of constructor
[#171029528] Co-authored-by: Connor Braa <cbraa@pivotal.io> Co-authored-by: Matt Royal <mroyal@pivotal.io>
1 parent b0761a9 commit 030a8aa

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

lib/cloud_controller/diego/lifecycles/kpack_lifecycle.rb

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@
22

33
module VCAP::CloudController
44
class KpackLifecycle
5-
attr_reader :staging_message, :buildpack_infos
5+
attr_reader :staging_message
66

77
def initialize(package, staging_message)
88
@staging_message = staging_message
99
@package = package
10-
11-
@buildpack_infos = requested_and_available_buildpacks(buildpacks_to_use)
12-
@validator = KpackLifecycleDataValidator.new(
13-
requested_buildpacks: buildpacks_to_use,
14-
buildpack_infos: buildpack_infos
15-
)
1610
end
1711

1812
delegate :valid?, :errors, to: :validator
@@ -36,7 +30,16 @@ def stack
3630
nil
3731
end
3832

39-
attr_reader :validator
33+
def buildpack_infos
34+
@buildpack_infos ||= requested_and_available_buildpacks(buildpacks_to_use)
35+
end
36+
37+
def validator
38+
@validator ||= KpackLifecycleDataValidator.new(
39+
requested_buildpacks: buildpacks_to_use,
40+
buildpack_infos: buildpack_infos
41+
)
42+
end
4043

4144
private
4245

@@ -49,11 +52,9 @@ def buildpacks_to_use
4952
end
5053

5154
def requested_and_available_buildpacks(buildpacks_to_use)
52-
# TODO: extract a common way to get the unfiltered list of buildpacks that can then have filters applied if needed?
53-
# TODO: Don't reach out to k8s unless buildpacks are requested
54-
available_buildpack_names = KpackBuildpackListFetcher.new.fetch_all.map(&:name)
55+
return [] if buildpacks_to_use.empty?
5556

56-
buildpacks_to_use & available_buildpack_names
57+
buildpacks_to_use & KpackBuildpackListFetcher.new.fetch_all.map(&:name)
5758
end
5859
end
5960
end

0 commit comments

Comments
 (0)