-
Notifications
You must be signed in to change notification settings - Fork 39.9k
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
ignore update pod without new image in alwayspullimages admission controller #96668
Conversation
/sig node auth |
rather than allowing the imagePullPolicy to be updated, I'd expect the AlwaysPullImages admission plugin to be fixed to ignore/tolerate updates to pods which do not change the container images, even if the pull policy is not |
changed to the other solution, ignore update pod in alwayspullimages. |
This comment has been minimized.
This comment has been minimized.
we can ignore update requests if no images change like this: if attributes.GetOperation() == admission.Update {
oldImages := sets.NewString()
pods.VisitContainersWithPath(&oldPod.Spec, field.NewPath("spec"), func(c *api.Container, _ *field.Path) bool {
oldImages.Insert(c.Image)
return true
})
newImages := sets.NewString()
pods.VisitContainersWithPath(&newPod.Spec, field.NewPath("spec"), func(c *api.Container, _ *field.Path) bool {
newImages.Insert(c.Image)
return true
})
if oldImages.HasAll(newImages) {
// ignore updates that don't change the images referenced by the pod spec
return nil
}
} |
Could this strategy be applied to other admissions as well? For example:
|
1746dc6
to
3c7b4c4
Compare
0ba45e7
to
d7cfbb6
Compare
/triage accepted |
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.
thanks, looks good, just a couple stylistic comments
go ahead and squash to a single commit as well
…ced by the pod spec Signed-off-by: pacoxu <paco.xu@daocloud.io>
/retest |
squashed and fixed |
/priority backlog |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: liggitt, pacoxu 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 |
@@ -101,12 +103,49 @@ func (*AlwaysPullImages) Validate(ctx context.Context, attributes admission.Attr | |||
return nil | |||
} | |||
|
|||
// check if it's update and it doesn't change the images referenced by the pod spec | |||
func isUpdateWithNoNewImages(attributes admission.Attributes) bool { |
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 guess this could be extracted as a utility function and then can be shared in other admissions. :)
@zhouhaibing089 |
What type of PR is this?
/kind bug
What this PR does / why we need it:
When AlwaysPullImages is enabled, the annotations/labels/finalizers of existing(old) pod(ImagePullPolicy=IfNotPresent) can not be updated.
The reason is that ImagePullPolicy is immutable container attribute. When we try to update the image of the pod, the ImagePullPolicy will be changed as AlwaysPullImages is enabled. The image change update will failed.
https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.19/#container-v1-core
Which issue(s) this PR fixes:
Fixes #96624
Special notes for your reviewer:
As @bjrara and liggit commented in 96624, This pr tries to ignore update pod when alwayspullimages is enabled.
Another workaround would be that pod need to be recreated after enabling AlwaysPullImages.
Does this PR introduce a user-facing change?:
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: