mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-28 18:38:40 +00:00
fix: update CLI to use store for fetching regclient (#9315)
* fix: use docker keychain as default in 1.11 Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> * feat: use store to get registry client Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> * fix: use kyverno as username Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> * fix: missed cli-test Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> * feat: changed location Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> * fix: undo test Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> --------- Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> Co-authored-by: Jim Bugwadia <jim@nirmata.com> Co-authored-by: shuting <shuting@nirmata.com>
This commit is contained in:
parent
e1a26f8eed
commit
c2e388a71c
4 changed files with 5 additions and 17 deletions
|
@ -29,7 +29,6 @@ import (
|
|||
"github.com/kyverno/kyverno/pkg/clients/dclient"
|
||||
"github.com/kyverno/kyverno/pkg/config"
|
||||
engineapi "github.com/kyverno/kyverno/pkg/engine/api"
|
||||
"github.com/kyverno/kyverno/pkg/registryclient"
|
||||
gitutils "github.com/kyverno/kyverno/pkg/utils/git"
|
||||
policyvalidation "github.com/kyverno/kyverno/pkg/validation/policy"
|
||||
"github.com/spf13/cobra"
|
||||
|
@ -166,13 +165,6 @@ func (c *ApplyCommandConfig) applyCommandHelper(out io.Writer) (*processor.Resul
|
|||
fmt.Fprintf(out, "\nApplying %d policy rule(s) to %d resource(s)...\n", policyRulesCount, len(resources))
|
||||
}
|
||||
|
||||
var regOpts []registryclient.Option
|
||||
if c.RegistryAccess {
|
||||
regOpts = append(regOpts, registryclient.WithLocalKeychain())
|
||||
}
|
||||
|
||||
rclient := registryclient.NewOrDie(regOpts...)
|
||||
|
||||
rc, resources1, responses1, err = c.applyPolicytoResource(
|
||||
out,
|
||||
&store,
|
||||
|
@ -183,7 +175,6 @@ func (c *ApplyCommandConfig) applyCommandHelper(out io.Writer) (*processor.Resul
|
|||
dClient,
|
||||
userInfo,
|
||||
mutateLogPathIsDir,
|
||||
rclient,
|
||||
)
|
||||
if err != nil {
|
||||
return rc, resources1, skipInvalidPolicies, responses1, err
|
||||
|
@ -241,7 +232,6 @@ func (c *ApplyCommandConfig) applyPolicytoResource(
|
|||
dClient dclient.Interface,
|
||||
userInfo *v1beta1.RequestInfo,
|
||||
mutateLogPathIsDir bool,
|
||||
rclient registryclient.Client,
|
||||
) (*processor.ResultCounts, []*unstructured.Unstructured, []engineapi.EngineResponse, error) {
|
||||
if vars != nil {
|
||||
vars.SetInStore(store)
|
||||
|
@ -283,7 +273,6 @@ func (c *ApplyCommandConfig) applyPolicytoResource(
|
|||
AuditWarn: c.AuditWarn,
|
||||
Subresources: vars.Subresources(),
|
||||
Out: out,
|
||||
RegistryClient: rclient,
|
||||
}
|
||||
ers, err := processor.ApplyPoliciesOnResource()
|
||||
if err != nil {
|
||||
|
|
|
@ -23,7 +23,6 @@ import (
|
|||
"github.com/kyverno/kyverno/pkg/clients/dclient"
|
||||
"github.com/kyverno/kyverno/pkg/config"
|
||||
engineapi "github.com/kyverno/kyverno/pkg/engine/api"
|
||||
"github.com/kyverno/kyverno/pkg/registryclient"
|
||||
policyvalidation "github.com/kyverno/kyverno/pkg/validation/policy"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
)
|
||||
|
@ -154,7 +153,6 @@ func runTest(out io.Writer, testCase test.TestCase, registryAccess bool, auditWa
|
|||
Client: dClient,
|
||||
Subresources: vars.Subresources(),
|
||||
Out: out,
|
||||
RegistryClient: registryclient.NewOrDie(),
|
||||
}
|
||||
ers, err := processor.ApplyPoliciesOnResource()
|
||||
if err != nil {
|
||||
|
|
|
@ -52,7 +52,6 @@ type PolicyProcessor struct {
|
|||
AuditWarn bool
|
||||
Subresources []v1alpha1.Subresource
|
||||
Out io.Writer
|
||||
RegistryClient registryclient.Client
|
||||
}
|
||||
|
||||
func (p *PolicyProcessor) ApplyPoliciesOnResource() ([]engineapi.EngineResponse, error) {
|
||||
|
@ -65,12 +64,16 @@ func (p *PolicyProcessor) ApplyPoliciesOnResource() ([]engineapi.EngineResponse,
|
|||
client = adapters.Client(p.Client)
|
||||
}
|
||||
|
||||
rclient := p.Store.GetRegistryClient()
|
||||
if rclient == nil {
|
||||
rclient = registryclient.NewOrDie()
|
||||
}
|
||||
eng := engine.NewEngine(
|
||||
cfg,
|
||||
config.NewDefaultMetricsConfiguration(),
|
||||
jmespath.New(cfg),
|
||||
client,
|
||||
factories.DefaultRegistryClientFactory(adapters.RegistryClient(p.RegistryClient), nil),
|
||||
factories.DefaultRegistryClientFactory(adapters.RegistryClient(rclient), nil),
|
||||
imageverifycache.DisabledImageVerifyCache(),
|
||||
store.ContextLoaderFactory(p.Store, nil),
|
||||
nil,
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
|
||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/resource"
|
||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/store"
|
||||
"github.com/kyverno/kyverno/pkg/registryclient"
|
||||
yamlutils "github.com/kyverno/kyverno/pkg/utils/yaml"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
@ -117,7 +116,6 @@ func Test_NamespaceSelector(t *testing.T) {
|
|||
NamespaceSelectorMap: tc.namespaceSelectorMap,
|
||||
Rc: rc,
|
||||
Out: os.Stdout,
|
||||
RegistryClient: registryclient.NewOrDie(),
|
||||
}
|
||||
processor.ApplyPoliciesOnResource()
|
||||
assert.Equal(t, int64(rc.Pass()), int64(tc.result.pass))
|
||||
|
|
Loading…
Add table
Reference in a new issue