metadata field not created after creation of resource #2726
-
I created a Deployment wrapper Controller. But the template's metadata field is empty even though I've added labels/annotations to the resource.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I can see that kubectl.kubernetes.io/last-applied-configuration annotation has labels/annotations. |
Beta Was this translation helpful? Give feedback.
-
Hi @akgowda, I think you've correctly diagnosed the issue. In Kubernetes, the Custom Resource Definitions (CRDs) have a feature called "field pruning". This feature ensures that unknown fields in the custom resource (CR) don't get saved to etcd. Given this, if you define fields in the CR that aren't present in the CRD, they will be pruned and won't be saved. For your DhruvaDeployment, the metadata under the template spec is not being preserved, hence the missing labels and annotations. To retain these fields, you can use the x-kubernetes-preserve-unknown-fields: true annotation for the specific field in the CRD. In this case, you'd want to apply it to the metadata field of the template to ensure the subfields (like labels and annotations) are preserved. I understand that you could solve that by using the marker: Since it seems that no longer need interactions I am closing this one but feel free to re-open if you need to do so, |
Beta Was this translation helpful? Give feedback.
Hi @akgowda,
I think you've correctly diagnosed the issue. In Kubernetes, the Custom Resource Definitions (CRDs) have a feature called "field pruning". This feature ensures that unknown fields in the custom resource (CR) don't get saved to etcd. Given this, if you define fields in the CR that aren't present in the CRD, they will be pruned and won't be saved.
For your DhruvaDeployment, the metadata under the template spec is not being preserved, hence the missing labels and annotations.
To retain these fields, you can use the x-kubernetes-preserve-unknown-fields: true annotation for the specific field in the CRD. In this case, you'd want to apply it to the metadata field of the template to…