Add image override logic for DaemonSet#281
Add image override logic for DaemonSet#281knative-prow-robot merged 5 commits intoknative:masterfrom
Conversation
knative-prow-robot
left a comment
There was a problem hiding this comment.
@savitaashture: 1 warning.
Details
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.
| ) | ||
|
|
||
| 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.
Golint comments: exported function ResourceTransform should have comment or be unexported. More info.
11051d1 to
b2a4459
Compare
markusthoemmes
left a comment
There was a problem hiding this comment.
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
| 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.
nit:
switch u.GetKind()
case "Deployment":
return updateDeployment(instance, u, log)
case "DaemonSet":
return updateDaemonSet(instance, u, log)
default:
return nil
}| mf.InjectNamespace(instance.GetNamespace()), | ||
| ConfigMapTransform(instance, log), | ||
| DeploymentTransform(instance, log), | ||
| ResourceTransform(instance, log), |
There was a problem hiding this comment.
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.
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.
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.
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.
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.
Yep that also won't work
There was a problem hiding this comment.
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.
jcrossley3
left a comment
There was a problem hiding this comment.
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.
Wanna knock out "StatefulSet" while we're at it? 😄
| return nil | ||
| default: | ||
| return nil | ||
| } | ||
| return nil |
There was a problem hiding this comment.
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.
nit: do the assignment in the if clause for consistency
| err = scheme.Scheme.Convert(daemonSet, u, nil) | ||
| if err != nil { | ||
| return err | ||
| } |
|
@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 DetailsNeeds 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