-
Notifications
You must be signed in to change notification settings - Fork 243
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
Update DataImportCron CronJob when needed #2316
Update DataImportCron CronJob when needed #2316
Conversation
Signed-off-by: Arnon Gilboa <agilboa@redhat.com>
var cronJob batchv1.CronJob | ||
cronJobNamespacedName := types.NamespacedName{Namespace: r.cdiNamespace, Name: GetCronJobName(cron)} | ||
return r.uncachedClient.Get(ctx, cronJobNamespacedName, &cronJob) == nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why were we doing uncached client here btw? (only a GET so should be ok, just curious)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
afair r.client.Get() sometime returned NotFound after creating CronJob. However, I'll try again r.client for Get() and Update() here and check if it's consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah looks like that uncached client snuck in. Michael mentioned it in the original PR, but we didn't address it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed. So far no surprises.
err := r.uncachedClient.Get(ctx, cronJobNamespacedName, &cronJob) | ||
podSpec := &cronJob.Spec.JobTemplate.Spec.Template.Spec | ||
if err == nil && len(podSpec.Containers) > 0 && podSpec.Containers[0].Image != r.image { | ||
podSpec.Containers[0].Image = r.image |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe Update() over newCronJob().Spec != foundCron.Spec?
It is possible at some point in the future we decided to change some fields in the cronjob object too, and want to sync existing cronjobs to those values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, seems much smarter. However, creating the spec for every check seems a bit expansive, and I see no clean way for memoizing it. Any idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@akalenyu tried this change and it seems that when CronJob is created based on newCronJob(), k8s patches several fields of the spec (dnsPolicy, schedulerName, serviceAccount etc.) so we cannot simply compare (DeepEqual) the current and the desired spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might help here
merged, err := sdk.MergeObject(desired, current, LastAppliedConfigAnnotation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used your tip, thanks @akalenyu !
podSpec := &cronJob.Spec.JobTemplate.Spec.Template.Spec | ||
if err == nil && len(podSpec.Containers) > 0 && podSpec.Containers[0].Image != r.image { | ||
podSpec.Containers[0].Image = r.image | ||
err = r.uncachedClient.Update(ctx, &cronJob) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uncached client here seems wrong as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
f1e89d2
to
a95b392
Compare
/hold |
a95b392
to
a6718df
Compare
/hold remove |
/unhold |
/retest |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: awels The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Manual backport of kubevirt#2316 Signed-off-by: Arnon Gilboa <agilboa@redhat.com>
Manual backport of #2316 Signed-off-by: Arnon Gilboa <agilboa@redhat.com>
Signed-off-by: Arnon Gilboa agilboa@redhat.com
What this PR does / why we need it:
When CDI is being upgraded, the DataImportCron CronJobs are kept as is, and refer cdi-importer image of the previous version, rather than the current (upgraded) one.
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #
Special notes for your reviewer:
Release note: