kapitan-reference
kapitan-reference copied to clipboard
Versioning and env valueFrom does not work in generators
If you do this with a versioned secret:
components:
echo-server:
<other config>
env:
KAPITAN_SECRET:
secretKeyRef:
key: 'kapitan_secret'
You would expect the name found to include the version, but its taking its information from a bit of the dataset that doesn't yet have versions (they haven't been calculated yet).
A solution could be something like this (in WorkloadCommon):
def update_env_for_versions(self, objects):
for object in objects.root:
rendered_name = object.root.metadata.name
containers = self.root.spec.template.spec.containers
for container in containers:
for env in container.env:
if "valueFrom" in env and "secretKeyRef" in env["valueFrom"]:
if env["valueFrom"].secretKeyRef.name == rendered_name.rsplit('-', 1)[0]:
env["valueFrom"].secretKeyRef.name = rendered_name
called after
workload.add_volumes_for_objects(secrets)
I can't help but feel theres a neater solution, this could do unexpected things. It also only does secrets.
Applogies for the lack of PR, my generator is hacked about quite a bit in ways you wouldn't want and I'm pushed for time. I'll try and backport the other bits that are globally applicable and do a PR for this if no one can see a better solution.
The env["valueFrom"] pains me, but python insisted...