diff --git a/changelog.d/20231116_110515_rra_DM_41708a.md b/changelog.d/20231116_110515_rra_DM_41708a.md new file mode 100644 index 00000000..98deb046 --- /dev/null +++ b/changelog.d/20231116_110515_rra_DM_41708a.md @@ -0,0 +1,3 @@ +### Bug fixes + +- Avoid reusing the same metadata object when creating a `Pod` from a `Job`. Previous versions modified the `spec` part of the `Job` when adding additional metadata to the child `Pod`. diff --git a/src/safir/testing/kubernetes.py b/src/safir/testing/kubernetes.py index 9b4e902a..ed3d2c92 100644 --- a/src/safir/testing/kubernetes.py +++ b/src/safir/testing/kubernetes.py @@ -1343,11 +1343,19 @@ async def create_namespaced_job( self._store_object(namespace, "Job", name, body) # Normally, Kubernetes will immediately spawn a Pod using the - # specification in the Job. Simulate that here. - pod = V1Pod( - metadata=body.spec.template.metadata or V1ObjectMeta(), - spec=body.spec.template.spec, - ) + # specification in the Job. Simulate that here. We have to copy the + # components of the spec metadata so that we don't modify the Job when + # we flesh out the metadata of the Pod. + metadata = V1ObjectMeta() + if body.spec.template.metadata: + source = body.spec.template.metadata + metadata.name = source.name + metadata.generate_name = source.generate_name + if source.labels: + metadata.labels = source.labels.copy() + if source.annotations: + metadata.annnotations = source.annotations.copy() + pod = V1Pod(metadata=metadata, spec=body.spec.template.spec) if not pod.metadata.name: if not pod.metadata.generate_name: pod.metadata.generate_name = f"{name}-"