From 26e5bd76c7b28868629f44d19f65917aa35fa309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Edouard=20Br=C3=A9t=C3=A9ch=C3=A9?= Date: Mon, 3 Jul 2023 15:22:05 +0200 Subject: [PATCH] fix: refactor cli values loading and remove dead code (#7739) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Charles-Edouard Brétéché --- .../kubectl-kyverno/apply/apply_command.go | 107 ++++++++--------- cmd/cli/kubectl-kyverno/test/api/types.go | 14 --- .../kubectl-kyverno/utils/common/common.go | 109 ++++-------------- .../utils/common/common_test.go | 3 +- cmd/cli/kubectl-kyverno/utils/common/fetch.go | 19 +-- .../utils/common/kyverno_resources_types.go | 3 +- .../validatingadmission_resources_types.go | 3 +- cmd/cli/kubectl-kyverno/utils/values/load.go | 37 ++++++ cmd/cli/kubectl-kyverno/utils/values/types.go | 39 +++++++ 9 files changed, 163 insertions(+), 171 deletions(-) create mode 100644 cmd/cli/kubectl-kyverno/utils/values/load.go create mode 100644 cmd/cli/kubectl-kyverno/utils/values/types.go diff --git a/cmd/cli/kubectl-kyverno/apply/apply_command.go b/cmd/cli/kubectl-kyverno/apply/apply_command.go index b1ecca061a..f5be7553cf 100644 --- a/cmd/cli/kubectl-kyverno/apply/apply_command.go +++ b/cmd/cli/kubectl-kyverno/apply/apply_command.go @@ -32,20 +32,6 @@ import ( yaml1 "sigs.k8s.io/yaml" ) -type Resource struct { - Name string `json:"name"` - Values map[string]string `json:"values"` -} - -type Policy struct { - Name string `json:"name"` - Resources []Resource `json:"resources"` -} - -type Values struct { - Policies []Policy `json:"policies"` -} - type SkippedInvalidPolicies struct { skipped []string invalid []string @@ -73,7 +59,6 @@ type ApplyCommandConfig struct { var ( applyHelp = ` - To apply on a resource: kyverno apply /path/to/policy.yaml /path/to/folderOfPolicies --resource=/path/to/resource1 --resource=/path/to/resource2 @@ -84,58 +69,58 @@ To apply on a cluster: kyverno apply /path/to/policy.yaml /path/to/folderOfPolicies --cluster To apply policies from a gitSourceURL on a cluster: - Example: Taking github.com as a gitSourceURL here. Some other standards gitSourceURL are: gitlab.com , bitbucket.org , etc. - kyverno apply https://github.com/kyverno/policies/openshift/ --git-branch main --cluster + Example: Taking github.com as a gitSourceURL here. Some other standards gitSourceURL are: gitlab.com , bitbucket.org , etc. + kyverno apply https://github.com/kyverno/policies/openshift/ --git-branch main --cluster To apply policy with variables: - 1. To apply single policy with variable on single resource use flag "set". - Example: - kyverno apply /path/to/policy.yaml --resource /path/to/resource.yaml --set =,= + 1. To apply single policy with variable on single resource use flag "set". + Example: + kyverno apply /path/to/policy.yaml --resource /path/to/resource.yaml --set =,= - 2. To apply multiple policy with variable on multiple resource use flag "values_file". - Example: - kyverno apply /path/to/policy1.yaml /path/to/policy2.yaml --resource /path/to/resource1.yaml --resource /path/to/resource2.yaml -f /path/to/value.yaml + 2. To apply multiple policy with variable on multiple resource use flag "values_file". + Example: + kyverno apply /path/to/policy1.yaml /path/to/policy2.yaml --resource /path/to/resource1.yaml --resource /path/to/resource2.yaml -f /path/to/value.yaml - Format of value.yaml: + Format of value.yaml: - policies: - - name: - rules: - - name: - values: - : - : - - name: - values: - : - : - resources: - - name: - values: - : - : - - name: - values: - : - : - - name: - resources: - - name: - values: - : - : - - name: - values: - : - : - namespaceSelector: - - name: - labels: -