mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-05 07:26:55 +00:00
Revert "added -exception flag loaded policyexception"
This reverts commit f53b205c08
.
This commit is contained in:
parent
12373c2e4e
commit
82689ea0c1
1 changed files with 11 additions and 22 deletions
|
@ -13,7 +13,6 @@ import (
|
|||
"github.com/go-git/go-billy/v5/memfs"
|
||||
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
||||
"github.com/kyverno/kyverno/api/kyverno/v1beta1"
|
||||
kyvernov2beta1 "github.com/kyverno/kyverno/api/kyverno/v2beta1"
|
||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/command"
|
||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/deprecations"
|
||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/log"
|
||||
|
@ -149,7 +148,7 @@ func (c *ApplyCommandConfig) applyCommandHelper(out io.Writer) (*processor.Resul
|
|||
if err != nil {
|
||||
return rc, resources1, skipInvalidPolicies, responses1, err
|
||||
}
|
||||
rc, resources1, skipInvalidPolicies, responses1, policies, vaps, vapBindings, exceptions, err := c.loadPolicies(skipInvalidPolicies)
|
||||
rc, resources1, skipInvalidPolicies, responses1, policies, vaps, vapBindings, err := c.loadPolicies(skipInvalidPolicies)
|
||||
if err != nil {
|
||||
return rc, resources1, skipInvalidPolicies, responses1, err
|
||||
}
|
||||
|
@ -163,11 +162,7 @@ func (c *ApplyCommandConfig) applyCommandHelper(out io.Writer) (*processor.Resul
|
|||
policyRulesCount += len(autogen.ComputeRules(policy))
|
||||
}
|
||||
policyRulesCount += len(vaps)
|
||||
if len(exceptions) > 0 {
|
||||
fmt.Fprintf(out, "\nApplying %d policy rule(s) to %d resource(s) with %d exception(s)...\n", policyRulesCount, len(resources), len(exceptions))
|
||||
} else {
|
||||
fmt.Fprintf(out, "\nApplying %d policy rule(s) to %d resource(s)...\n", policyRulesCount, len(resources))
|
||||
}
|
||||
fmt.Fprintf(out, "\nApplying %d policy rule(s) to %d resource(s)...\n", policyRulesCount, len(resources))
|
||||
}
|
||||
|
||||
rc, resources1, responses1, err = c.applyPolicytoResource(
|
||||
|
@ -176,7 +171,6 @@ func (c *ApplyCommandConfig) applyCommandHelper(out io.Writer) (*processor.Resul
|
|||
variables,
|
||||
policies,
|
||||
resources,
|
||||
exceptions,
|
||||
&skipInvalidPolicies,
|
||||
dClient,
|
||||
userInfo,
|
||||
|
@ -235,7 +229,6 @@ func (c *ApplyCommandConfig) applyPolicytoResource(
|
|||
vars *variables.Variables,
|
||||
policies []kyvernov1.PolicyInterface,
|
||||
resources []*unstructured.Unstructured,
|
||||
exceptions []kyvernov2beta1.PolicyException,
|
||||
skipInvalidPolicies *SkippedInvalidPolicies,
|
||||
dClient dclient.Interface,
|
||||
userInfo *v1beta1.RequestInfo,
|
||||
|
@ -268,7 +261,6 @@ func (c *ApplyCommandConfig) applyPolicytoResource(
|
|||
Store: store,
|
||||
Policies: validPolicies,
|
||||
Resource: *resource,
|
||||
PolicyExceptions: exceptions,
|
||||
MutateLogPath: c.MutateLogPath,
|
||||
MutateLogPathIsDir: mutateLogPathIsDir,
|
||||
Variables: vars,
|
||||
|
@ -300,12 +292,11 @@ func (c *ApplyCommandConfig) loadResources(out io.Writer, policies []kyvernov1.P
|
|||
return resources, nil
|
||||
}
|
||||
|
||||
func (c *ApplyCommandConfig) loadPolicies(skipInvalidPolicies SkippedInvalidPolicies) (*processor.ResultCounts, []*unstructured.Unstructured, SkippedInvalidPolicies, []engineapi.EngineResponse, []kyvernov1.PolicyInterface, []v1alpha1.ValidatingAdmissionPolicy, []v1alpha1.ValidatingAdmissionPolicyBinding, []kyvernov2beta1.PolicyException, error) {
|
||||
func (c *ApplyCommandConfig) loadPolicies(skipInvalidPolicies SkippedInvalidPolicies) (*processor.ResultCounts, []*unstructured.Unstructured, SkippedInvalidPolicies, []engineapi.EngineResponse, []kyvernov1.PolicyInterface, []v1alpha1.ValidatingAdmissionPolicy, []v1alpha1.ValidatingAdmissionPolicyBinding, error) {
|
||||
// load policies
|
||||
var policies []kyvernov1.PolicyInterface
|
||||
var vaps []v1alpha1.ValidatingAdmissionPolicy
|
||||
var vapBindings []v1alpha1.ValidatingAdmissionPolicyBinding
|
||||
var exceptions []kyvernov2beta1.PolicyException
|
||||
|
||||
for _, path := range c.PolicyPaths {
|
||||
isGit := source.IsGit(path)
|
||||
|
@ -313,13 +304,13 @@ func (c *ApplyCommandConfig) loadPolicies(skipInvalidPolicies SkippedInvalidPoli
|
|||
if isGit {
|
||||
gitSourceURL, err := url.Parse(path)
|
||||
if err != nil {
|
||||
return nil, nil, skipInvalidPolicies, nil, nil, nil, nil, nil, fmt.Errorf("failed to load policies (%w)", err)
|
||||
return nil, nil, skipInvalidPolicies, nil, nil, nil, nil, fmt.Errorf("failed to load policies (%w)", err)
|
||||
}
|
||||
|
||||
pathElems := strings.Split(gitSourceURL.Path[1:], "/")
|
||||
if len(pathElems) <= 1 {
|
||||
err := fmt.Errorf("invalid URL path %s - expected https://<any_git_source_domain>/:owner/:repository/:branch (without --git-branch flag) OR https://<any_git_source_domain>/:owner/:repository/:directory (with --git-branch flag)", gitSourceURL.Path)
|
||||
return nil, nil, skipInvalidPolicies, nil, nil, nil, nil, nil, fmt.Errorf("failed to parse URL (%w)", err)
|
||||
return nil, nil, skipInvalidPolicies, nil, nil, nil, nil, fmt.Errorf("failed to parse URL (%w)", err)
|
||||
}
|
||||
gitSourceURL.Path = strings.Join([]string{pathElems[0], pathElems[1]}, "/")
|
||||
repoURL := gitSourceURL.String()
|
||||
|
@ -328,35 +319,33 @@ func (c *ApplyCommandConfig) loadPolicies(skipInvalidPolicies SkippedInvalidPoli
|
|||
fs := memfs.New()
|
||||
if _, err := gitutils.Clone(repoURL, fs, c.GitBranch); err != nil {
|
||||
log.Log.V(3).Info(fmt.Sprintf("failed to clone repository %v as it is not valid", repoURL), "error", err)
|
||||
return nil, nil, skipInvalidPolicies, nil, nil, nil, nil, nil, fmt.Errorf("failed to clone repository (%w)", err)
|
||||
return nil, nil, skipInvalidPolicies, nil, nil, nil, nil, fmt.Errorf("failed to clone repository (%w)", err)
|
||||
}
|
||||
policyYamls, err := gitutils.ListYamls(fs, gitPathToYamls)
|
||||
if err != nil {
|
||||
return nil, nil, skipInvalidPolicies, nil, nil, nil, nil, nil, fmt.Errorf("failed to list YAMLs in repository (%w)", err)
|
||||
return nil, nil, skipInvalidPolicies, nil, nil, nil, nil, fmt.Errorf("failed to list YAMLs in repository (%w)", err)
|
||||
}
|
||||
for _, policyYaml := range policyYamls {
|
||||
policiesFromFile, vapsFromFile, vapBindingsFromFile, exceptionsFormFile, err := policy.Load(fs, "", policyYaml)
|
||||
policiesFromFile, vapsFromFile, vapBindingsFromFile, err := policy.Load(fs, "", policyYaml)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
policies = append(policies, policiesFromFile...)
|
||||
vaps = append(vaps, vapsFromFile...)
|
||||
vapBindings = append(vapBindings, vapBindingsFromFile...)
|
||||
exceptions = append(exceptions, exceptionsFormFile...)
|
||||
}
|
||||
} else {
|
||||
policiesFromFile, vapsFromFile, vapBindingsFromFile, exceptionsFormFile, err := policy.Load(nil, "", path)
|
||||
policiesFromFile, vapsFromFile, vapBindingsFromFile, err := policy.Load(nil, "", path)
|
||||
if err != nil {
|
||||
return nil, nil, skipInvalidPolicies, nil, nil, nil, nil, nil, fmt.Errorf("failed to load policies (%w)", err)
|
||||
return nil, nil, skipInvalidPolicies, nil, nil, nil, nil, fmt.Errorf("failed to load policies (%w)", err)
|
||||
}
|
||||
policies = append(policies, policiesFromFile...)
|
||||
vaps = append(vaps, vapsFromFile...)
|
||||
vapBindings = append(vapBindings, vapBindingsFromFile...)
|
||||
exceptions = append(exceptions, exceptionsFormFile...)
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil, skipInvalidPolicies, nil, policies, vaps, vapBindings, exceptions, nil
|
||||
return nil, nil, skipInvalidPolicies, nil, policies, vaps, vapBindings, nil
|
||||
}
|
||||
|
||||
func (c *ApplyCommandConfig) initStoreAndClusterClient(store *store.Store, skipInvalidPolicies SkippedInvalidPolicies) (*processor.ResultCounts, []*unstructured.Unstructured, SkippedInvalidPolicies, []engineapi.EngineResponse, error, dclient.Interface) {
|
||||
|
|
Loading…
Add table
Reference in a new issue