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

ImageCheckPullPolicy gets overriden by ImagePullPolicy #486

Open
dziemba opened this issue Jan 29, 2025 · 0 comments
Open

ImageCheckPullPolicy gets overriden by ImagePullPolicy #486

dziemba opened this issue Jan 29, 2025 · 0 comments

Comments

@dziemba
Copy link

dziemba commented Jan 29, 2025

The recent changes of image pull policies in #459 created an issue where the CheckPullPolicy isn't correctly computed.

Looking at this code:

policy := pnr.policy
if policy == "" {
policy = w.cfg.DefaultImageCheckPullPolicy
}
if policy == "" {
// If pull policy is unspecified by either the podSpec{,Patch} or
// controller configuration, use Always, unless there is a
// digest that has pinned the ref, in which case use IfNotPresent.
// (No need to pull a pinned image ref if it's present.)
policy = corev1.PullAlways
if _, hasDigest := pnr.ref.(reference.Digested); hasDigest {
policy = corev1.PullIfNotPresent
}
}

When no DefaultImageCheckPullPolicy is set, correct defaults are applied based on the image ref (Always if it doesn't have a digest, otherwise IfNotPresent). It seems however that these defaults never get applied when the policy of the container is already set to something, here:

if c.ImagePullPolicy == "" {
c.ImagePullPolicy = w.cfg.DefaultImagePullPolicy
}

So if there is a DefaultImagePullPolicy set or the container spec has an explicit policy, that will always take precedence over the CheckPolicy, either set by DefaultImageCheckPullPolicy or calculated by the logic mentioned above.

When now using the default config

cmd.Flags().String(
"default-image-pull-policy",
"IfNotPresent",
"Configures a default image pull policy for containers that do not specify a pull policy and non-init containers created by the stack itself",
)
cmd.Flags().String(
"default-image-check-pull-policy",
"",
"Sets a default PullPolicy for image-check init containers, used if an image pull policy is not set for the corresponding container in a podSpec or podSpecPatch",
)

that sets default-image-pull-policy: "IfNotPresent" and "default-image-check-pull-policy": ""
we never get the desired behavior of always pulling images with no digest.

It seems like the only way to get the pull logic based on the digest being present is to unset the defaultImagePullPolicy. I assume then we'd fall back to the defaults the K8s sets: https://github.com/kubernetes/api/blob/b849e76aab64dcc5d2d4947cccccebdf0d8ec3c0/core/v1/types.go#L2912

This would be reasonable in a standalone scenario, but would pull twice again with your check logic.

It seems like there's no combination of settings that would achieve correctness and pull deduplication as originally indented by #459

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