diff --git a/.golangci.yml b/.golangci.yml index 6115f150d1..538b583f24 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -53,3 +53,5 @@ linters-settings: alias: $1$2 - pkg: k8s.io/api/(\w+)/(v[\w\d]+) alias: $1$2 + - pkg: github.com/kyverno/kyverno/pkg/dclient + alias: dclient diff --git a/cmd/cli/kubectl-kyverno/apply/apply_command.go b/cmd/cli/kubectl-kyverno/apply/apply_command.go index 3c860424be..f643659bf9 100644 --- a/cmd/cli/kubectl-kyverno/apply/apply_command.go +++ b/cmd/cli/kubectl-kyverno/apply/apply_command.go @@ -12,7 +12,7 @@ import ( "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/common" sanitizederror "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/sanitizedError" "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/store" - client "github.com/kyverno/kyverno/pkg/dclient" + "github.com/kyverno/kyverno/pkg/dclient" "github.com/kyverno/kyverno/pkg/openapi" policy2 "github.com/kyverno/kyverno/pkg/policy" "github.com/kyverno/kyverno/pkg/policyreport" @@ -170,13 +170,13 @@ func applyCommandHelper(resourcePaths []string, userInfoPath string, cluster boo return rc, resources, skipInvalidPolicies, pvInfos, sanitizederror.NewWithError("failed to initialize openAPIController", err) } - var dClient client.Interface + var dClient dclient.Interface if cluster { restConfig, err := kubernetesConfig.ToRESTConfig() if err != nil { return rc, resources, skipInvalidPolicies, pvInfos, err } - dClient, err = client.NewClient(restConfig, 15*time.Minute, make(chan struct{})) + dClient, err = dclient.NewClient(restConfig, 15*time.Minute, make(chan struct{})) if err != nil { return rc, resources, skipInvalidPolicies, pvInfos, err } diff --git a/cmd/cli/kubectl-kyverno/test/test_command.go b/cmd/cli/kubectl-kyverno/test/test_command.go index 95148cae87..853bd26445 100644 --- a/cmd/cli/kubectl-kyverno/test/test_command.go +++ b/cmd/cli/kubectl-kyverno/test/test_command.go @@ -25,7 +25,7 @@ import ( "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/store" "github.com/kyverno/kyverno/pkg/autogen" "github.com/kyverno/kyverno/pkg/background/generate" - client "github.com/kyverno/kyverno/pkg/dclient" + "github.com/kyverno/kyverno/pkg/dclient" "github.com/kyverno/kyverno/pkg/engine/response" "github.com/kyverno/kyverno/pkg/openapi" policy2 "github.com/kyverno/kyverno/pkg/policy" @@ -708,7 +708,7 @@ func getFullPath(paths []string, policyResourcePath string, isGit bool) []string func applyPoliciesFromPath(fs billy.Filesystem, policyBytes []byte, isGit bool, policyResourcePath string, rc *resultCounts, openAPIController *openapi.Controller, tf *testFilter) (err error) { engineResponses := make([]*response.EngineResponse, 0) - var dClient client.Interface + var dClient dclient.Interface values := &Test{} var variablesString string var pvInfos []policyreport.Info diff --git a/cmd/cli/kubectl-kyverno/utils/common/common.go b/cmd/cli/kubectl-kyverno/utils/common/common.go index be9ef1d57f..e27102c079 100644 --- a/cmd/cli/kubectl-kyverno/utils/common/common.go +++ b/cmd/cli/kubectl-kyverno/utils/common/common.go @@ -21,7 +21,7 @@ import ( 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/pkg/autogen" - client "github.com/kyverno/kyverno/pkg/dclient" + "github.com/kyverno/kyverno/pkg/dclient" "github.com/kyverno/kyverno/pkg/engine" engineContext "github.com/kyverno/kyverno/pkg/engine/context" "github.com/kyverno/kyverno/pkg/engine/response" @@ -654,7 +654,7 @@ func GetPoliciesFromPaths(fs billy.Filesystem, dirPath []string, isGit bool, pol // GetResourceAccordingToResourcePath - get resources according to the resource path func GetResourceAccordingToResourcePath(fs billy.Filesystem, resourcePaths []string, - cluster bool, policies []kyvernov1.PolicyInterface, dClient client.Interface, namespace string, policyReport bool, isGit bool, policyResourcePath string, + cluster bool, policies []kyvernov1.PolicyInterface, dClient dclient.Interface, namespace string, policyReport bool, isGit bool, policyResourcePath string, ) (resources []*unstructured.Unstructured, err error) { if isGit { resources, err = GetResourcesWithTest(fs, policies, resourcePaths, isGit, policyResourcePath) diff --git a/cmd/cli/kubectl-kyverno/utils/common/fetch.go b/cmd/cli/kubectl-kyverno/utils/common/fetch.go index 8f75fccff9..a33271b605 100644 --- a/cmd/cli/kubectl-kyverno/utils/common/fetch.go +++ b/cmd/cli/kubectl-kyverno/utils/common/fetch.go @@ -12,7 +12,7 @@ import ( "github.com/go-git/go-billy/v5" kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1" "github.com/kyverno/kyverno/pkg/autogen" - client "github.com/kyverno/kyverno/pkg/dclient" + "github.com/kyverno/kyverno/pkg/dclient" engineutils "github.com/kyverno/kyverno/pkg/engine/utils" yamlutils "github.com/kyverno/kyverno/pkg/utils/yaml" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -26,7 +26,7 @@ import ( // the resources are fetched from // - local paths to resources, if given // - the k8s cluster, if given -func GetResources(policies []kyvernov1.PolicyInterface, resourcePaths []string, dClient client.Interface, cluster bool, namespace string, policyReport bool) ([]*unstructured.Unstructured, error) { +func GetResources(policies []kyvernov1.PolicyInterface, resourcePaths []string, dClient dclient.Interface, cluster bool, namespace string, policyReport bool) ([]*unstructured.Unstructured, error) { resources := make([]*unstructured.Unstructured, 0) var err error resourceTypesMap := make(map[string]bool) @@ -59,7 +59,7 @@ func GetResources(policies []kyvernov1.PolicyInterface, resourcePaths []string, return resources, err } -func whenClusterIsTrue(resourceTypes []string, dClient client.Interface, namespace string, resourcePaths []string, policyReport bool) ([]*unstructured.Unstructured, error) { +func whenClusterIsTrue(resourceTypes []string, dClient dclient.Interface, namespace string, resourcePaths []string, policyReport bool) ([]*unstructured.Unstructured, error) { resources := make([]*unstructured.Unstructured, 0) resourceMap, err := getResourcesOfTypeFromCluster(resourceTypes, dClient, namespace) if err != nil { @@ -186,7 +186,7 @@ func GetResource(resourceBytes []byte) ([]*unstructured.Unstructured, error) { return resources, nil } -func getResourcesOfTypeFromCluster(resourceTypes []string, dClient client.Interface, namespace string) (map[string]*unstructured.Unstructured, error) { +func getResourcesOfTypeFromCluster(resourceTypes []string, dClient dclient.Interface, namespace string) (map[string]*unstructured.Unstructured, error) { r := make(map[string]*unstructured.Unstructured) for _, kind := range resourceTypes { diff --git a/cmd/initContainer/main.go b/cmd/initContainer/main.go index 6c52f9f9ca..9d70592fd0 100644 --- a/cmd/initContainer/main.go +++ b/cmd/initContainer/main.go @@ -13,7 +13,7 @@ import ( kyvernov1beta1 "github.com/kyverno/kyverno/api/kyverno/v1beta1" kyvernoclient "github.com/kyverno/kyverno/pkg/client/clientset/versioned" "github.com/kyverno/kyverno/pkg/config" - client "github.com/kyverno/kyverno/pkg/dclient" + "github.com/kyverno/kyverno/pkg/dclient" engineUtils "github.com/kyverno/kyverno/pkg/engine/utils" "github.com/kyverno/kyverno/pkg/leaderelection" "github.com/kyverno/kyverno/pkg/policyreport" @@ -82,7 +82,7 @@ func main() { // DYNAMIC CLIENT // - client for all registered resources - client, err := client.NewClient(clientConfig, 15*time.Minute, stopCh) + client, err := dclient.NewClient(clientConfig, 15*time.Minute, stopCh) if err != nil { setupLog.Error(err, "Failed to create client") os.Exit(1) @@ -203,7 +203,7 @@ func acquireLeader(ctx context.Context, kubeClient kubernetes.Interface) error { return err } -func executeRequest(client client.Interface, kyvernoclient kyvernoclient.Interface, req request) error { +func executeRequest(client dclient.Interface, kyvernoclient kyvernoclient.Interface, req request) error { switch req.kind { case policyReportKind: return removePolicyReport(client, req.kind) @@ -253,7 +253,7 @@ func gen(done <-chan struct{}, stopCh <-chan struct{}, requests ...request) <-ch } // processes the requests -func process(client client.Interface, kyvernoclient kyvernoclient.Interface, done <-chan struct{}, stopCh <-chan struct{}, requests <-chan request) <-chan error { +func process(client dclient.Interface, kyvernoclient kyvernoclient.Interface, done <-chan struct{}, stopCh <-chan struct{}, requests <-chan request) <-chan error { logger := log.Log.WithName("process") out := make(chan error) go func() { @@ -307,7 +307,7 @@ func merge(done <-chan struct{}, stopCh <-chan struct{}, processes ...<-chan err return out } -func removeClusterPolicyReport(client client.Interface, kind string) error { +func removeClusterPolicyReport(client dclient.Interface, kind string) error { logger := log.Log.WithName("removeClusterPolicyReport") cpolrs, err := client.ListResource("", kind, "", policyreport.LabelSelector) @@ -322,7 +322,7 @@ func removeClusterPolicyReport(client client.Interface, kind string) error { return nil } -func removePolicyReport(client client.Interface, kind string) error { +func removePolicyReport(client dclient.Interface, kind string) error { logger := log.Log.WithName("removePolicyReport") polrs, err := client.ListResource("", kind, metav1.NamespaceAll, policyreport.LabelSelector) @@ -338,7 +338,7 @@ func removePolicyReport(client client.Interface, kind string) error { return nil } -func addClusterPolicyReportSelectorLabel(client client.Interface) { +func addClusterPolicyReportSelectorLabel(client dclient.Interface) { logger := log.Log.WithName("addClusterPolicyReportSelectorLabel") cpolrs, err := client.ListResource("", clusterPolicyReportKind, "", updateLabelSelector) @@ -354,7 +354,7 @@ func addClusterPolicyReportSelectorLabel(client client.Interface) { } } -func addPolicyReportSelectorLabel(client client.Interface) { +func addPolicyReportSelectorLabel(client dclient.Interface) { logger := log.Log.WithName("addPolicyReportSelectorLabel") polrs, err := client.ListResource("", policyReportKind, metav1.NamespaceAll, updateLabelSelector) @@ -370,7 +370,7 @@ func addPolicyReportSelectorLabel(client client.Interface) { } } -func removeReportChangeRequest(client client.Interface, kind string) error { +func removeReportChangeRequest(client dclient.Interface, kind string) error { logger := log.Log.WithName("removeReportChangeRequest") ns := config.KyvernoNamespace() @@ -387,7 +387,7 @@ func removeReportChangeRequest(client client.Interface, kind string) error { return nil } -func removeClusterReportChangeRequest(client client.Interface, kind string) error { +func removeClusterReportChangeRequest(client dclient.Interface, kind string) error { crcrList, err := client.ListResource("", kind, "", nil) if err != nil { log.Log.Error(err, "failed to list clusterReportChangeRequest") @@ -400,7 +400,7 @@ func removeClusterReportChangeRequest(client client.Interface, kind string) erro return nil } -func deleteResource(client client.Interface, apiversion, kind, ns, name string) { +func deleteResource(client dclient.Interface, apiversion, kind, ns, name string) { err := client.DeleteResource(apiversion, kind, ns, name, false) if err != nil && !errors.IsNotFound(err) { log.Log.Error(err, "failed to delete resource", "kind", kind, "name", name) @@ -410,7 +410,7 @@ func deleteResource(client client.Interface, apiversion, kind, ns, name string) log.Log.Info("successfully cleaned up resource", "kind", kind, "name", name) } -func addSelectorLabel(client client.Interface, apiversion, kind, ns, name string) { +func addSelectorLabel(client dclient.Interface, apiversion, kind, ns, name string) { res, err := client.GetResource(apiversion, kind, ns, name) if err != nil && !errors.IsNotFound(err) { log.Log.Error(err, "failed to get resource", "kind", kind, "name", name) diff --git a/pkg/auth/auth.go b/pkg/auth/auth.go index 89bc965473..a23aa80dff 100644 --- a/pkg/auth/auth.go +++ b/pkg/auth/auth.go @@ -4,7 +4,7 @@ import ( "fmt" "reflect" - client "github.com/kyverno/kyverno/pkg/dclient" + "github.com/kyverno/kyverno/pkg/dclient" authorizationv1 "k8s.io/api/authorization/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime/schema" @@ -15,11 +15,11 @@ type CanIOptions struct { namespace string verb string kind string - client client.Interface + client dclient.Interface } // NewCanI returns a new instance of operation access controller evaluator -func NewCanI(client client.Interface, kind, namespace, verb string) *CanIOptions { +func NewCanI(client dclient.Interface, kind, namespace, verb string) *CanIOptions { return &CanIOptions{ namespace: namespace, kind: kind, diff --git a/pkg/dclient/client.go b/pkg/dclient/client.go index e074646625..b7fb4ab194 100644 --- a/pkg/dclient/client.go +++ b/pkg/dclient/client.go @@ -1,4 +1,4 @@ -package client +package dclient import ( "context" diff --git a/pkg/dclient/client_test.go b/pkg/dclient/client_test.go index 0ed079be3d..23e87c5887 100644 --- a/pkg/dclient/client_test.go +++ b/pkg/dclient/client_test.go @@ -1,4 +1,4 @@ -package client +package dclient import ( "context" diff --git a/pkg/dclient/discovery.go b/pkg/dclient/discovery.go index c870cd6233..59cac6e331 100644 --- a/pkg/dclient/discovery.go +++ b/pkg/dclient/discovery.go @@ -1,4 +1,4 @@ -package client +package dclient import ( "fmt" diff --git a/pkg/dclient/discovery_test.go b/pkg/dclient/discovery_test.go index 3fd6f8478d..7f58ffb96d 100644 --- a/pkg/dclient/discovery_test.go +++ b/pkg/dclient/discovery_test.go @@ -1,4 +1,4 @@ -package client +package dclient import ( "testing" diff --git a/pkg/dclient/fake.go b/pkg/dclient/fake.go index fa035ee7f3..3f5768695e 100644 --- a/pkg/dclient/fake.go +++ b/pkg/dclient/fake.go @@ -1,4 +1,4 @@ -package client +package dclient import ( "fmt" diff --git a/pkg/dclient/log.go b/pkg/dclient/log.go index 712d8e5fb5..fe393ee0a2 100644 --- a/pkg/dclient/log.go +++ b/pkg/dclient/log.go @@ -1,4 +1,4 @@ -package client +package dclient import "sigs.k8s.io/controller-runtime/pkg/log" diff --git a/pkg/dclient/mock.go b/pkg/dclient/mock.go index 147cfb2fa6..b535f0c8ee 100644 --- a/pkg/dclient/mock.go +++ b/pkg/dclient/mock.go @@ -1,4 +1,4 @@ -package client +package dclient import ( "k8s.io/apimachinery/pkg/runtime" diff --git a/pkg/dclient/utils.go b/pkg/dclient/utils.go index e4aabc114d..c0032e5071 100644 --- a/pkg/dclient/utils.go +++ b/pkg/dclient/utils.go @@ -1,4 +1,4 @@ -package client +package dclient import ( "strings" diff --git a/pkg/engine/policyContext.go b/pkg/engine/policyContext.go index 40f41a89d7..b133d2dce5 100644 --- a/pkg/engine/policyContext.go +++ b/pkg/engine/policyContext.go @@ -3,7 +3,7 @@ package engine import ( kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1" kyvernov1beta1 "github.com/kyverno/kyverno/api/kyverno/v1beta1" - client "github.com/kyverno/kyverno/pkg/dclient" + "github.com/kyverno/kyverno/pkg/dclient" "github.com/kyverno/kyverno/pkg/engine/context" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) @@ -26,7 +26,7 @@ type PolicyContext struct { AdmissionInfo kyvernov1beta1.RequestInfo // Dynamic client - used for api lookups - Client client.Interface + Client dclient.Interface // Config handler ExcludeGroupRole []string diff --git a/pkg/event/controller.go b/pkg/event/controller.go index aa87db1abe..4aec4decb6 100644 --- a/pkg/event/controller.go +++ b/pkg/event/controller.go @@ -7,7 +7,7 @@ import ( "github.com/kyverno/kyverno/pkg/client/clientset/versioned/scheme" kyvernoinformer "github.com/kyverno/kyverno/pkg/client/informers/externalversions/kyverno/v1" kyvernolister "github.com/kyverno/kyverno/pkg/client/listers/kyverno/v1" - client "github.com/kyverno/kyverno/pkg/dclient" + "github.com/kyverno/kyverno/pkg/dclient" corev1 "k8s.io/api/core/v1" errors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" @@ -21,7 +21,7 @@ import ( // Generator generate events type Generator struct { - client client.Interface + client dclient.Interface // list/get cluster policy cpLister kyvernolister.ClusterPolicyLister // list/get policy @@ -46,7 +46,7 @@ type Interface interface { } // NewEventGenerator to generate a new event controller -func NewEventGenerator(client client.Interface, cpInformer kyvernoinformer.ClusterPolicyInformer, pInformer kyvernoinformer.PolicyInformer, log logr.Logger) *Generator { +func NewEventGenerator(client dclient.Interface, cpInformer kyvernoinformer.ClusterPolicyInformer, pInformer kyvernoinformer.PolicyInformer, log logr.Logger) *Generator { gen := Generator{ client: client, cpLister: cpInformer.Lister(), @@ -65,7 +65,7 @@ func rateLimiter() workqueue.RateLimiter { return workqueue.DefaultItemBasedRateLimiter() } -func initRecorder(client client.Interface, eventSource Source, log logr.Logger) record.EventRecorder { +func initRecorder(client dclient.Interface, eventSource Source, log logr.Logger) record.EventRecorder { // Initialize Event Broadcaster err := scheme.AddToScheme(scheme.Scheme) if err != nil { diff --git a/pkg/openapi/crdSync.go b/pkg/openapi/crdSync.go index 9a86108015..8c9693d160 100644 --- a/pkg/openapi/crdSync.go +++ b/pkg/openapi/crdSync.go @@ -9,7 +9,7 @@ import ( "github.com/googleapis/gnostic/compiler" openapiv2 "github.com/googleapis/gnostic/openapiv2" - client "github.com/kyverno/kyverno/pkg/dclient" + "github.com/kyverno/kyverno/pkg/dclient" "github.com/pkg/errors" "gopkg.in/yaml.v3" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -20,7 +20,7 @@ import ( ) type crdSync struct { - client client.Interface + client dclient.Interface controller *Controller } @@ -52,7 +52,7 @@ var crdDefinitionNew struct { } // NewCRDSync ... -func NewCRDSync(client client.Interface, controller *Controller) *crdSync { +func NewCRDSync(client dclient.Interface, controller *Controller) *crdSync { if controller == nil { panic(fmt.Errorf("nil controller sent into crd sync")) } diff --git a/pkg/policy/apply.go b/pkg/policy/apply.go index 5368256d1a..1161937f94 100644 --- a/pkg/policy/apply.go +++ b/pkg/policy/apply.go @@ -9,7 +9,7 @@ import ( jsonpatch "github.com/evanphx/json-patch/v5" "github.com/go-logr/logr" kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1" - client "github.com/kyverno/kyverno/pkg/dclient" + "github.com/kyverno/kyverno/pkg/dclient" "github.com/kyverno/kyverno/pkg/engine" "github.com/kyverno/kyverno/pkg/engine/context" "github.com/kyverno/kyverno/pkg/engine/response" @@ -20,7 +20,7 @@ import ( // applyPolicy applies policy on a resource func applyPolicy(policy kyvernov1.PolicyInterface, resource unstructured.Unstructured, logger logr.Logger, excludeGroupRole []string, - client client.Interface, namespaceLabels map[string]string, + client dclient.Interface, namespaceLabels map[string]string, ) (responses []*response.EngineResponse) { startTime := time.Now() defer func() { diff --git a/pkg/policy/policy_controller.go b/pkg/policy/policy_controller.go index 979a8fe1bb..e7110b0f51 100644 --- a/pkg/policy/policy_controller.go +++ b/pkg/policy/policy_controller.go @@ -21,7 +21,7 @@ import ( kyvernolister "github.com/kyverno/kyverno/pkg/client/listers/kyverno/v1" urkyvernolister "github.com/kyverno/kyverno/pkg/client/listers/kyverno/v1beta1" "github.com/kyverno/kyverno/pkg/config" - client "github.com/kyverno/kyverno/pkg/dclient" + "github.com/kyverno/kyverno/pkg/dclient" "github.com/kyverno/kyverno/pkg/event" "github.com/kyverno/kyverno/pkg/metrics" "github.com/kyverno/kyverno/pkg/policyreport" @@ -53,7 +53,7 @@ const ( // PolicyController is responsible for synchronizing Policy objects stored // in the system with the corresponding policy violations type PolicyController struct { - client client.Interface + client dclient.Interface kyvernoClient kyvernoclient.Interface pInformer kyvernoinformer.ClusterPolicyInformer npInformer kyvernoinformer.PolicyInformer @@ -98,7 +98,7 @@ type PolicyController struct { func NewPolicyController( kubeClient kubernetes.Interface, kyvernoClient kyvernoclient.Interface, - client client.Interface, + client dclient.Interface, pInformer kyvernoinformer.ClusterPolicyInformer, npInformer kyvernoinformer.PolicyInformer, urInformer urkyvernoinformer.UpdateRequestInformer, @@ -504,7 +504,7 @@ func (pc *PolicyController) getPolicy(key string) (policy kyvernov1.PolicyInterf return } -func generateTriggers(client client.Interface, rule kyvernov1.Rule, log logr.Logger) []*unstructured.Unstructured { +func generateTriggers(client dclient.Interface, rule kyvernov1.Rule, log logr.Logger) []*unstructured.Unstructured { list := &unstructured.UnstructuredList{} kinds := fetchUniqueKinds(rule) diff --git a/pkg/testrunner/scenario.go b/pkg/testrunner/scenario.go index d0ef98f0a5..4b0bdbce2e 100644 --- a/pkg/testrunner/scenario.go +++ b/pkg/testrunner/scenario.go @@ -12,7 +12,7 @@ import ( "testing" kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1" - client "github.com/kyverno/kyverno/pkg/dclient" + "github.com/kyverno/kyverno/pkg/dclient" "github.com/kyverno/kyverno/pkg/engine" "github.com/kyverno/kyverno/pkg/engine/context" "github.com/kyverno/kyverno/pkg/engine/response" @@ -203,12 +203,12 @@ func runTestCase(t *testing.T, tc TestCase) bool { return true } -func createNamespace(client client.Interface, ns *unstructured.Unstructured) error { +func createNamespace(client dclient.Interface, ns *unstructured.Unstructured) error { _, err := client.CreateResource("", "Namespace", "", ns, false) return err } -func validateGeneratedResources(t *testing.T, client client.Interface, policy kyvernov1.ClusterPolicy, namespace string, expected []kyvernov1.ResourceSpec) { +func validateGeneratedResources(t *testing.T, client dclient.Interface, policy kyvernov1.ClusterPolicy, namespace string, expected []kyvernov1.ResourceSpec) { t.Helper() t.Log("--validate if resources are generated---") // list of expected generated resources @@ -357,7 +357,7 @@ func loadPolicyResource(t *testing.T, file string) *unstructured.Unstructured { return resources[0] } -func getClient(t *testing.T, files []string) client.Interface { +func getClient(t *testing.T, files []string) dclient.Interface { t.Helper() var objects []k8sRuntime.Object for _, file := range files { @@ -366,14 +366,14 @@ func getClient(t *testing.T, files []string) client.Interface { // create mock client scheme := k8sRuntime.NewScheme() // mock client expects the resource to be as runtime.Object - c, err := client.NewMockClient(scheme, nil, objects...) + c, err := dclient.NewMockClient(scheme, nil, objects...) if err != nil { t.Errorf("failed to create client. %v", err) return nil } // get GVR from GVK gvrs := getGVRForResources(objects) - c.SetDiscovery(client.NewFakeDiscoveryClient(gvrs)) + c.SetDiscovery(dclient.NewFakeDiscoveryClient(gvrs)) t.Log("created mock client with pre-loaded resources") return c } diff --git a/pkg/utils/util.go b/pkg/utils/util.go index bf5627339d..999ebc2d02 100644 --- a/pkg/utils/util.go +++ b/pkg/utils/util.go @@ -9,7 +9,7 @@ import ( "github.com/go-logr/logr" wildcard "github.com/kyverno/go-wildcard" kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1" - client "github.com/kyverno/kyverno/pkg/dclient" + "github.com/kyverno/kyverno/pkg/dclient" engineutils "github.com/kyverno/kyverno/pkg/engine/utils" "github.com/pkg/errors" admissionv1 "k8s.io/api/admission/v1" @@ -99,7 +99,7 @@ func compareString(str, name string) bool { } // CRDsInstalled checks if the Kyverno CRDs are installed or not -func CRDsInstalled(discovery client.IDiscovery) bool { +func CRDsInstalled(discovery dclient.IDiscovery) bool { kyvernoCRDs := []string{"ClusterPolicy", "ClusterPolicyReport", "PolicyReport", "ClusterReportChangeRequest", "ReportChangeRequest"} for _, crd := range kyvernoCRDs { if !isCRDInstalled(discovery, crd) { @@ -110,7 +110,7 @@ func CRDsInstalled(discovery client.IDiscovery) bool { return true } -func isCRDInstalled(discoveryClient client.IDiscovery, kind string) bool { +func isCRDInstalled(discoveryClient dclient.IDiscovery, kind string) bool { gvr, err := discoveryClient.GetGVRFromKind(kind) if gvr.Empty() { if err == nil { diff --git a/pkg/webhookconfig/configmanager.go b/pkg/webhookconfig/configmanager.go index 6fa31e542e..b9115c102e 100644 --- a/pkg/webhookconfig/configmanager.go +++ b/pkg/webhookconfig/configmanager.go @@ -15,7 +15,7 @@ import ( kyvernoinformer "github.com/kyverno/kyverno/pkg/client/informers/externalversions/kyverno/v1" kyvernolister "github.com/kyverno/kyverno/pkg/client/listers/kyverno/v1" "github.com/kyverno/kyverno/pkg/config" - client "github.com/kyverno/kyverno/pkg/dclient" + "github.com/kyverno/kyverno/pkg/dclient" "github.com/kyverno/kyverno/pkg/utils" kubeutils "github.com/kyverno/kyverno/pkg/utils/kube" "github.com/pkg/errors" @@ -39,7 +39,7 @@ var DefaultWebhookTimeout int32 = 10 // it is NOT multi-thread safe type webhookConfigManager struct { // clients - discoveryClient client.IDiscovery + discoveryClient dclient.IDiscovery kubeClient kubernetes.Interface kyvernoClient kyvernoclient.Interface @@ -77,7 +77,7 @@ type manage interface { } func newWebhookConfigManager( - discoveryClient client.IDiscovery, + discoveryClient dclient.IDiscovery, kubeClient kubernetes.Interface, kyvernoClient kyvernoclient.Interface, pInformer kyvernoinformer.ClusterPolicyInformer, diff --git a/pkg/webhookconfig/registration.go b/pkg/webhookconfig/registration.go index 17a6c16095..07e9781214 100644 --- a/pkg/webhookconfig/registration.go +++ b/pkg/webhookconfig/registration.go @@ -13,7 +13,7 @@ import ( kyvernoclient "github.com/kyverno/kyverno/pkg/client/clientset/versioned" kyvernoinformer "github.com/kyverno/kyverno/pkg/client/informers/externalversions/kyverno/v1" "github.com/kyverno/kyverno/pkg/config" - client "github.com/kyverno/kyverno/pkg/dclient" + "github.com/kyverno/kyverno/pkg/dclient" "github.com/kyverno/kyverno/pkg/utils" "github.com/pkg/errors" admissionregistrationv1 "k8s.io/api/admissionregistration/v1" @@ -66,7 +66,7 @@ type Register struct { // NewRegister creates new Register instance func NewRegister( clientConfig *rest.Config, - client client.Interface, + client dclient.Interface, kubeClient kubernetes.Interface, kyvernoClient kyvernoclient.Interface, mwcInformer adminformers.MutatingWebhookConfigurationInformer, diff --git a/pkg/webhooks/policy/handlers.go b/pkg/webhooks/policy/handlers.go index e1ba9bbfac..9327c8675c 100644 --- a/pkg/webhooks/policy/handlers.go +++ b/pkg/webhooks/policy/handlers.go @@ -6,7 +6,7 @@ import ( "time" "github.com/go-logr/logr" - client "github.com/kyverno/kyverno/pkg/dclient" + "github.com/kyverno/kyverno/pkg/dclient" "github.com/kyverno/kyverno/pkg/openapi" policyvalidate "github.com/kyverno/kyverno/pkg/policy" "github.com/kyverno/kyverno/pkg/policymutation" @@ -16,11 +16,11 @@ import ( ) type handlers struct { - client client.Interface + client dclient.Interface openAPIController *openapi.Controller } -func NewHandlers(client client.Interface, openAPIController *openapi.Controller) webhooks.Handlers { +func NewHandlers(client dclient.Interface, openAPIController *openapi.Controller) webhooks.Handlers { return &handlers{ client: client, openAPIController: openAPIController, diff --git a/pkg/webhooks/resource/handlers.go b/pkg/webhooks/resource/handlers.go index 428779e997..1c3afad24b 100644 --- a/pkg/webhooks/resource/handlers.go +++ b/pkg/webhooks/resource/handlers.go @@ -13,7 +13,7 @@ import ( urlister "github.com/kyverno/kyverno/pkg/client/listers/kyverno/v1beta1" "github.com/kyverno/kyverno/pkg/common" "github.com/kyverno/kyverno/pkg/config" - client "github.com/kyverno/kyverno/pkg/dclient" + "github.com/kyverno/kyverno/pkg/dclient" "github.com/kyverno/kyverno/pkg/engine" enginectx "github.com/kyverno/kyverno/pkg/engine/context" "github.com/kyverno/kyverno/pkg/engine/response" @@ -40,7 +40,7 @@ import ( type handlers struct { // clients - client client.Interface + client dclient.Interface kyvernoClient kyvernoclient.Interface // config @@ -65,7 +65,7 @@ type handlers struct { } func NewHandlers( - client client.Interface, + client dclient.Interface, kyvernoClient kyvernoclient.Interface, configuration config.Configuration, promConfig *metrics.PromConfig, diff --git a/pkg/webhooks/resource/utils.go b/pkg/webhooks/resource/utils.go index a805ab6621..ed3b9ade4f 100644 --- a/pkg/webhooks/resource/utils.go +++ b/pkg/webhooks/resource/utils.go @@ -10,7 +10,7 @@ import ( kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1" kyvernov1beta1 "github.com/kyverno/kyverno/api/kyverno/v1beta1" "github.com/kyverno/kyverno/pkg/autogen" - client "github.com/kyverno/kyverno/pkg/dclient" + "github.com/kyverno/kyverno/pkg/dclient" "github.com/kyverno/kyverno/pkg/engine" enginectx "github.com/kyverno/kyverno/pkg/engine/context" "github.com/kyverno/kyverno/pkg/engine/response" @@ -222,7 +222,7 @@ func hasAnnotations(context *engine.PolicyContext) bool { return len(annotations) != 0 } -func getGeneratedByResource(newRes *unstructured.Unstructured, resLabels map[string]string, client client.Interface, rule kyvernov1.Rule, logger logr.Logger) (kyvernov1.Rule, error) { +func getGeneratedByResource(newRes *unstructured.Unstructured, resLabels map[string]string, client dclient.Interface, rule kyvernov1.Rule, logger logr.Logger) (kyvernov1.Rule, error) { var apiVersion, kind, name, namespace string sourceRequest := &admissionv1.AdmissionRequest{} kind = resLabels["kyverno.io/generated-by-kind"] diff --git a/pkg/webhooks/resource/validate_audit.go b/pkg/webhooks/resource/validate_audit.go index 0a35eee5f3..1638395e0f 100644 --- a/pkg/webhooks/resource/validate_audit.go +++ b/pkg/webhooks/resource/validate_audit.go @@ -8,7 +8,7 @@ import ( "github.com/kyverno/kyverno/api/kyverno/v1beta1" "github.com/kyverno/kyverno/pkg/common" "github.com/kyverno/kyverno/pkg/config" - client "github.com/kyverno/kyverno/pkg/dclient" + "github.com/kyverno/kyverno/pkg/dclient" "github.com/kyverno/kyverno/pkg/engine" "github.com/kyverno/kyverno/pkg/event" "github.com/kyverno/kyverno/pkg/metrics" @@ -42,7 +42,7 @@ type AuditHandler interface { } type auditHandler struct { - client client.Interface + client dclient.Interface queue workqueue.RateLimitingInterface pCache policycache.Cache eventGen event.Interface @@ -66,7 +66,7 @@ func NewValidateAuditHandler(pCache policycache.Cache, namespaces informers.NamespaceInformer, log logr.Logger, dynamicConfig config.Configuration, - client client.Interface, + client dclient.Interface, promConfig *metrics.PromConfig, ) AuditHandler { return &auditHandler{