Files
Yi ChenandGitHub a0c7c605c6 Refactor webhook logging (#2799)
* refactor(webhook): get logger with predefined values from context

Signed-off-by: Yi Chen <[email protected]>

* refactor(webhook): use a customized log constructor

Signed-off-by: Yi Chen <[email protected]>

* Update logging statements

Signed-off-by: Yi Chen <[email protected]>

---------

Signed-off-by: Yi Chen <[email protected]>
2026-01-06 06:57:11 +00:00

50 lines
1.3 KiB
Go

/*
Copyright 2024 The Kubeflow authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package webhook
import (
"github.com/go-logr/logr"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)
type Options struct {
SparkJobNamespaces []string
WebhookName string
WebhookPort int
WebhookSecretName string
WebhookSecretNamespace string
WebhookServiceName string
WebhookServiceNamespace string
WebhookMetricsBindAddress string
EnableResourceQuotaEnforcement bool
}
// LogConstructor is used to customize the loggers used in webhooks.
func LogConstructor(logger logr.Logger, req *admission.Request) logr.Logger {
if req == nil {
return logger
}
return logger.WithValues(
req.Kind.Kind,
klog.KRef(req.Namespace, req.Name),
"requestID",
req.UID,
)
}