Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] keep added labels and annotations during Job re-run #114

Open
aren92 opened this issue Oct 12, 2021 · 0 comments
Open

[Feature] keep added labels and annotations during Job re-run #114

aren92 opened this issue Oct 12, 2021 · 0 comments

Comments

@aren92
Copy link

aren92 commented Oct 12, 2021

Currently, pod template metadata is reset to create new job which delete customized label and annotations added during job creation.
File:

job.spec.template.metadata = None

By default k8s job add below labels for unique identification reference - kubernetes Job :

  • 'controller-uid'
  • 'job-name'
    so, during job recreate, just delete above labels, and keep other labels and annotations which is added during job create

By below solution, I have recreate job and keeps labels and annotions which is added during job create.

  1. backup labels & annotations before setting __'job.spec.template.metadata'__as NULL i.e. 'None'
        labels = copy.copy(job.spec.template.metadata.labels)           #create a copy of existing labels
        annotations = copy.copy(job.spec.template.metadata.annotations) #create a copy of existing annotations
  1. delete 'controller-uid' and 'job-name' from old labels
        del labels["controller-uid"]
        del labels["job-name"]
  1. create objectMeta using backup labels and annotations
         job.spec.template.metadata = client.V1ObjectMeta(labels=labels,annotations=annotations)

If maintainer and reviewer are okay with above solution, i would like to add above solution here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant