mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-15 20:20:22 +00:00
refactor: move all cli commands in a commands package (#8231)
* chore: name all cli command files the same Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * refactor: move all cli commands in a commands package Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * root Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> --------- Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
parent
b5030987a6
commit
cef4a9b546
50 changed files with 115 additions and 101 deletions
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/go-git/go-billy/v5/memfs"
|
"github.com/go-git/go-billy/v5/memfs"
|
||||||
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
||||||
"github.com/kyverno/kyverno/api/kyverno/v1beta1"
|
"github.com/kyverno/kyverno/api/kyverno/v1beta1"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/color"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/color"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/common"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/common"
|
||||||
reportutils "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/report"
|
reportutils "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/report"
|
|
@ -20,14 +20,14 @@ func Test_Apply(t *testing.T) {
|
||||||
stdinFile string
|
stdinFile string
|
||||||
}
|
}
|
||||||
// copy disallow_latest_tag.yaml to local path
|
// copy disallow_latest_tag.yaml to local path
|
||||||
localFileName, err := copyFileToThisDir("../../../../test/best_practices/disallow_latest_tag.yaml")
|
localFileName, err := copyFileToThisDir("../../../../../test/best_practices/disallow_latest_tag.yaml")
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
defer func() { _ = os.Remove(localFileName) }()
|
defer func() { _ = os.Remove(localFileName) }()
|
||||||
|
|
||||||
testcases := []*TestCase{{
|
testcases := []*TestCase{{
|
||||||
config: ApplyCommandConfig{
|
config: ApplyCommandConfig{
|
||||||
PolicyPaths: []string{"../../../../test/best_practices/disallow_latest_tag.yaml"},
|
PolicyPaths: []string{"../../../../../test/best_practices/disallow_latest_tag.yaml"},
|
||||||
ResourcePaths: []string{"../../../../test/resources/pod_with_version_tag.yaml"},
|
ResourcePaths: []string{"../../../../../test/resources/pod_with_version_tag.yaml"},
|
||||||
PolicyReport: true,
|
PolicyReport: true,
|
||||||
},
|
},
|
||||||
expectedPolicyReports: []policyreportv1alpha2.PolicyReport{{
|
expectedPolicyReports: []policyreportv1alpha2.PolicyReport{{
|
||||||
|
@ -42,7 +42,7 @@ func Test_Apply(t *testing.T) {
|
||||||
}, {
|
}, {
|
||||||
config: ApplyCommandConfig{
|
config: ApplyCommandConfig{
|
||||||
PolicyPaths: []string{localFileName},
|
PolicyPaths: []string{localFileName},
|
||||||
ResourcePaths: []string{"../../../../test/resources/pod_with_version_tag.yaml"},
|
ResourcePaths: []string{"../../../../../test/resources/pod_with_version_tag.yaml"},
|
||||||
PolicyReport: true,
|
PolicyReport: true,
|
||||||
},
|
},
|
||||||
expectedPolicyReports: []policyreportv1alpha2.PolicyReport{{
|
expectedPolicyReports: []policyreportv1alpha2.PolicyReport{{
|
||||||
|
@ -56,8 +56,8 @@ func Test_Apply(t *testing.T) {
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
config: ApplyCommandConfig{
|
config: ApplyCommandConfig{
|
||||||
PolicyPaths: []string{"../../../../test/best_practices/disallow_latest_tag.yaml"},
|
PolicyPaths: []string{"../../../../../test/best_practices/disallow_latest_tag.yaml"},
|
||||||
ResourcePaths: []string{"../../../../test/resources/pod_with_latest_tag.yaml"},
|
ResourcePaths: []string{"../../../../../test/resources/pod_with_latest_tag.yaml"},
|
||||||
PolicyReport: true,
|
PolicyReport: true,
|
||||||
},
|
},
|
||||||
expectedPolicyReports: []policyreportv1alpha2.PolicyReport{{
|
expectedPolicyReports: []policyreportv1alpha2.PolicyReport{{
|
||||||
|
@ -71,8 +71,8 @@ func Test_Apply(t *testing.T) {
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
config: ApplyCommandConfig{
|
config: ApplyCommandConfig{
|
||||||
PolicyPaths: []string{"../../../../test/cli/apply/policies"},
|
PolicyPaths: []string{"../../../../../test/cli/apply/policies"},
|
||||||
ResourcePaths: []string{"../../../../test/cli/apply/resource"},
|
ResourcePaths: []string{"../../../../../test/cli/apply/resource"},
|
||||||
PolicyReport: true,
|
PolicyReport: true,
|
||||||
},
|
},
|
||||||
expectedPolicyReports: []policyreportv1alpha2.PolicyReport{{
|
expectedPolicyReports: []policyreportv1alpha2.PolicyReport{{
|
||||||
|
@ -86,8 +86,8 @@ func Test_Apply(t *testing.T) {
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
config: ApplyCommandConfig{
|
config: ApplyCommandConfig{
|
||||||
PolicyPaths: []string{"../../../../test/best_practices/disallow_latest_tag.yaml"},
|
PolicyPaths: []string{"../../../../../test/best_practices/disallow_latest_tag.yaml"},
|
||||||
ResourcePaths: []string{"../../../../test/resources/pod_with_latest_tag.yaml"},
|
ResourcePaths: []string{"../../../../../test/resources/pod_with_latest_tag.yaml"},
|
||||||
PolicyReport: true,
|
PolicyReport: true,
|
||||||
AuditWarn: true,
|
AuditWarn: true,
|
||||||
},
|
},
|
||||||
|
@ -103,11 +103,11 @@ func Test_Apply(t *testing.T) {
|
||||||
}, {
|
}, {
|
||||||
config: ApplyCommandConfig{
|
config: ApplyCommandConfig{
|
||||||
PolicyPaths: []string{"-"},
|
PolicyPaths: []string{"-"},
|
||||||
ResourcePaths: []string{"../../../../test/resources/pod_with_latest_tag.yaml"},
|
ResourcePaths: []string{"../../../../../test/resources/pod_with_latest_tag.yaml"},
|
||||||
PolicyReport: true,
|
PolicyReport: true,
|
||||||
AuditWarn: true,
|
AuditWarn: true,
|
||||||
},
|
},
|
||||||
stdinFile: "../../../../test/best_practices/disallow_latest_tag.yaml",
|
stdinFile: "../../../../../test/best_practices/disallow_latest_tag.yaml",
|
||||||
expectedPolicyReports: []policyreportv1alpha2.PolicyReport{{
|
expectedPolicyReports: []policyreportv1alpha2.PolicyReport{{
|
||||||
Summary: policyreportv1alpha2.PolicyReportSummary{
|
Summary: policyreportv1alpha2.PolicyReportSummary{
|
||||||
Pass: 1,
|
Pass: 1,
|
||||||
|
@ -119,12 +119,12 @@ func Test_Apply(t *testing.T) {
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
config: ApplyCommandConfig{
|
config: ApplyCommandConfig{
|
||||||
PolicyPaths: []string{"../../../../test/best_practices/disallow_latest_tag.yaml"},
|
PolicyPaths: []string{"../../../../../test/best_practices/disallow_latest_tag.yaml"},
|
||||||
ResourcePaths: []string{"-"},
|
ResourcePaths: []string{"-"},
|
||||||
PolicyReport: true,
|
PolicyReport: true,
|
||||||
AuditWarn: true,
|
AuditWarn: true,
|
||||||
},
|
},
|
||||||
stdinFile: "../../../../test/resources/pod_with_latest_tag.yaml",
|
stdinFile: "../../../../../test/resources/pod_with_latest_tag.yaml",
|
||||||
expectedPolicyReports: []policyreportv1alpha2.PolicyReport{{
|
expectedPolicyReports: []policyreportv1alpha2.PolicyReport{{
|
||||||
Summary: policyreportv1alpha2.PolicyReportSummary{
|
Summary: policyreportv1alpha2.PolicyReportSummary{
|
||||||
Pass: 1,
|
Pass: 1,
|
||||||
|
@ -137,7 +137,7 @@ func Test_Apply(t *testing.T) {
|
||||||
}, {
|
}, {
|
||||||
config: ApplyCommandConfig{
|
config: ApplyCommandConfig{
|
||||||
PolicyPaths: []string{"https://github.com/kyverno/policies/openshift/team-validate-ns-name/"},
|
PolicyPaths: []string{"https://github.com/kyverno/policies/openshift/team-validate-ns-name/"},
|
||||||
ResourcePaths: []string{"../../../../test/openshift/team-validate-ns-name.yaml"},
|
ResourcePaths: []string{"../../../../../test/openshift/team-validate-ns-name.yaml"},
|
||||||
GitBranch: "main",
|
GitBranch: "main",
|
||||||
PolicyReport: true,
|
PolicyReport: true,
|
||||||
},
|
},
|
||||||
|
@ -152,8 +152,8 @@ func Test_Apply(t *testing.T) {
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
config: ApplyCommandConfig{
|
config: ApplyCommandConfig{
|
||||||
PolicyPaths: []string{"../../../../test/cli/apply/policies-set"},
|
PolicyPaths: []string{"../../../../../test/cli/apply/policies-set"},
|
||||||
ResourcePaths: []string{"../../../../test/cli/apply/resources-set"},
|
ResourcePaths: []string{"../../../../../test/cli/apply/resources-set"},
|
||||||
Variables: []string{"request.operation=UPDATE"},
|
Variables: []string{"request.operation=UPDATE"},
|
||||||
PolicyReport: true,
|
PolicyReport: true,
|
||||||
},
|
},
|
||||||
|
@ -168,8 +168,8 @@ func Test_Apply(t *testing.T) {
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
config: ApplyCommandConfig{
|
config: ApplyCommandConfig{
|
||||||
PolicyPaths: []string{"../../../../test/cli/test-validating-admission-policy/check-deployments-replica/policy.yaml"},
|
PolicyPaths: []string{"../../../../../test/cli/test-validating-admission-policy/check-deployments-replica/policy.yaml"},
|
||||||
ResourcePaths: []string{"../../../../test/cli/test-validating-admission-policy/check-deployments-replica/deployment1.yaml"},
|
ResourcePaths: []string{"../../../../../test/cli/test-validating-admission-policy/check-deployments-replica/deployment1.yaml"},
|
||||||
PolicyReport: true,
|
PolicyReport: true,
|
||||||
},
|
},
|
||||||
expectedPolicyReports: []policyreportv1alpha2.PolicyReport{{
|
expectedPolicyReports: []policyreportv1alpha2.PolicyReport{{
|
||||||
|
@ -183,8 +183,8 @@ func Test_Apply(t *testing.T) {
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
config: ApplyCommandConfig{
|
config: ApplyCommandConfig{
|
||||||
PolicyPaths: []string{"../../../../test/cli/test-validating-admission-policy/check-deployments-replica/policy.yaml"},
|
PolicyPaths: []string{"../../../../../test/cli/test-validating-admission-policy/check-deployments-replica/policy.yaml"},
|
||||||
ResourcePaths: []string{"../../../../test/cli/test-validating-admission-policy/check-deployments-replica/deployment2.yaml"},
|
ResourcePaths: []string{"../../../../../test/cli/test-validating-admission-policy/check-deployments-replica/deployment2.yaml"},
|
||||||
PolicyReport: true,
|
PolicyReport: true,
|
||||||
},
|
},
|
||||||
expectedPolicyReports: []policyreportv1alpha2.PolicyReport{{
|
expectedPolicyReports: []policyreportv1alpha2.PolicyReport{{
|
||||||
|
@ -198,8 +198,8 @@ func Test_Apply(t *testing.T) {
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
config: ApplyCommandConfig{
|
config: ApplyCommandConfig{
|
||||||
PolicyPaths: []string{"../../../../test/cli/test-validating-admission-policy/disallow-host-path/policy.yaml"},
|
PolicyPaths: []string{"../../../../../test/cli/test-validating-admission-policy/disallow-host-path/policy.yaml"},
|
||||||
ResourcePaths: []string{"../../../../test/cli/test-validating-admission-policy/disallow-host-path/pod1.yaml"},
|
ResourcePaths: []string{"../../../../../test/cli/test-validating-admission-policy/disallow-host-path/pod1.yaml"},
|
||||||
PolicyReport: true,
|
PolicyReport: true,
|
||||||
},
|
},
|
||||||
expectedPolicyReports: []policyreportv1alpha2.PolicyReport{{
|
expectedPolicyReports: []policyreportv1alpha2.PolicyReport{{
|
||||||
|
@ -213,8 +213,8 @@ func Test_Apply(t *testing.T) {
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
config: ApplyCommandConfig{
|
config: ApplyCommandConfig{
|
||||||
PolicyPaths: []string{"../../../../test/cli/test-validating-admission-policy/disallow-host-path/policy.yaml"},
|
PolicyPaths: []string{"../../../../../test/cli/test-validating-admission-policy/disallow-host-path/policy.yaml"},
|
||||||
ResourcePaths: []string{"../../../../test/cli/test-validating-admission-policy/disallow-host-path/pod2.yaml"},
|
ResourcePaths: []string{"../../../../../test/cli/test-validating-admission-policy/disallow-host-path/pod2.yaml"},
|
||||||
PolicyReport: true,
|
PolicyReport: true,
|
||||||
},
|
},
|
||||||
expectedPolicyReports: []policyreportv1alpha2.PolicyReport{{
|
expectedPolicyReports: []policyreportv1alpha2.PolicyReport{{
|
||||||
|
@ -228,8 +228,8 @@ func Test_Apply(t *testing.T) {
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
config: ApplyCommandConfig{
|
config: ApplyCommandConfig{
|
||||||
PolicyPaths: []string{"../../../../test/cli/test-validating-admission-policy/check-deployment-labels/policy.yaml"},
|
PolicyPaths: []string{"../../../../../test/cli/test-validating-admission-policy/check-deployment-labels/policy.yaml"},
|
||||||
ResourcePaths: []string{"../../../../test/cli/test-validating-admission-policy/check-deployment-labels/deployment1.yaml"},
|
ResourcePaths: []string{"../../../../../test/cli/test-validating-admission-policy/check-deployment-labels/deployment1.yaml"},
|
||||||
PolicyReport: true,
|
PolicyReport: true,
|
||||||
},
|
},
|
||||||
expectedPolicyReports: []policyreportv1alpha2.PolicyReport{{
|
expectedPolicyReports: []policyreportv1alpha2.PolicyReport{{
|
||||||
|
@ -243,8 +243,8 @@ func Test_Apply(t *testing.T) {
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
config: ApplyCommandConfig{
|
config: ApplyCommandConfig{
|
||||||
PolicyPaths: []string{"../../../../test/cli/test-validating-admission-policy/check-deployment-labels/policy.yaml"},
|
PolicyPaths: []string{"../../../../../test/cli/test-validating-admission-policy/check-deployment-labels/policy.yaml"},
|
||||||
ResourcePaths: []string{"../../../../test/cli/test-validating-admission-policy/check-deployment-labels/deployment2.yaml"},
|
ResourcePaths: []string{"../../../../../test/cli/test-validating-admission-policy/check-deployment-labels/deployment2.yaml"},
|
||||||
PolicyReport: true,
|
PolicyReport: true,
|
||||||
},
|
},
|
||||||
expectedPolicyReports: []policyreportv1alpha2.PolicyReport{{
|
expectedPolicyReports: []policyreportv1alpha2.PolicyReport{{
|
||||||
|
@ -258,8 +258,8 @@ func Test_Apply(t *testing.T) {
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
config: ApplyCommandConfig{
|
config: ApplyCommandConfig{
|
||||||
PolicyPaths: []string{"https://github.com/kyverno/policies/best-practices/require-labels/", "../../../../test/best_practices/disallow_latest_tag.yaml"},
|
PolicyPaths: []string{"https://github.com/kyverno/policies/best-practices/require-labels/", "../../../../../test/best_practices/disallow_latest_tag.yaml"},
|
||||||
ResourcePaths: []string{"../../../../test/resources/pod_with_version_tag.yaml"},
|
ResourcePaths: []string{"../../../../../test/resources/pod_with_version_tag.yaml"},
|
||||||
GitBranch: "main",
|
GitBranch: "main",
|
||||||
PolicyReport: true,
|
PolicyReport: true,
|
||||||
},
|
},
|
||||||
|
@ -275,8 +275,8 @@ func Test_Apply(t *testing.T) {
|
||||||
}, {
|
}, {
|
||||||
// Same as the above test case but the policy paths are reordered
|
// Same as the above test case but the policy paths are reordered
|
||||||
config: ApplyCommandConfig{
|
config: ApplyCommandConfig{
|
||||||
PolicyPaths: []string{"../../../../test/best_practices/disallow_latest_tag.yaml", "https://github.com/kyverno/policies/best-practices/require-labels/"},
|
PolicyPaths: []string{"../../../../../test/best_practices/disallow_latest_tag.yaml", "https://github.com/kyverno/policies/best-practices/require-labels/"},
|
||||||
ResourcePaths: []string{"../../../../test/resources/pod_with_version_tag.yaml"},
|
ResourcePaths: []string{"../../../../../test/resources/pod_with_version_tag.yaml"},
|
||||||
GitBranch: "main",
|
GitBranch: "main",
|
||||||
PolicyReport: true,
|
PolicyReport: true,
|
||||||
},
|
},
|
40
cmd/cli/kubectl-kyverno/commands/command.go
Normal file
40
cmd/cli/kubectl-kyverno/commands/command.go
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/apply"
|
||||||
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/create"
|
||||||
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/docs"
|
||||||
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/fix"
|
||||||
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/jp"
|
||||||
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/oci"
|
||||||
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test"
|
||||||
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/version"
|
||||||
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/experimental"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func RootCommand() *cobra.Command {
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "kyverno",
|
||||||
|
Long: "To enable experimental commands, KYVERNO_EXPERIMENTAL should be configured with true or 1.",
|
||||||
|
Short: "Kubernetes Native Policy Management",
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
return cmd.Help()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
cmd.AddCommand(
|
||||||
|
apply.Command(),
|
||||||
|
create.Command(),
|
||||||
|
docs.Command(cmd),
|
||||||
|
jp.Command(),
|
||||||
|
test.Command(),
|
||||||
|
version.Command(),
|
||||||
|
)
|
||||||
|
if experimental.IsExperimentalEnabled() {
|
||||||
|
cmd.AddCommand(
|
||||||
|
fix.Command(),
|
||||||
|
oci.Command(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return cmd
|
||||||
|
}
|
|
@ -1,10 +1,10 @@
|
||||||
package create
|
package create
|
||||||
|
|
||||||
import (
|
import (
|
||||||
metricsconfig "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/create/metrics-config"
|
metricsconfig "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/create/metrics-config"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/create/test"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/create/test"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/create/userinfo"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/create/userinfo"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/create/values"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/create/values"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/Masterminds/sprig/v3"
|
"github.com/Masterminds/sprig/v3"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/create/templates"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/create/templates"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/create/templates"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/create/templates"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/kyverno/kyverno/api/kyverno/v1beta1"
|
"github.com/kyverno/kyverno/api/kyverno/v1beta1"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/create/templates"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/create/templates"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
authenticationv1 "k8s.io/api/authentication/v1"
|
authenticationv1 "k8s.io/api/authentication/v1"
|
||||||
)
|
)
|
|
@ -5,8 +5,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/create/templates"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/create/templates"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package fix
|
package fix
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/fix/test"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/fix/test"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,9 +3,9 @@ package jp
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/jp/function"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/jp/function"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/jp/parse"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/jp/parse"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/jp/query"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/jp/query"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
|
@ -8,8 +8,8 @@ import (
|
||||||
"github.com/google/go-containerregistry/pkg/authn"
|
"github.com/google/go-containerregistry/pkg/authn"
|
||||||
"github.com/google/go-containerregistry/pkg/authn/github"
|
"github.com/google/go-containerregistry/pkg/authn/github"
|
||||||
"github.com/google/go-containerregistry/pkg/v1/google"
|
"github.com/google/go-containerregistry/pkg/v1/google"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/oci/pull"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/oci/pull"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/oci/push"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/oci/push"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/google/go-containerregistry/pkg/authn"
|
"github.com/google/go-containerregistry/pkg/authn"
|
||||||
"github.com/google/go-containerregistry/pkg/name"
|
"github.com/google/go-containerregistry/pkg/name"
|
||||||
"github.com/google/go-containerregistry/pkg/v1/remote"
|
"github.com/google/go-containerregistry/pkg/v1/remote"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/oci/internal"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/oci/internal"
|
||||||
policyutils "github.com/kyverno/kyverno/pkg/utils/policy"
|
policyutils "github.com/kyverno/kyverno/pkg/utils/policy"
|
||||||
yamlutils "github.com/kyverno/kyverno/pkg/utils/yaml"
|
yamlutils "github.com/kyverno/kyverno/pkg/utils/yaml"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/google/go-containerregistry/pkg/v1/remote"
|
"github.com/google/go-containerregistry/pkg/v1/remote"
|
||||||
"github.com/google/go-containerregistry/pkg/v1/static"
|
"github.com/google/go-containerregistry/pkg/v1/static"
|
||||||
"github.com/google/go-containerregistry/pkg/v1/types"
|
"github.com/google/go-containerregistry/pkg/v1/types"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/oci/internal"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/oci/internal"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/common"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/common"
|
||||||
"github.com/kyverno/kyverno/pkg/config"
|
"github.com/kyverno/kyverno/pkg/config"
|
||||||
"github.com/kyverno/kyverno/pkg/openapi"
|
"github.com/kyverno/kyverno/pkg/openapi"
|
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
"github.com/go-git/go-billy/v5"
|
"github.com/go-git/go-billy/v5"
|
||||||
policyreportv1alpha2 "github.com/kyverno/kyverno/api/policyreport/v1alpha2"
|
policyreportv1alpha2 "github.com/kyverno/kyverno/api/policyreport/v1alpha2"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/color"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/color"
|
||||||
filterutils "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/filter"
|
filterutils "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/filter"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/output/table"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/output/table"
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/go-git/go-billy/v5/memfs"
|
"github.com/go-git/go-billy/v5/memfs"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/common"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/common"
|
||||||
"gotest.tools/assert"
|
"gotest.tools/assert"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
|
@ -20,7 +20,7 @@ func Test_selectResourcesForCheck(t *testing.T) {
|
||||||
expectedDuplicates int
|
expectedDuplicates int
|
||||||
expectedUnused int
|
expectedUnused int
|
||||||
}
|
}
|
||||||
baseTestDir := "../../../../test/cli/test-unit/selectResourcesForCheck/"
|
baseTestDir := "../../../../../test/cli/test-unit/selectResourcesForCheck/"
|
||||||
testcases := []*TestCase{
|
testcases := []*TestCase{
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/go-git/go-billy/v5"
|
"github.com/go-git/go-billy/v5"
|
||||||
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
||||||
"github.com/kyverno/kyverno/api/kyverno/v1beta1"
|
"github.com/kyverno/kyverno/api/kyverno/v1beta1"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/common"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/common"
|
||||||
filterutils "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/filter"
|
filterutils "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/filter"
|
||||||
pathutils "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/path"
|
pathutils "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/path"
|
|
@ -5,28 +5,15 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/apply"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/create"
|
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/docs"
|
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/fix"
|
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/jp"
|
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/oci"
|
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test"
|
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/experimental"
|
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/version"
|
|
||||||
"github.com/kyverno/kyverno/pkg/logging"
|
"github.com/kyverno/kyverno/pkg/logging"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cli := &cobra.Command{
|
cmd := commands.RootCommand()
|
||||||
Use: "kyverno",
|
configureLogs(cmd)
|
||||||
Long: "To enable experimental commands, KYVERNO_EXPERIMENTAL should be configured with true or 1.",
|
if err := cmd.Execute(); err != nil {
|
||||||
Short: "Kubernetes Native Policy Management",
|
|
||||||
}
|
|
||||||
configureLogs(cli)
|
|
||||||
registerCommands(cli)
|
|
||||||
if err := cli.Execute(); err != nil {
|
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,20 +26,3 @@ func configureLogs(cli *cobra.Command) {
|
||||||
}
|
}
|
||||||
cli.PersistentFlags().AddGoFlagSet(flag.CommandLine)
|
cli.PersistentFlags().AddGoFlagSet(flag.CommandLine)
|
||||||
}
|
}
|
||||||
|
|
||||||
func registerCommands(cli *cobra.Command) {
|
|
||||||
cli.AddCommand(
|
|
||||||
apply.Command(),
|
|
||||||
create.Command(),
|
|
||||||
docs.Command(cli),
|
|
||||||
jp.Command(),
|
|
||||||
test.Command(),
|
|
||||||
version.Command(),
|
|
||||||
)
|
|
||||||
if experimental.IsExperimentalEnabled() {
|
|
||||||
cli.AddCommand(
|
|
||||||
fix.Command(),
|
|
||||||
oci.Command(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
"github.com/go-git/go-billy/v5"
|
"github.com/go-git/go-billy/v5"
|
||||||
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
||||||
kyvernov1beta1 "github.com/kyverno/kyverno/api/kyverno/v1beta1"
|
kyvernov1beta1 "github.com/kyverno/kyverno/api/kyverno/v1beta1"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
||||||
annotationsutils "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/annotations"
|
annotationsutils "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/annotations"
|
||||||
sanitizederror "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/sanitizedError"
|
sanitizederror "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/sanitizedError"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/source"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/source"
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/kyverno/kyverno/api/kyverno/v1beta1"
|
"github.com/kyverno/kyverno/api/kyverno/v1beta1"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
||||||
yamlutils "github.com/kyverno/kyverno/pkg/utils/yaml"
|
yamlutils "github.com/kyverno/kyverno/pkg/utils/yaml"
|
||||||
"gotest.tools/assert"
|
"gotest.tools/assert"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
|
|
||||||
"github.com/go-git/go-billy/v5"
|
"github.com/go-git/go-billy/v5"
|
||||||
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/source"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/source"
|
||||||
"github.com/kyverno/kyverno/pkg/autogen"
|
"github.com/kyverno/kyverno/pkg/autogen"
|
||||||
"github.com/kyverno/kyverno/pkg/clients/dclient"
|
"github.com/kyverno/kyverno/pkg/clients/dclient"
|
||||||
|
|
|
@ -2,7 +2,7 @@ package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
||||||
"github.com/kyverno/kyverno/pkg/autogen"
|
"github.com/kyverno/kyverno/pkg/autogen"
|
||||||
"github.com/kyverno/kyverno/pkg/clients/dclient"
|
"github.com/kyverno/kyverno/pkg/clients/dclient"
|
||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
||||||
"github.com/kyverno/kyverno/pkg/clients/dclient"
|
"github.com/kyverno/kyverno/pkg/clients/dclient"
|
||||||
"k8s.io/api/admissionregistration/v1alpha1"
|
"k8s.io/api/admissionregistration/v1alpha1"
|
||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/go-git/go-billy/v5"
|
"github.com/go-git/go-billy/v5"
|
||||||
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
||||||
sanitizederror "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/sanitizedError"
|
sanitizederror "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/sanitizedError"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/store"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/store"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/values"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/values"
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
||||||
"github.com/kyverno/kyverno/pkg/utils/wildcard"
|
"github.com/kyverno/kyverno/pkg/utils/wildcard"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_policy_Apply(t *testing.T) {
|
func Test_policy_Apply(t *testing.T) {
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/go-git/go-billy/v5"
|
"github.com/go-git/go-billy/v5"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
||||||
"k8s.io/apimachinery/pkg/util/yaml"
|
"k8s.io/apimachinery/pkg/util/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
policyreportv1alpha2 "github.com/kyverno/kyverno/api/policyreport/v1alpha2"
|
policyreportv1alpha2 "github.com/kyverno/kyverno/api/policyreport/v1alpha2"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTestCases_Errors(t *testing.T) {
|
func TestTestCases_Errors(t *testing.T) {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/go-git/go-billy/v5"
|
"github.com/go-git/go-billy/v5"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
||||||
"k8s.io/apimachinery/pkg/util/yaml"
|
"k8s.io/apimachinery/pkg/util/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/go-git/go-billy/v5"
|
"github.com/go-git/go-billy/v5"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_readFile(t *testing.T) {
|
func Test_readFile(t *testing.T) {
|
||||||
|
|
|
@ -6,6 +6,10 @@ Kubernetes Native Policy Management
|
||||||
|
|
||||||
To enable experimental commands, KYVERNO_EXPERIMENTAL should be configured with true or 1.
|
To enable experimental commands, KYVERNO_EXPERIMENTAL should be configured with true or 1.
|
||||||
|
|
||||||
|
```
|
||||||
|
kyverno [flags]
|
||||||
|
```
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
Loading…
Add table
Reference in a new issue