Skip to content

Commit

Permalink
Merge pull request #157 from MariamFahmy98/cherrypick-11237-2
Browse files Browse the repository at this point in the history
feat: add dumpPatch flag
  • Loading branch information
amittiwari28 authored Oct 3, 2024
2 parents c96c5ad + c8ec5fe commit dac9dec
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions charts/kyverno/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ The chart values are organised per component.
| features.configMapCaching.enabled | bool | `true` | Enables the feature |
| features.deferredLoading.enabled | bool | `true` | Enables the feature |
| features.dumpPayload.enabled | bool | `false` | Enables the feature |
| features.dumpPatches.enabled | bool | `false` | Enables the feature |
| features.forceFailurePolicyIgnore.enabled | bool | `false` | Enables the feature |
| features.logging.format | string | `"text"` | Logging format |
| features.logging.verbosity | int | `2` | Logging verbosity |
Expand Down
3 changes: 3 additions & 0 deletions charts/kyverno/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
{{- with .dumpPayload -}}
{{- $flags = append $flags (print "--dumpPayload=" .enabled) -}}
{{- end -}}
{{- with .dumpPatches -}}
{{- $flags = append $flags (print "--dumpPatches=" .enabled) -}}
{{- end -}}
{{- with .forceFailurePolicyIgnore -}}
{{- $flags = append $flags (print "--forceFailurePolicyIgnore=" .enabled) -}}
{{- end -}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ spec:
"deferredLoading"
"dumpPayload"
"forceFailurePolicyIgnore"
"dumpPatches"
"logging"
"omitEvents"
"policyExceptions"
Expand Down
3 changes: 3 additions & 0 deletions charts/kyverno/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,9 @@ features:
dumpPayload:
# -- Enables the feature
enabled: false
dumpPatches:
# -- Enables the feature
enabled: false
forceFailurePolicyIgnore:
# -- Enables the feature
enabled: false
Expand Down
1 change: 1 addition & 0 deletions cmd/kyverno/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ func main() {
flagset.DurationVar(&webhookRegistrationTimeout, "webhookRegistrationTimeout", 120*time.Second, "Timeout for webhook registration, e.g., 30s, 1m, 5m.")
flagset.Func(toggle.ProtectManagedResourcesFlagName, toggle.ProtectManagedResourcesDescription, toggle.ProtectManagedResources.Parse)
flagset.Func(toggle.ForceFailurePolicyIgnoreFlagName, toggle.ForceFailurePolicyIgnoreDescription, toggle.ForceFailurePolicyIgnore.Parse)
flagset.Func(toggle.DumpMutatePatchesFlagName, toggle.DumpMutatePatchesDescription, toggle.DumpMutatePatches.Parse)
flagset.BoolVar(&admissionReports, "admissionReports", true, "Enable or disable admission reports.")
flagset.IntVar(&servicePort, "servicePort", 443, "Port used by the Kyverno Service resource and for webhook configurations.")
flagset.StringVar(&backgroundServiceAccountName, "backgroundServiceAccountName", "", "Background service account name.")
Expand Down
1 change: 1 addition & 0 deletions config/install-latest-testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32426,6 +32426,7 @@ spec:
- --enableConfigMapCaching=true
- --enableDeferredLoading=true
- --dumpPayload=false
- --dumpPatches=false
- --forceFailurePolicyIgnore=false
- --loggingFormat=text
- --v=2
Expand Down
6 changes: 6 additions & 0 deletions pkg/toggle/toggle.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ const (
EnableDeferredLoadingDescription = "enable deferred loading of context variables"
enableDeferredLoadingEnvVar = "FLAG_ENABLE_DEFERRED_LOADING"
defaultEnableDeferredLoading = true
// dump mutate patches
DumpMutatePatchesFlagName = "dumpPatches"
DumpMutatePatchesDescription = "Set the flag to 'true', to dump mutate patches."
dumpMutatePatchesEnvVar = "FLAG_DUMP_PATCHES"
defaultDumpMutatePatches = false
)

var (
ProtectManagedResources = newToggle(defaultProtectManagedResources, protectManagedResourcesEnvVar)
ForceFailurePolicyIgnore = newToggle(defaultForceFailurePolicyIgnore, forceFailurePolicyIgnoreEnvVar)
EnableDeferredLoading = newToggle(defaultEnableDeferredLoading, enableDeferredLoadingEnvVar)
DumpMutatePatches = newToggle(defaultDumpMutatePatches, dumpMutatePatchesEnvVar)
)

type Toggle interface {
Expand Down
5 changes: 4 additions & 1 deletion pkg/webhooks/resource/mutation/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/kyverno/kyverno/pkg/event"
"github.com/kyverno/kyverno/pkg/metrics"
"github.com/kyverno/kyverno/pkg/openapi"
"github.com/kyverno/kyverno/pkg/toggle"
"github.com/kyverno/kyverno/pkg/tracing"
engineutils "github.com/kyverno/kyverno/pkg/utils/engine"
jsonutils "github.com/kyverno/kyverno/pkg/utils/json"
Expand Down Expand Up @@ -66,7 +67,9 @@ func (h *mutationHandler) HandleMutation(
if err != nil {
return nil, nil, err
}
h.log.V(6).Info("", "generated patches", string(mutatePatches))
if toggle.DumpMutatePatches.Enabled() {
h.log.V(2).Info("", "generated patches", string(mutatePatches))
}
return mutatePatches, webhookutils.GetWarningMessages(mutateEngineResponses), nil
}

Expand Down

0 comments on commit dac9dec

Please sign in to comment.