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

k8s: inject pull policies into crds #4304

Merged
merged 2 commits into from
Mar 12, 2021
Merged

Conversation

landism
Copy link
Member

@landism landism commented Mar 11, 2021

Fixes #4291

Problem

For standard k8s objects, Tilt will inject an image pull policy. For CRDs, it will not.
It's relatively common for CRDs to use the normal k8s container spec, with "image" and "imagePullPolicy" fields. Tilt provides a way for users to configure how to inject the image ref, but leave users to their own devices when it comes to imagePullPolicy.

Solution

If a CRD "image" field has an "imagePullPolicy" neighbor, inject the pull policy.

Note: the image object locator (where you specify, e.g., a repo and ref field) just ignores the pull policy. An obvious answer here is to add an option to specify the pull policy field. My weak gut instinct is it's not worth the effort to worry about that until someone complains. I'm happy to do that as well if someone has a different gut instinct.

@landism landism requested review from nicks and maiamcc March 11, 2021 19:52
Copy link
Member

@nicks nicks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

func (v *Value) Sibling(name string) (val Value, ok bool) {
key := reflect.ValueOf(name)
sib := v.parentMap.MapIndex(key)
if sib == (reflect.Value{}) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think sib.IsZero() would be more idiomatic

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what a great error message: panic: reflect: call of reflect.Value.IsZero on zero Value

It looks like:

  1. Value.IsZero returns true if it's got the value's zero value, and panics otherwise.
  2. MapIndex returns an untyped zero value
  3. Value.IsValid is what we want for this case

@@ -121,6 +125,10 @@ func (l *JSONPathImageLocator) Inject(e K8sEntity, selector container.RefSelecto
if selector.Matches(ref) {
val.Set(reflect.ValueOf(container.FamiliarString(injectRef)))
modified = true

if pullPolicyVal, ok := val.Sibling(imagePullPolicyKey); ok {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also check pullPolicyVal.CanSet()? always get nervous about Value.Set panicking

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ha, did you see the CI failure?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, nope i did not! 🌟

@landism landism merged commit dc95c49 into master Mar 12, 2021
@landism landism deleted the matt/inject_crd_pullpolicy branch March 12, 2021 16:19
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

Successfully merging this pull request may close these issues.

Overriding imagePullPolicy in CRDs with tilt-managed images
2 participants