-
Notifications
You must be signed in to change notification settings - Fork 45
Add image override logic for DaemonSet #281
Conversation
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.
@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 { |
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.
Golint comments: exported function ResourceTransform should have comment or be unexported. More info.
11051d1
to
b2a4459
Compare
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.
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 |
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.
nit:
switch u.GetKind()
case "Deployment":
return updateDeployment(instance, u, log)
case "DaemonSet":
return updateDaemonSet(instance, u, log)
default:
return 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.
Thank you @markusthoemmes Updated PR
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 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), |
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 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?
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.
Thank you @jcrossley3 I will keep PodSpecableTransform
👍
Yep true i will make use of |
CI fail until PR merge |
specData.Spec.Template.Spec.ImagePullSecrets = addImagePullSecrets( | ||
specData.Spec.Template.Spec.ImagePullSecrets, ®istry, log) | ||
|
||
unstructuredData, err := duck.ToUnstructured(specData.DeepCopyObject().(duck.OneOfOurs)) |
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.
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?
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.
Do you mean this https://github.com/knative/serving-operator/pull/281/files#diff-411a842e3f404ed5adc1b082ea595d72R78 directly instead of duck.ToUnstructured
?
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.
No I don't think that'd work either. Lemme try if what I though actually works before I bother you more with 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.
Yep that also won't work
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.
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.
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 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": |
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.
Wanna knock out "StatefulSet" while we're at 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.
Just some minor nits
return nil | ||
default: | ||
return nil | ||
} | ||
return 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.
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.
err := scheme.Scheme.Convert(u, daemonSet, nil) | ||
if err != nil { | ||
log.Error(err, "Error converting Unstructured to daemonSet", "unstructured", u, "daemonSet", daemonSet) | ||
return err | ||
} |
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.
nit: do the assignment in the if clause for consistency
err = scheme.Scheme.Convert(daemonSet, u, nil) | ||
if err != nil { | ||
return err | ||
} |
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.
nit: same as ^^
@jcrossley3 thank you |
The following is the coverage report on the affected files.
|
Thanks @savitaashture 😄 |
[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 |
Fixes #280
Proposed Changes
Release Note
This PR will be validated when release manifest updated to changes from knative/serving#6624
This PR has dependency knative.dev/pkg