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

Commit cb41b2e

Browse files
author
Aakash Shah
committed
Fix app env vars when updating an existing Image
* In the original PR (cloudfoundry#1600), we only applied environment variables when creating the first "Image" resource [#172301179] Authored-by: Aakash Shah <ashah@pivotal.io>
1 parent 13a74e0 commit cb41b2e

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

lib/cloud_controller/kpack/stager.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def mark_build_as_failed(build, message)
4646
def update_image_resource(image, staging_details)
4747
image.metadata.labels[BUILD_GUID_LABEL_KEY.to_sym] = staging_details.staging_guid
4848
image.spec.source.blob.url = blobstore_url_generator.package_download_url(staging_details.package)
49+
image.spec.build.env = get_environment_variables(staging_details)
4950

5051
image
5152
end
@@ -77,14 +78,18 @@ def image_resource(staging_details)
7778
}
7879
},
7980
build: {
80-
env: staging_details.environment_variables.to_a.
81-
delete_if { |key, value| key == 'VCAP_SERVICES' }.
82-
map { |key, value| { name: key, value: value.to_s } }
81+
env: get_environment_variables(staging_details),
8382
}
8483
}
8584
})
8685
end
8786

87+
def get_environment_variables(staging_details)
88+
staging_details.environment_variables.
89+
except('VCAP_SERVICES').
90+
map { |key, value| { name: key, value: value.to_s } }
91+
end
92+
8893
def logger
8994
@logger ||= Steno.logger('cc.stager')
9095
end

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ module Kpack
7979
}
8080
},
8181
build: {
82-
env: [{ name: 'BP_JAVA_VERSION', value: '8.*' }, { name: 'BPL_HEAD_ROOM', value: '0' }]
82+
env: [
83+
{ name: 'BP_JAVA_VERSION', value: '8.*' },
84+
{ name: 'BPL_HEAD_ROOM', value: '0' },
85+
]
8386
}
8487
}
8588
}))
@@ -135,11 +138,18 @@ module Kpack
135138
blob: {
136139
url: 'old-package-url',
137140
}
141+
},
142+
build: {
143+
env: [],
138144
}
139145
}
140146
})
141147
end
142148

149+
let(:environment_variables) do
150+
{ 'VCAP_SERVICES' => 'ignored', 'FOO' => 'BAR' }
151+
end
152+
143153
before do
144154
allow(client).to receive(:get_image).with(package.app.guid, 'namespace').and_return(existing_image)
145155
end
@@ -148,6 +158,9 @@ module Kpack
148158
updated_image = Kubeclient::Resource.new(existing_image.to_hash)
149159
updated_image.metadata.labels[Kpack::Stager::BUILD_GUID_LABEL_KEY.to_sym] = build.guid
150160
updated_image.spec.source.blob.url = 'package-download-url'
161+
updated_image.spec.build.env = [
162+
{ name: 'FOO', value: 'BAR' }
163+
]
151164

152165
expect(client).to_not receive(:create_image)
153166
expect(client).to receive(:update_image).with(updated_image)

0 commit comments

Comments
 (0)