Skip to content

Commit

Permalink
Update naming
Browse files Browse the repository at this point in the history
  • Loading branch information
mviswanathsai committed Jan 11, 2024
1 parent 72bcb31 commit a6133e5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
40 changes: 20 additions & 20 deletions cmd/cli/kubectl-kyverno/commands/apply/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,24 @@ type SkippedInvalidPolicies struct {
}

type ApplyCommandConfig struct {
KubeConfig string
Context string
Namespace string
MutateLogPath string
Variables []string
ValuesFile string
UserInfoPath string
Cluster bool
PolicyReport bool
Stdin bool
RegistryAccess bool
AuditWarn bool
ResourcePaths []string
PolicyPaths []string
GitBranch string
warnExitCode int
warnNoPassed bool
genericJSONResource bool
KubeConfig string
Context string
Namespace string
MutateLogPath string
Variables []string
ValuesFile string
UserInfoPath string
Cluster bool
PolicyReport bool
Stdin bool
RegistryAccess bool
AuditWarn bool
ResourcePaths []string
PolicyPaths []string
GitBranch string
warnExitCode int
warnNoPassed bool
genericResource bool
}

func Command() *cobra.Command {
Expand Down Expand Up @@ -97,7 +97,7 @@ func Command() *cobra.Command {
}
cmd.Flags().StringSliceVarP(&applyCommandConfig.ResourcePaths, "resource", "r", []string{}, "Path to resource files")
cmd.Flags().BoolVarP(&applyCommandConfig.Cluster, "cluster", "c", false, "Checks if policies should be applied to cluster in the current context")
cmd.Flags().BoolVar(&applyCommandConfig.genericJSONResource, "genericjson", false, "Apply policy to a file that is not a kubernetes resource. for eg, does not contain `apiVersion` and `kind`")
cmd.Flags().BoolVar(&applyCommandConfig.genericResource, "genericresource", false, "Apply policy to a file that is not a kubernetes resource. for eg, does not contain `apiVersion` and `kind`")
cmd.Flags().StringVarP(&applyCommandConfig.MutateLogPath, "output", "o", "", "Prints the mutated resources in provided file/directory")
// currently `set` flag supports variable for single policy applied on single resource
cmd.Flags().StringVarP(&applyCommandConfig.UserInfoPath, "userinfo", "u", "", "Admission Info including Roles, Cluster Roles and Subjects")
Expand Down Expand Up @@ -286,7 +286,7 @@ func (c *ApplyCommandConfig) applyPolicytoResource(
}

func (c *ApplyCommandConfig) loadResources(out io.Writer, policies []kyvernov1.PolicyInterface, validatingAdmissionPolicies []v1alpha1.ValidatingAdmissionPolicy, dClient dclient.Interface) ([]*unstructured.Unstructured, error) {
resources, err := common.GetResourceAccordingToResourcePath(out, nil, c.ResourcePaths, c.Cluster, policies, validatingAdmissionPolicies, dClient, c.Namespace, c.PolicyReport, "", c.genericJSONResource)
resources, err := common.GetResourceAccordingToResourcePath(out, nil, c.ResourcePaths, c.Cluster, policies, validatingAdmissionPolicies, dClient, c.Namespace, c.PolicyReport, "", c.genericResource)
if err != nil {
return resources, fmt.Errorf("failed to load resources (%w)", err)
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/cli/kubectl-kyverno/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
)

const (
GenericJSONApiVersion = "V1"
GenericJSONResourceKind = "GenericJSONResource"
GenericResourceApiVersion = "V1"
GenericResourceKind = "GenericJSONResource"
)

func GetUnstructuredResources(resourceBytes []byte) ([]*unstructured.Unstructured, error) {
Expand Down Expand Up @@ -159,8 +159,8 @@ func prependGVKToGenericJSON(resourceJSON []byte) ([]byte, error) {
return nil, fmt.Errorf("Error in unmarshalling to intermediate object: %w", err)
}

bytes["apiVersion"] = GenericJSONApiVersion
bytes["kind"] = GenericJSONResourceKind
bytes["apiVersion"] = GenericResourceApiVersion
bytes["kind"] = GenericResourceKind

finalResourceJSON, err := json.Marshal(bytes)

Check failure on line 166 in cmd/cli/kubectl-kyverno/resource/resource.go

View workflow job for this annotation

GitHub Actions / tests

File is not `gofumpt`-ed (gofumpt)
Expand Down
4 changes: 2 additions & 2 deletions cmd/cli/kubectl-kyverno/utils/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func GetResourceAccordingToResourcePath(
namespace string,
policyReport bool,
policyResourcePath string,
isGenericJson bool,
isGenericResource bool,
) (resources []*unstructured.Unstructured, err error) {
if fs != nil {
//TODO: add logic here too for generic JSON

Check failure on line 41 in cmd/cli/kubectl-kyverno/utils/common/common.go

View workflow job for this annotation

GitHub Actions / tests

File is not `gofumpt`-ed (gofumpt)
Expand Down Expand Up @@ -83,7 +83,7 @@ func GetResourceAccordingToResourcePath(
}
}

resources, err = GetResources(out, policies, validatingAdmissionPolicies, resourcePaths, dClient, cluster, namespace, policyReport, isGenericJson)
resources, err = GetResources(out, policies, validatingAdmissionPolicies, resourcePaths, dClient, cluster, namespace, policyReport, isGenericResource)
if err != nil {
return resources, err
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/utils/match/kind.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package match

import (
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/resource"
"github.com/kyverno/kyverno/ext/wildcard"
kubeutils "github.com/kyverno/kyverno/pkg/utils/kube"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand All @@ -14,7 +15,7 @@ var podGVK = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Pod"}
func CheckKind(kinds []string, gvk schema.GroupVersionKind, subresource string, allowEphemeralContainers bool) bool {
for _, k := range kinds {
group, version, kind, sub := kubeutils.ParseKindSelector(k)
matchKind := wildcard.Match(kind, gvk.Kind) || gvk.Kind == "GenericJSONResource"
matchKind := wildcard.Match(kind, gvk.Kind) || gvk.Kind == resource.GenericResourceKind
if wildcard.Match(group, gvk.Group) && wildcard.Match(version, gvk.Version) && matchKind {
if wildcard.Match(sub, subresource) {
return true
Expand Down

0 comments on commit a6133e5

Please sign in to comment.