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

refactor(webhook): change for mutating webhook to use Default to set ModelReg namespace #1241

Merged

Conversation

zdtsw
Copy link
Member

@zdtsw zdtsw commented Sep 17, 2024

Description

  • use Default() instead of setDSCDefaults()

How Has This Been Tested?

Screenshot or short clip

Merge criteria

  • You have read the contributors guide.
  • Commit messages are meaningful - have a clear and concise summary and detailed explanation of what was changed and why.
  • Pull Request contains a description of the solution, a link to the JIRA issue, and to any dependent or related Pull Request.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

@openshift-ci openshift-ci bot requested review from CFSNM and StevenTobin September 17, 2024 09:58
@zdtsw zdtsw requested review from bartoszmajsak and ykaliuta and removed request for StevenTobin and CFSNM September 17, 2024 09:59
@zdtsw zdtsw changed the title refactor: change for mutating webhook to use Default to set ModelReg namespace refactor(webhook): change for mutating webhook to use Default to set ModelReg namespace Sep 17, 2024
@zdtsw zdtsw marked this pull request as draft September 17, 2024 10:20
@@ -44,10 +47,10 @@ type OpenDataHubValidatingWebhook struct {
Decoder *admission.Decoder
}

func (w *OpenDataHubValidatingWebhook) SetupWithManager(mgr ctrl.Manager) {
func (v *OpenDataHubValidatingWebhook) SetupValidatingWebhookWithManager(mgr ctrl.Manager) {
Copy link
Contributor

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

@@ -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 {
Copy link
Contributor

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 :)

Copy link
Member Author

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

return admission.Errored(http.StatusInternalServerError, err)
}
// use PatchResponseFromRaw to ensure dsc CR is updated with defaults
return admission.PatchResponseFromRaw(req.Object.Raw, dscBytes)
Copy link
Contributor

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?

Copy link
Member Author

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.

@zdtsw zdtsw marked this pull request as ready for review September 17, 2024 13:14
@openshift-ci openshift-ci bot requested review from adelton and AjayJagan September 17, 2024 13:14
}

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 {
Copy link
Contributor

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.

Copy link
Member Author

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>
@zdtsw
Copy link
Member Author

zdtsw commented Sep 19, 2024

/test opendatahub-operator-e2e

Signed-off-by: Wen Zhou <wenzhou@redhat.com>
@openshift-ci openshift-ci bot added the lgtm label Sep 19, 2024
Copy link

openshift-ci bot commented Sep 19, 2024

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

@openshift-merge-bot openshift-merge-bot bot merged commit d33ccf6 into opendatahub-io:incubation Sep 19, 2024
8 checks passed
zdtsw referenced this pull request in zdtsw-forking/rhods-operator Oct 1, 2024
…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)
openshift-merge-bot bot referenced this pull request in red-hat-data-services/rhods-operator Oct 4, 2024
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants