mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-10 09:56:55 +00:00
* refactor: improve instrumented clients creation Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * refactor: instrumented clients code part 3 Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * metadata Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * metadata Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
57 lines
2.1 KiB
Go
57 lines
2.1 KiB
Go
package resource
|
|
|
|
import (
|
|
context "context"
|
|
"fmt"
|
|
|
|
"github.com/kyverno/kyverno/pkg/metrics"
|
|
"github.com/kyverno/kyverno/pkg/tracing"
|
|
"go.opentelemetry.io/otel/attribute"
|
|
"go.opentelemetry.io/otel/codes"
|
|
k8s_io_api_authorization_v1 "k8s.io/api/authorization/v1"
|
|
k8s_io_apimachinery_pkg_apis_meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
k8s_io_client_go_kubernetes_typed_authorization_v1 "k8s.io/client-go/kubernetes/typed/authorization/v1"
|
|
)
|
|
|
|
func WithMetrics(inner k8s_io_client_go_kubernetes_typed_authorization_v1.SubjectAccessReviewInterface, recorder metrics.Recorder) k8s_io_client_go_kubernetes_typed_authorization_v1.SubjectAccessReviewInterface {
|
|
return &withMetrics{inner, recorder}
|
|
}
|
|
|
|
func WithTracing(inner k8s_io_client_go_kubernetes_typed_authorization_v1.SubjectAccessReviewInterface, client, kind string) k8s_io_client_go_kubernetes_typed_authorization_v1.SubjectAccessReviewInterface {
|
|
return &withTracing{inner, client, kind}
|
|
}
|
|
|
|
type withMetrics struct {
|
|
inner k8s_io_client_go_kubernetes_typed_authorization_v1.SubjectAccessReviewInterface
|
|
recorder metrics.Recorder
|
|
}
|
|
|
|
func (c *withMetrics) Create(arg0 context.Context, arg1 *k8s_io_api_authorization_v1.SubjectAccessReview, arg2 k8s_io_apimachinery_pkg_apis_meta_v1.CreateOptions) (*k8s_io_api_authorization_v1.SubjectAccessReview, error) {
|
|
defer c.recorder.Record("create")
|
|
return c.inner.Create(arg0, arg1, arg2)
|
|
}
|
|
|
|
type withTracing struct {
|
|
inner k8s_io_client_go_kubernetes_typed_authorization_v1.SubjectAccessReviewInterface
|
|
client string
|
|
kind string
|
|
}
|
|
|
|
func (c *withTracing) Create(arg0 context.Context, arg1 *k8s_io_api_authorization_v1.SubjectAccessReview, arg2 k8s_io_apimachinery_pkg_apis_meta_v1.CreateOptions) (*k8s_io_api_authorization_v1.SubjectAccessReview, error) {
|
|
ctx, span := tracing.StartSpan(
|
|
arg0,
|
|
"",
|
|
fmt.Sprintf("KUBE %s/%s/%s", c.client, c.kind, "Create"),
|
|
attribute.String("client", c.client),
|
|
attribute.String("kind", c.kind),
|
|
attribute.String("operation", "Create"),
|
|
)
|
|
defer span.End()
|
|
arg0 = ctx
|
|
ret0, ret1 := c.inner.Create(arg0, arg1, arg2)
|
|
if ret1 != nil {
|
|
span.RecordError(ret1)
|
|
span.SetStatus(codes.Error, ret1.Error())
|
|
}
|
|
return ret0, ret1
|
|
}
|