-
Notifications
You must be signed in to change notification settings - Fork 151
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
refactor(webhook): change for mutating webhook to use Default to set ModelReg namespace #1241
refactor(webhook): change for mutating webhook to use Default to set ModelReg namespace #1241
Conversation
controllers/webhook/webhook.go
Outdated
@@ -44,10 +47,10 @@ type OpenDataHubValidatingWebhook struct { | |||
Decoder *admission.Decoder | |||
} | |||
|
|||
func (w *OpenDataHubValidatingWebhook) SetupWithManager(mgr ctrl.Manager) { | |||
func (v *OpenDataHubValidatingWebhook) SetupValidatingWebhookWithManager(mgr ctrl.Manager) { |
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.
Why?
They have distinct types and type.SetupWithManager is self describing
controllers/webhook/webhook.go
Outdated
@@ -76,7 +79,7 @@ func denyCountGtZero(ctx context.Context, cli client.Client, gvk schema.GroupVer | |||
return admission.Allowed("") | |||
} | |||
|
|||
func (w *OpenDataHubValidatingWebhook) checkDupCreation(ctx context.Context, req admission.Request) admission.Response { | |||
func (v *OpenDataHubValidatingWebhook) checkDupCreation(ctx context.Context, req admission.Request) admission.Response { |
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.
why? w as webhook is good enough. (I would abstract it even further till s Self :)
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.
right, forgot to revert this change after commit 2
controllers/webhook/webhook.go
Outdated
return admission.Errored(http.StatusInternalServerError, err) | ||
} | ||
// use PatchResponseFromRaw to ensure dsc CR is updated with defaults | ||
return admission.PatchResponseFromRaw(req.Object.Raw, dscBytes) |
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.
so finally this is the actual change :) But still, could you put some reasoning behind?
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.
this is outdated change, check the latest code.
} | ||
|
||
func (w *OpenDataHubMutatingWebhook) setDSCDefaults(_ context.Context, dsc *dscv1.DataScienceCluster) admission.Response { | ||
// implement admission.CustomDefaulter interface. | ||
func (m *DSCDefaulter) Default(_ context.Context, obj runtime.Object) error { |
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.
As this is now extracted to a simple function, how about providing some unit tests for it? It does not even have to employ EnvTest, plain unit testing should be fine here.
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.
did some updates on the unit-test.
only for the case which mutate webhook is related.
…namespace - rename SetupValidatingWebhookWithManager and SetupMutateWebhookWithManager per each - use Default() instead of setDSCDefaults() - return call PatchResponseFromRaw than admission.Allowed() Signed-off-by: Wen Zhou <wenzhou@redhat.com>
Signed-off-by: Wen Zhou <wenzhou@redhat.com>
Signed-off-by: Wen Zhou <wenzhou@redhat.com>
… is "" - update unit-test Signed-off-by: Wen Zhou <wenzhou@redhat.com>
Signed-off-by: Wen Zhou <wenzhou@redhat.com>
/test opendatahub-operator-e2e |
Signed-off-by: Wen Zhou <wenzhou@redhat.com>
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ykaliuta 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 |
d33ccf6
into
opendatahub-io:incubation
…ModelReg namespace (red-hat-data-services#1241) * refactor: change for mutating webhook to use Default to set ModelReg namespace - rename SetupValidatingWebhookWithManager and SetupMutateWebhookWithManager per each - use Default() instead of setDSCDefaults() - return call PatchResponseFromRaw than admission.Allowed() Signed-off-by: Wen Zhou <wenzhou@redhat.com> * update: rework implmentation Signed-off-by: Wen Zhou <wenzhou@redhat.com> * update: revert some unnecessary changes and add type in log Signed-off-by: Wen Zhou <wenzhou@redhat.com> * update: make it more clear for the "defaulter" case is when namespace is "" - update unit-test Signed-off-by: Wen Zhou <wenzhou@redhat.com> * test: add more testcase Signed-off-by: Wen Zhou <wenzhou@redhat.com> * update: rename function and move comments Signed-off-by: Wen Zhou <wenzhou@redhat.com> --------- Signed-off-by: Wen Zhou <wenzhou@redhat.com> (cherry picked from commit d33ccf6)
…ModelReg namespace (#1241) * refactor: change for mutating webhook to use Default to set ModelReg namespace - rename SetupValidatingWebhookWithManager and SetupMutateWebhookWithManager per each - use Default() instead of setDSCDefaults() - return call PatchResponseFromRaw than admission.Allowed() Signed-off-by: Wen Zhou <wenzhou@redhat.com> * update: rework implmentation Signed-off-by: Wen Zhou <wenzhou@redhat.com> * update: revert some unnecessary changes and add type in log Signed-off-by: Wen Zhou <wenzhou@redhat.com> * update: make it more clear for the "defaulter" case is when namespace is "" - update unit-test Signed-off-by: Wen Zhou <wenzhou@redhat.com> * test: add more testcase Signed-off-by: Wen Zhou <wenzhou@redhat.com> * update: rename function and move comments Signed-off-by: Wen Zhou <wenzhou@redhat.com> --------- Signed-off-by: Wen Zhou <wenzhou@redhat.com> (cherry picked from commit d33ccf6)
Description
How Has This Been Tested?
Screenshot or short clip
Merge criteria