Skip to content
This repository has been archived by the owner on Jun 24, 2020. It is now read-only.

Add image override logic for DaemonSet #281

Merged
merged 5 commits into from
Feb 6, 2020

Conversation

savitaashture
Copy link
Contributor

@savitaashture savitaashture commented Feb 3, 2020

Fixes #280

Proposed Changes

  • Extended image override logic for DaemonSet when there is image update by override

Release Note

This PR will be validated when release manifest updated to changes from knative/serving#6624
This PR has dependency knative.dev/pkg

@googlebot googlebot added the cla: yes Author(s) signed a CLA. label Feb 3, 2020
Copy link
Contributor

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

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

@savitaashture: 1 warning.

In response to this:

Fixes #280

Proposed Changes

  • Extended image override logic for DaemonSet when there is image update by override

Release Note

This PR will be validated when release manifest updated to changes from knative/serving#6624

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@@ -38,12 +38,16 @@ var (
containerNameVariable = "${NAME}"
)

func DeploymentTransform(instance *servingv1alpha1.KnativeServing, log *zap.SugaredLogger) mf.Transformer {
func ResourceTransform(instance *servingv1alpha1.KnativeServing, log *zap.SugaredLogger) mf.Transformer {
Copy link
Contributor

Choose a reason for hiding this comment

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

Golint comments: exported function ResourceTransform should have comment or be unexported. More info.

Copy link
Contributor

@markusthoemmes markusthoemmes left a comment

Choose a reason for hiding this comment

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

A lot of the duplication can probably be removed by using a PodSpecable duck type rather than Deployment and DaemonSet specifically. That's material for a follow up PR though imo.

/lgtm

return func(u *unstructured.Unstructured) error {
// Update the deployment with the new registry and tag
if u.GetKind() == "Deployment" {
return updateDeployment(instance, u, log)
}
// Update the daemonSet with the new registry and tag
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

switch u.GetKind()
case "Deployment":
  return updateDeployment(instance, u, log)
case "DaemonSet":
  return updateDaemonSet(instance, u, log)
default:
  return nil
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you @markusthoemmes Updated PR

Copy link
Contributor

@jcrossley3 jcrossley3 left a comment

Choose a reason for hiding this comment

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

I almost feel like it's worth biting the bullet and using PodSpecable. Seems like that would reduce a lot of the code in the PR and simultaneously pull in support for StatefulSets as well. WDYT?

@@ -32,7 +32,7 @@ func (platforms Platforms) Transformers(kubeClientSet kubernetes.Interface, inst
mf.InjectOwner(instance),
mf.InjectNamespace(instance.GetNamespace()),
ConfigMapTransform(instance, log),
DeploymentTransform(instance, log),
ResourceTransform(instance, log),
Copy link
Contributor

@jcrossley3 jcrossley3 Feb 3, 2020

Choose a reason for hiding this comment

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

I think this name is a little vague. DaemonSets and StatefulSets are really just specialized Deployments. And pretty much everything is a Resource. I'd say just keep the name DeploymentTransform or maybe PodSpecableTransform? Or save that for another PR?

Copy link
Contributor Author

@savitaashture savitaashture Feb 3, 2020

Choose a reason for hiding this comment

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

Thank you @jcrossley3 I will keep PodSpecableTransform 👍

@savitaashture
Copy link
Contributor Author

I almost feel like it's worth biting the bullet and using PodSpecable. Seems like that would reduce a lot of the code in the PR and simultaneously pull in support for StatefulSets as well. WDYT?

Yep true i will make use of PodSpecable in the PR and update

@savitaashture
Copy link
Contributor Author

CI fail until PR merge

specData.Spec.Template.Spec.ImagePullSecrets = addImagePullSecrets(
specData.Spec.Template.Spec.ImagePullSecrets, &registry, log)

unstructuredData, err := duck.ToUnstructured(specData.DeepCopyObject().(duck.OneOfOurs))
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see, you need the selector in PodSpecable to successfully serialize back here? 🤔

Can you instead use the existing unstructured and only override things? I.e. take the transformed podSpec and set it into the unstructured element at Spec.Template or something like that?

Copy link
Contributor Author

@savitaashture savitaashture Feb 4, 2020

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

No I don't think that'd work either. Lemme try if what I though actually works before I bother you more with it 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep that also won't work

Copy link
Contributor

Choose a reason for hiding this comment

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

In pseudo-code, we need something like this:

podSpecable := duck.FromUnstructured(u)

updateImages(podSpecable)
updatePullSecret(podSpecable)

unstructured.SetNestedField(u.Object, podSpecable.Spec.Template, "spec", "template")

Or alternatively

podSpecable := duck.FromUnstructured(u)
afterChanges := podSpecable.DeepCopy()

updateImages(afterChanges)
updatePullSecret(afterChanges)

patch := generatePatch(podSpecable, afterChanges)
applyPatch(u, patch)

That way we keep the fields of the unstructured intact that PodSpecable doesn't capture (see selector etc.) while also having the profit of using just one type. I haven't gotten a working version of the above together yet though.

Copy link
Contributor

@jcrossley3 jcrossley3 left a comment

Choose a reason for hiding this comment

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

I love that you're handling all the possible image overrides in a single ImageTransform function. Great idea!

if u.GetAPIVersion() == "caching.internal.knative.dev/v1alpha1" && u.GetKind() == "Image" {
return updateCachingImage(instance, u)
switch u.GetKind() {
case "Deployment", "DaemonSet":
Copy link
Contributor

Choose a reason for hiding this comment

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

Wanna knock out "StatefulSet" while we're at it? 😄

Copy link
Contributor

@jcrossley3 jcrossley3 left a comment

Choose a reason for hiding this comment

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

Just some minor nits

Comment on lines 54 to 57
return nil
default:
return nil
}
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: i would lose the default case and replace the two returns in the switch with the old one at the end of the function.

Comment on lines 84 to 88
err := scheme.Scheme.Convert(u, daemonSet, nil)
if err != nil {
log.Error(err, "Error converting Unstructured to daemonSet", "unstructured", u, "daemonSet", daemonSet)
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: do the assignment in the if clause for consistency

Comment on lines 90 to 93
err = scheme.Scheme.Convert(daemonSet, u, nil)
if err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: same as ^^

@savitaashture
Copy link
Contributor Author

@jcrossley3 thank you
Addressed all the comments

@knative-metrics-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-knative-serving-operator-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/knativeserving/common/images.go 87.3% 85.1% -2.2

@jcrossley3
Copy link
Contributor

Thanks @savitaashture 😄
/lgtm
/approve

@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jcrossley3, savitaashture

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot merged commit 3ebfe06 into knative:master Feb 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extend image override logic to Daemonsets
6 participants