mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-15 17:51:20 +00:00
6d7f19688a
* feat: bump k8s deps to 1.27 Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * bump k8s 1.27.1 Signed-off-by: ShutingZhao <shuting@nirmata.com> --------- Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> Signed-off-by: ShutingZhao <shuting@nirmata.com> Co-authored-by: ShutingZhao <shuting@nirmata.com>
83 lines
3.3 KiB
Go
83 lines
3.3 KiB
Go
package resource
|
|
|
|
import (
|
|
context "context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/go-logr/logr"
|
|
"github.com/kyverno/kyverno/pkg/metrics"
|
|
"github.com/kyverno/kyverno/pkg/tracing"
|
|
"go.opentelemetry.io/otel/trace"
|
|
"go.uber.org/multierr"
|
|
k8s_io_api_authentication_v1beta1 "k8s.io/api/authentication/v1beta1"
|
|
k8s_io_apimachinery_pkg_apis_meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
k8s_io_client_go_kubernetes_typed_authentication_v1beta1 "k8s.io/client-go/kubernetes/typed/authentication/v1beta1"
|
|
)
|
|
|
|
func WithLogging(inner k8s_io_client_go_kubernetes_typed_authentication_v1beta1.SelfSubjectReviewInterface, logger logr.Logger) k8s_io_client_go_kubernetes_typed_authentication_v1beta1.SelfSubjectReviewInterface {
|
|
return &withLogging{inner, logger}
|
|
}
|
|
|
|
func WithMetrics(inner k8s_io_client_go_kubernetes_typed_authentication_v1beta1.SelfSubjectReviewInterface, recorder metrics.Recorder) k8s_io_client_go_kubernetes_typed_authentication_v1beta1.SelfSubjectReviewInterface {
|
|
return &withMetrics{inner, recorder}
|
|
}
|
|
|
|
func WithTracing(inner k8s_io_client_go_kubernetes_typed_authentication_v1beta1.SelfSubjectReviewInterface, client, kind string) k8s_io_client_go_kubernetes_typed_authentication_v1beta1.SelfSubjectReviewInterface {
|
|
return &withTracing{inner, client, kind}
|
|
}
|
|
|
|
type withLogging struct {
|
|
inner k8s_io_client_go_kubernetes_typed_authentication_v1beta1.SelfSubjectReviewInterface
|
|
logger logr.Logger
|
|
}
|
|
|
|
func (c *withLogging) Create(arg0 context.Context, arg1 *k8s_io_api_authentication_v1beta1.SelfSubjectReview, arg2 k8s_io_apimachinery_pkg_apis_meta_v1.CreateOptions) (*k8s_io_api_authentication_v1beta1.SelfSubjectReview, error) {
|
|
start := time.Now()
|
|
logger := c.logger.WithValues("operation", "Create")
|
|
ret0, ret1 := c.inner.Create(arg0, arg1, arg2)
|
|
if err := multierr.Combine(ret1); err != nil {
|
|
logger.Error(err, "Create failed", "duration", time.Since(start))
|
|
} else {
|
|
logger.Info("Create done", "duration", time.Since(start))
|
|
}
|
|
return ret0, ret1
|
|
}
|
|
|
|
type withMetrics struct {
|
|
inner k8s_io_client_go_kubernetes_typed_authentication_v1beta1.SelfSubjectReviewInterface
|
|
recorder metrics.Recorder
|
|
}
|
|
|
|
func (c *withMetrics) Create(arg0 context.Context, arg1 *k8s_io_api_authentication_v1beta1.SelfSubjectReview, arg2 k8s_io_apimachinery_pkg_apis_meta_v1.CreateOptions) (*k8s_io_api_authentication_v1beta1.SelfSubjectReview, error) {
|
|
defer c.recorder.RecordWithContext(arg0, "create")
|
|
return c.inner.Create(arg0, arg1, arg2)
|
|
}
|
|
|
|
type withTracing struct {
|
|
inner k8s_io_client_go_kubernetes_typed_authentication_v1beta1.SelfSubjectReviewInterface
|
|
client string
|
|
kind string
|
|
}
|
|
|
|
func (c *withTracing) Create(arg0 context.Context, arg1 *k8s_io_api_authentication_v1beta1.SelfSubjectReview, arg2 k8s_io_apimachinery_pkg_apis_meta_v1.CreateOptions) (*k8s_io_api_authentication_v1beta1.SelfSubjectReview, error) {
|
|
var span trace.Span
|
|
if tracing.IsInSpan(arg0) {
|
|
arg0, span = tracing.StartChildSpan(
|
|
arg0,
|
|
"",
|
|
fmt.Sprintf("KUBE %s/%s/%s", c.client, c.kind, "Create"),
|
|
trace.WithAttributes(
|
|
tracing.KubeClientGroupKey.String(c.client),
|
|
tracing.KubeClientKindKey.String(c.kind),
|
|
tracing.KubeClientOperationKey.String("Create"),
|
|
),
|
|
)
|
|
defer span.End()
|
|
}
|
|
ret0, ret1 := c.inner.Create(arg0, arg1, arg2)
|
|
if span != nil {
|
|
tracing.SetSpanStatus(span, ret1)
|
|
}
|
|
return ret0, ret1
|
|
}
|