Skip to content

Commit

Permalink
webhook: switch to contextual logger
Browse files Browse the repository at this point in the history
Use k8s contextual logger instead of own. Comparing to other parts
of the operator webhook is a bit special since it serves own
endpoints and has context independent from controllers.

The output changes and it looks like

```
{"level":"info","ts":"2024-10-09T13:11:14Z","logger":"admission","msg":"Got request","object":{"name":"default-dsci"},"namespace":"","name":"default-dsci","resource":{"group":"dscinitialization.opendatahub.io","version":"v1","resource":"dscinitializations"},"user":"kube:admin","requestID":"e3489544-38dc-410a-8c96-56d6f9f90cd6","operation":"CREATE","kind":"DSCInitialization"}
```

Signed-off-by: Yauheni Kaliuta <[email protected]>
  • Loading branch information
ykaliuta committed Oct 9, 2024
1 parent 5cfa13b commit ad30b9b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions controllers/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

Expand All @@ -36,8 +37,6 @@ import (
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster/gvk"
)

var log = ctrl.Log.WithName("odh-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;delete,versions=v1,name=operator.opendatahub.io,admissionReviewVersions=v1
//nolint:lll

Expand Down Expand Up @@ -88,6 +87,8 @@ func denyCountGtZero(ctx context.Context, cli client.Client, gvk schema.GroupVer
}

func (w *OpenDataHubValidatingWebhook) checkDupCreation(ctx context.Context, req admission.Request) admission.Response {
log := logf.FromContext(ctx)

switch req.Kind.Kind {
case "DataScienceCluster", "DSCInitialization":
default:
Expand Down

0 comments on commit ad30b9b

Please sign in to comment.