Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add dumpPatch flag #156

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions charts/kyverno/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ The chart values are organised per component.
| features.dumpPayload.enabled | bool | `false` | Enables the feature |
| features.forceFailurePolicyIgnore.enabled | bool | `false` | Enables the feature |
| features.generateValidatingAdmissionPolicy.enabled | bool | `false` | Enables the feature |
| features.dumpPatches.enabled | bool | `false` | Enables the feature |
| features.logging.format | string | `"text"` | Logging format |
| features.logging.verbosity | int | `2` | Logging verbosity |
| features.omitEvents.eventTypes | list | `[]` | Events which should not be emitted (possible values `PolicyViolation`, `PolicyApplied`, `PolicyError`, and `PolicySkipped`) |
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 @@ -46,6 +46,9 @@
{{- with .generateValidatingAdmissionPolicy -}}
{{- $flags = append $flags (print "--generateValidatingAdmissionPolicy=" .enabled) -}}
{{- end -}}
{{- with .dumpPatches -}}
{{- $flags = append $flags (print "--dumpPatches=" .enabled) -}}
{{- end -}}
{{- with .logging -}}
{{- $flags = append $flags (print "--loggingFormat=" .format) -}}
{{- $flags = append $flags (print "--v=" (join "," .verbosity)) -}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ spec:
"dumpPayload"
"forceFailurePolicyIgnore"
"generateValidatingAdmissionPolicy"
"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 @@ -493,6 +493,9 @@ features:
generateValidatingAdmissionPolicy:
# -- Enables the feature
enabled: false
dumpPatches:
# -- Enables the feature
enabled: false
logging:
# -- Logging format
format: text
Expand Down
1 change: 1 addition & 0 deletions cmd/kyverno/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ func main() {
flagset.Func(toggle.ProtectManagedResourcesFlagName, toggle.ProtectManagedResourcesDescription, toggle.ProtectManagedResources.Parse)
flagset.Func(toggle.ForceFailurePolicyIgnoreFlagName, toggle.ForceFailurePolicyIgnoreDescription, toggle.ForceFailurePolicyIgnore.Parse)
flagset.Func(toggle.GenerateValidatingAdmissionPolicyFlagName, toggle.GenerateValidatingAdmissionPolicyDescription, toggle.GenerateValidatingAdmissionPolicy.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 @@ -42179,6 +42179,7 @@ spec:
- --dumpPayload=false
- --forceFailurePolicyIgnore=false
- --generateValidatingAdmissionPolicy=false
- --dumpPatches=false
- --loggingFormat=text
- --v=2
- --enablePolicyException=true
Expand Down
5 changes: 5 additions & 0 deletions pkg/toggle/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Toggles interface {
ForceFailurePolicyIgnore() bool
EnableDeferredLoading() bool
GenerateValidatingAdmissionPolicy() bool
DumpMutatePatches() bool
}

type defaultToggles struct{}
Expand All @@ -31,6 +32,10 @@ func (defaultToggles) GenerateValidatingAdmissionPolicy() bool {
return GenerateValidatingAdmissionPolicy.enabled()
}

func (defaultToggles) DumpMutatePatches() bool {
return DumpMutatePatches.enabled()
}

type contextKey struct{}

func NewContext(ctx context.Context, toggles Toggles) context.Context {
Expand Down
6 changes: 6 additions & 0 deletions pkg/toggle/toggle.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@ const (
GenerateValidatingAdmissionPolicyDescription = "Set the flag to 'true', to generate validating admission policies."
generateValidatingAdmissionPolicyEnvVar = "FLAG_GENERATE_VALIDATING_ADMISSION_POLICY"
defaultGenerateValidatingAdmissionPolicy = false
// 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)
GenerateValidatingAdmissionPolicy = newToggle(defaultGenerateValidatingAdmissionPolicy, generateValidatingAdmissionPolicyEnvVar)
DumpMutatePatches = newToggle(defaultDumpMutatePatches, dumpMutatePatchesEnvVar)
)

type ToggleFlag 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/engine/mutate/patch"
"github.com/kyverno/kyverno/pkg/event"
"github.com/kyverno/kyverno/pkg/metrics"
"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 @@ -64,7 +65,9 @@ func (h *mutationHandler) HandleMutation(
if err != nil {
return nil, nil, err
}
h.log.V(6).Info("", "generated patches", string(mutatePatches))
if toggle.FromContext(ctx).DumpMutatePatches() {
h.log.V(2).Info("", "generated patches", string(mutatePatches))
}
return mutatePatches, webhookutils.GetWarningMessages(mutateEngineResponses), nil
}

Expand Down
Loading