From e2e40a066ebb44bf69d7b78ee83dd0214af33afb Mon Sep 17 00:00:00 2001 From: achimweigel Date: Wed, 24 Jan 2024 13:07:02 +0100 Subject: [PATCH] Investigate strict checks (#955) * logging for webhook errors (run-int-tests) --- cmd/landscaper-agent/app/options.go | 3 ++- cmd/landscaper-controller/app/app.go | 3 ++- pkg/deployer/lib/cmd/default.go | 3 ++- pkg/utils/webhook/webhook.go | 26 ++++++++++++++++++++++---- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/cmd/landscaper-agent/app/options.go b/cmd/landscaper-agent/app/options.go index aa6fadeeb..4ca6817fd 100644 --- a/cmd/landscaper-agent/app/options.go +++ b/cmd/landscaper-agent/app/options.go @@ -8,10 +8,11 @@ import ( "errors" goflag "flag" "fmt" - "k8s.io/utils/pointer" "os" "time" + "k8s.io/utils/pointer" + flag "github.com/spf13/pflag" "k8s.io/apimachinery/pkg/runtime/serializer" "k8s.io/client-go/tools/clientcmd" diff --git a/cmd/landscaper-controller/app/app.go b/cmd/landscaper-controller/app/app.go index b7a0140c7..762cb88e4 100644 --- a/cmd/landscaper-controller/app/app.go +++ b/cmd/landscaper-controller/app/app.go @@ -7,10 +7,11 @@ package app import ( "context" "fmt" - "k8s.io/utils/pointer" "os" "time" + "k8s.io/utils/pointer" + "github.com/mandelsoft/vfs/pkg/osfs" "github.com/spf13/cobra" "golang.org/x/sync/errgroup" diff --git a/pkg/deployer/lib/cmd/default.go b/pkg/deployer/lib/cmd/default.go index 19bd533a8..b9c051739 100644 --- a/pkg/deployer/lib/cmd/default.go +++ b/pkg/deployer/lib/cmd/default.go @@ -9,10 +9,11 @@ import ( "errors" goflag "flag" "fmt" - "k8s.io/utils/pointer" "os" "time" + "k8s.io/utils/pointer" + flag "github.com/spf13/pflag" "golang.org/x/sync/errgroup" v1 "k8s.io/api/core/v1" diff --git a/pkg/utils/webhook/webhook.go b/pkg/utils/webhook/webhook.go index 8b6ac7b7a..b124716ce 100644 --- a/pkg/utils/webhook/webhook.go +++ b/pkg/utils/webhook/webhook.go @@ -25,13 +25,17 @@ import ( // INSTALLATION var InstallationWebhookLogic webhooklib.WebhookLogic = func(ctx context.Context, req admission.Request, dec runtime.Decoder) admission.Response { + logger, _ := logging.FromContextOrNew(ctx, []interface{}{lc.KeyMethod, "InstallationWebhookLogic"}) inst := &lscore.Installation{} if _, _, err := dec.Decode(req.Object.Raw, nil, inst); err != nil { + logger.Debug("Decoding failed: " + err.Error()) return admission.Errored(http.StatusBadRequest, err) } if errs := validation.ValidateInstallation(inst); len(errs) > 0 { - return admission.Denied(errs.ToAggregate().Error()) + aggErr := errs.ToAggregate().Error() + logger.Debug("Validation failed: " + aggErr) + return admission.Denied(aggErr) } return admission.Allowed("Installation is valid") @@ -44,17 +48,21 @@ var DeployItemWebhookLogic webhooklib.WebhookLogic = func(ctx context.Context, r di := &lscore.DeployItem{} if _, _, err := dec.Decode(req.Object.Raw, nil, di); err != nil { + logger.Debug("Decoding failed: " + err.Error()) return admission.Errored(http.StatusBadRequest, err) } if errs := validation.ValidateDeployItem(di); len(errs) > 0 { - return admission.Denied(errs.ToAggregate().Error()) + aggErr := errs.ToAggregate().Error() + logger.Debug("Validation failed: " + aggErr) + return admission.Denied(aggErr) } // check if the type was updated for update events if req.Operation == admissionv1.Update { oldDi := &lscore.DeployItem{} if _, _, err := dec.Decode(req.OldObject.Raw, nil, oldDi); err != nil { + logger.Debug("Decoding old failed: " + err.Error()) return admission.Errored(http.StatusBadRequest, err) } if oldDi.Spec.Type != di.Spec.Type { @@ -69,13 +77,18 @@ var DeployItemWebhookLogic webhooklib.WebhookLogic = func(ctx context.Context, r // EXECUTION var ExecutionWebhookLogic webhooklib.WebhookLogic = func(ctx context.Context, req admission.Request, dec runtime.Decoder) admission.Response { + logger, _ := logging.FromContextOrNew(ctx, []interface{}{lc.KeyMethod, "ExecutionWebhookLogic"}) + exec := &lscore.Execution{} if _, _, err := dec.Decode(req.Object.Raw, nil, exec); err != nil { + logger.Debug("Decoding failed: " + err.Error()) return admission.Errored(http.StatusBadRequest, err) } if errs := validation.ValidateExecution(exec); len(errs) > 0 { - return admission.Denied(errs.ToAggregate().Error()) + aggErr := errs.ToAggregate().Error() + logger.Debug("Validation failed: " + aggErr) + return admission.Denied(aggErr) } return admission.Allowed("Execution is valid") @@ -84,13 +97,18 @@ var ExecutionWebhookLogic webhooklib.WebhookLogic = func(ctx context.Context, re // TARGET var TargetWebhookLogic webhooklib.WebhookLogic = func(ctx context.Context, req admission.Request, dec runtime.Decoder) admission.Response { + logger, _ := logging.FromContextOrNew(ctx, []interface{}{lc.KeyMethod, "ExecutionWebhookLogic"}) + t := &lscore.Target{} if _, _, err := dec.Decode(req.Object.Raw, nil, t); err != nil { + logger.Debug("Decoding failed: " + err.Error()) return admission.Errored(http.StatusBadRequest, err) } if errs := validation.ValidateTarget(t); len(errs) > 0 { - return admission.Denied(errs.ToAggregate().Error()) + aggErr := errs.ToAggregate().Error() + logger.Debug("Validation failed: " + aggErr) + return admission.Denied(aggErr) } return admission.Allowed("Target is valid")