Skip to content

Commit

Permalink
chore: remove UPDATE from webhook operation list (opendatahub-io#1134)
Browse files Browse the repository at this point in the history
* chore: disable message from webhook when DSC/DSCI gets UPDATE

Signed-off-by: Wen Zhou <[email protected]>

* update: remove UPDATE from operation list because we do not handle it

- keep "default" in switch-case to satisfy staticcheck
- add initial to convert Allowed to "true" for pass thro

Signed-off-by: Wen Zhou <[email protected]>

---------

Signed-off-by: Wen Zhou <[email protected]>
(cherry picked from commit b58ab82)
  • Loading branch information
zdtsw authored and openshift-merge-bot[bot] committed Sep 18, 2024
1 parent cd06abf commit b5902ba
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
1 change: 0 additions & 1 deletion bundle/manifests/rhods-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1807,7 +1807,6 @@ spec:
- v1
operations:
- CREATE
- UPDATE
- DELETE
resources:
- datascienceclusters
Expand Down
1 change: 0 additions & 1 deletion config/webhook/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ webhooks:
- v1
operations:
- CREATE
- UPDATE
- DELETE
resources:
- datascienceclusters
Expand Down
10 changes: 4 additions & 6 deletions controllers/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (

var log = ctrl.Log.WithName("rhoai-controller-webhook")

//+kubebuilder:webhook:path=/validate-opendatahub-io-v1,mutating=false,failurePolicy=fail,sideEffects=None,groups=datasciencecluster.opendatahub.io;dscinitialization.opendatahub.io,resources=datascienceclusters;dscinitializations,verbs=create;update;delete,versions=v1,name=operator.opendatahub.io,admissionReviewVersions=v1
//+kubebuilder:webhook:path=/validate-opendatahub-io-v1,mutating=false,failurePolicy=fail,sideEffects=None,groups=datasciencecluster.opendatahub.io;dscinitialization.opendatahub.io,resources=datascienceclusters;dscinitializations,verbs=create;delete,versions=v1,name=operator.opendatahub.io,admissionReviewVersions=v1
//nolint:lll

type OpenDataHubWebhook struct {
Expand Down Expand Up @@ -105,18 +105,16 @@ func (w *OpenDataHubWebhook) checkDeletion(ctx context.Context, req admission.Re

func (w *OpenDataHubWebhook) Handle(ctx context.Context, req admission.Request) admission.Response {
var resp admission.Response
resp.Allowed = true // initialize Allowed to be true in case Operation falls into "default" case

switch req.Operation {
case admissionv1.Create:
resp = w.checkDupCreation(ctx, req)
case admissionv1.Delete:
resp = w.checkDeletion(ctx, req)
default:
msg := fmt.Sprintf("No logic check by webhook is applied on %v request", req.Operation)
log.Info(msg)
resp = admission.Allowed("")
default: // for other operations by default it is admission.Allowed("")
// no-op
}

if !resp.Allowed {
return resp
}
Expand Down

0 comments on commit b5902ba

Please sign in to comment.