lib/configgin.rb in configgin-0.20.1 vs lib/configgin.rb in configgin-0.20.1.1
- old
+ new
@@ -69,11 +69,12 @@
# Write exported properties to secret and update annotations on importing stateful sets.
def export_job_properties(jobs)
# Co-located containers don't get to export properties.
return unless instance_group == ENV["KUBERNETES_CONTAINER_NAME"]
- # Jobs (errands) don't export properties.
+ # Jobs (errands) and unowned pods (tests) don't export properties.
+ return unless self_pod['metadata']['ownerReferences']
return unless self_pod['metadata']['ownerReferences'][0]['kind'] == "StatefulSet"
sts = kube_client_stateful_set.get_stateful_set(instance_group, kube_namespace)
# Make sure the secret attached to the stateful set exists.
@@ -99,33 +100,39 @@
secret = kube_client.get_secret(instance_group, kube_namespace)
secret.data ||= {}
# version tag changes whenever the chart version or the secrets generation changes
version_tag = ENV["CONFIGGIN_VERSION_TAG"]
- new_tag = !secret.data.to_h.key?(version_tag.to_sym)
+ new_tag = !secret.data[version_tag]
secret.data = {version_tag => ""} if new_tag # make sure old properties are deleted during upgrade
digests = {}
jobs.each do |name, job|
- secret.data["skiff-exported-properties-#{name}"] = Base64.encode64(job.exported_properties.to_json)
+ secret.data["skiff-exported-properties-#{name}"] = Base64.strict_encode64(job.exported_properties.to_json)
digests[name] = property_digest(job.exported_properties)
# Record initial digest values whenever the tag changes, in which case the pod startup
# order is already controlled by the "CONFIGGIN_IMPORT_#{role}" references to the new
# tags in the corresponding secrets. There is no annotation when importing this set of
# initial values because the helm chart doesn't include any annotations, and we don't
# want to trigger a pod restart by adding them.
- encoded_digest = Base64.encode64(digests[name])
+ encoded_digest = Base64.strict_encode64(digests[name])
if new_tag
secret.data["skiff-initial-digest-#{name}"] = encoded_digest
+ secret.data["skiff-initial-properties-#{name}"] = secret.data["skiff-exported-properties-#{name}"]
end
if secret.data["skiff-initial-digest-#{name}"] == encoded_digest
digests[name] = nil
end
end
kube_client.update_secret(secret)
+ warn "new_tag=#{new_tag}"
+ secret.data.to_h.each_pair do |key, value|
+ warn "secret.data[#{key}]=#{value}"
+ end
+
# Some pods might depend on the properties exported by this pod; add annotations
# to the template spec of the stateful sets so that the pods will be restarted if
# the exported values have changed from the initial values.
expected_annotations(@job_configs, digests).each_pair do |instance_group_name, digests|
# Avoid restarting our own pod
@@ -152,12 +159,14 @@
# Update annotations to match digests for current property values. The stateful set will
# only restarts pods when the checksum of the pod spec changes, so no-op "updates" are ok.
annotations = {}
sts.spec.template.metadata.annotations.each_pair do |key, value|
+ warn "Copying old annotation #{key}=#{value}"
annotations[key] = value
end
digests.each_pair do |key, value|
+ warn "Setting new annotation #{key}=#{value}"
annotations[key] = value
end
kube_client_stateful_set.merge_patch_stateful_set(
instance_group_name,