From 572a76ce3362eb8c891f5fb82143adecd78a96d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Edouard=20Br=C3=A9t=C3=A9ch=C3=A9?= Date: Tue, 17 May 2022 17:51:03 +0200 Subject: [PATCH] chore: make kube informers and listers import aliases consistent (#3957) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: make kyverno api import aliases consistent Signed-off-by: Charles-Edouard Brétéché * chore: make apimachinery api import aliases consistent Signed-off-by: Charles-Edouard Brétéché * chore: make dclient api import aliases consistent Signed-off-by: Charles-Edouard Brétéché * chore: make clients import aliases consistent Signed-off-by: Charles-Edouard Brétéché * chore: make kube informers and listers import aliases consistent Signed-off-by: Charles-Edouard Brétéché --- .golangci.yml | 4 ++++ pkg/background/generate/cleanup/controller.go | 8 ++++---- pkg/background/generate/generate.go | 6 +++--- pkg/background/update_request_controller.go | 8 ++++---- pkg/common/common.go | 4 ++-- pkg/controllers/certmanager/controller.go | 8 ++++---- pkg/policy/policy_controller.go | 8 ++++---- pkg/policyreport/reportcontroller.go | 8 ++++---- pkg/userinfo/roleRef.go | 4 ++-- pkg/webhookconfig/configmanager.go | 16 +++++++-------- pkg/webhookconfig/registration.go | 20 +++++++++---------- pkg/webhooks/resource/handlers.go | 16 +++++++-------- pkg/webhooks/resource/validate_audit.go | 20 +++++++++---------- 13 files changed, 67 insertions(+), 63 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index e9e85f3c19..6c5366aecb 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -59,3 +59,7 @@ linters-settings: alias: kyvernoclient - pkg: k8s.io/client-go/kubernetes alias: kubernetes + - pkg: k8s.io/client-go/informers/(\w+)/(v[\w\d]+) + alias: ${1}${2}informers + - pkg: k8s.io/client-go/listers/(\w+)/(v[\w\d]+) + alias: ${1}${2}listers diff --git a/pkg/background/generate/cleanup/controller.go b/pkg/background/generate/cleanup/controller.go index 8a3fa9a27c..c34c9f949e 100644 --- a/pkg/background/generate/cleanup/controller.go +++ b/pkg/background/generate/cleanup/controller.go @@ -18,9 +18,9 @@ import ( "k8s.io/apimachinery/pkg/labels" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/wait" - coreinformers "k8s.io/client-go/informers/core/v1" + corev1informers "k8s.io/client-go/informers/core/v1" "k8s.io/client-go/kubernetes" - corelister "k8s.io/client-go/listers/core/v1" + corev1listers "k8s.io/client-go/listers/core/v1" "k8s.io/client-go/tools/cache" "k8s.io/client-go/util/workqueue" ) @@ -56,7 +56,7 @@ type Controller struct { urLister urkyvernolister.UpdateRequestNamespaceLister // nsLister can list/get namespaces from the shared informer's store - nsLister corelister.NamespaceLister + nsLister corev1listers.NamespaceLister // logger log logr.Logger @@ -70,7 +70,7 @@ func NewController( pInformer kyvernoinformer.ClusterPolicyInformer, npInformer kyvernoinformer.PolicyInformer, urInformer urkyvernoinformer.UpdateRequestInformer, - namespaceInformer coreinformers.NamespaceInformer, + namespaceInformer corev1informers.NamespaceInformer, log logr.Logger, ) (*Controller, error) { c := Controller{ diff --git a/pkg/background/generate/generate.go b/pkg/background/generate/generate.go index c03b7897b9..da1acc5f49 100644 --- a/pkg/background/generate/generate.go +++ b/pkg/background/generate/generate.go @@ -32,7 +32,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/labels" - corelister "k8s.io/client-go/listers/core/v1" + corev1listers "k8s.io/client-go/listers/core/v1" "k8s.io/client-go/tools/cache" ) @@ -55,7 +55,7 @@ type GenerateController struct { urLister urlister.UpdateRequestNamespaceLister // nsLister can list/get namespaces from the shared informer's store - nsLister corelister.NamespaceLister + nsLister corev1listers.NamespaceLister // policyLister can list/get cluster policy from the shared informer's store policyLister kyvernolister.ClusterPolicyLister @@ -74,7 +74,7 @@ func NewGenerateController( npolicyLister kyvernolister.PolicyLister, urLister urlister.UpdateRequestNamespaceLister, eventGen event.Interface, - nsLister corelister.NamespaceLister, + nsLister corev1listers.NamespaceLister, log logr.Logger, dynamicConfig config.Configuration, ) (*GenerateController, error) { diff --git a/pkg/background/update_request_controller.go b/pkg/background/update_request_controller.go index 069e8a6aff..af1faaafb9 100644 --- a/pkg/background/update_request_controller.go +++ b/pkg/background/update_request_controller.go @@ -22,9 +22,9 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/wait" - coreinformers "k8s.io/client-go/informers/core/v1" + corev1informers "k8s.io/client-go/informers/core/v1" "k8s.io/client-go/kubernetes" - corelister "k8s.io/client-go/listers/core/v1" + corev1listers "k8s.io/client-go/listers/core/v1" "k8s.io/client-go/tools/cache" "k8s.io/client-go/util/workqueue" ) @@ -62,7 +62,7 @@ type Controller struct { urLister urlister.UpdateRequestNamespaceLister // nsLister can list/get namespaces from the shared informer's store - nsLister corelister.NamespaceLister + nsLister corev1listers.NamespaceLister log logr.Logger @@ -78,7 +78,7 @@ func NewController( npolicyInformer kyvernoinformer.PolicyInformer, urInformer urkyvernoinformer.UpdateRequestInformer, eventGen event.Interface, - namespaceInformer coreinformers.NamespaceInformer, + namespaceInformer corev1informers.NamespaceInformer, log logr.Logger, dynamicConfig config.Configuration, ) (*Controller, error) { diff --git a/pkg/common/common.go b/pkg/common/common.go index f903841f75..1cc4a9f544 100644 --- a/pkg/common/common.go +++ b/pkg/common/common.go @@ -14,7 +14,7 @@ import ( "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" - listerv1 "k8s.io/client-go/listers/core/v1" + corev1listers "k8s.io/client-go/listers/core/v1" "sigs.k8s.io/controller-runtime/pkg/log" ) @@ -25,7 +25,7 @@ const ( ) // GetNamespaceSelectorsFromNamespaceLister - extract the namespacelabels when namespace lister is passed -func GetNamespaceSelectorsFromNamespaceLister(kind, namespaceOfResource string, nsLister listerv1.NamespaceLister, logger logr.Logger) map[string]string { +func GetNamespaceSelectorsFromNamespaceLister(kind, namespaceOfResource string, nsLister corev1listers.NamespaceLister, logger logr.Logger) map[string]string { namespaceLabels := make(map[string]string) if kind != "Namespace" && namespaceOfResource != "" { namespaceObj, err := nsLister.Get(namespaceOfResource) diff --git a/pkg/controllers/certmanager/controller.go b/pkg/controllers/certmanager/controller.go index 6620db6376..97fe23224f 100644 --- a/pkg/controllers/certmanager/controller.go +++ b/pkg/controllers/certmanager/controller.go @@ -9,8 +9,8 @@ import ( "github.com/kyverno/kyverno/pkg/config" "github.com/kyverno/kyverno/pkg/tls" corev1 "k8s.io/api/core/v1" - informerv1 "k8s.io/client-go/informers/core/v1" - listersv1 "k8s.io/client-go/listers/core/v1" + corev1informers "k8s.io/client-go/informers/core/v1" + corev1listers "k8s.io/client-go/listers/core/v1" "k8s.io/client-go/tools/cache" ) @@ -24,12 +24,12 @@ type Controller interface { type controller struct { renewer *tls.CertRenewer - secretLister listersv1.SecretLister + secretLister corev1listers.SecretLister secretQueue chan bool onSecretChanged func() error } -func NewController(secretInformer informerv1.SecretInformer, certRenewer *tls.CertRenewer, onSecretChanged func() error) (Controller, error) { +func NewController(secretInformer corev1informers.SecretInformer, certRenewer *tls.CertRenewer, onSecretChanged func() error) (Controller, error) { manager := &controller{ renewer: certRenewer, secretLister: secretInformer.Lister(), diff --git a/pkg/policy/policy_controller.go b/pkg/policy/policy_controller.go index e7110b0f51..3896831dc9 100644 --- a/pkg/policy/policy_controller.go +++ b/pkg/policy/policy_controller.go @@ -32,10 +32,10 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/wait" - informers "k8s.io/client-go/informers/core/v1" + corev1informers "k8s.io/client-go/informers/core/v1" "k8s.io/client-go/kubernetes" typedcorev1 "k8s.io/client-go/kubernetes/typed/core/v1" - listerv1 "k8s.io/client-go/listers/core/v1" + corev1listers "k8s.io/client-go/listers/core/v1" "k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/record" "k8s.io/client-go/util/workqueue" @@ -74,7 +74,7 @@ type PolicyController struct { urLister urkyvernolister.UpdateRequestLister // nsLister can list/get namespaces from the shared informer's store - nsLister listerv1.NamespaceLister + nsLister corev1listers.NamespaceLister // Resource manager, manages the mapping for already processed resource rm resourceManager @@ -106,7 +106,7 @@ func NewPolicyController( eventGen event.Interface, prGenerator policyreport.GeneratorInterface, policyReportEraser policyreport.PolicyReportEraser, - namespaces informers.NamespaceInformer, + namespaces corev1informers.NamespaceInformer, log logr.Logger, reconcilePeriod time.Duration, promConfig *metrics.PromConfig, diff --git a/pkg/policyreport/reportcontroller.go b/pkg/policyreport/reportcontroller.go index 8b33cb2341..7f1c7abe95 100644 --- a/pkg/policyreport/reportcontroller.go +++ b/pkg/policyreport/reportcontroller.go @@ -28,8 +28,8 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/wait" - informers "k8s.io/client-go/informers/core/v1" - listerv1 "k8s.io/client-go/listers/core/v1" + corev1informers "k8s.io/client-go/informers/core/v1" + corev1listers "k8s.io/client-go/listers/core/v1" "k8s.io/client-go/tools/cache" "k8s.io/client-go/util/workqueue" ) @@ -62,7 +62,7 @@ type ReportGenerator struct { clusterReportLister policyreport.ClusterPolicyReportLister reportChangeRequestLister requestlister.ReportChangeRequestLister clusterReportChangeRequestLister requestlister.ClusterReportChangeRequestLister - nsLister listerv1.NamespaceLister + nsLister corev1listers.NamespaceLister queue workqueue.RateLimitingInterface @@ -81,7 +81,7 @@ func NewReportGenerator( reportInformer policyreportinformer.PolicyReportInformer, reportReqInformer requestinformer.ReportChangeRequestInformer, clusterReportReqInformer requestinformer.ClusterReportChangeRequestInformer, - namespace informers.NamespaceInformer, + namespace corev1informers.NamespaceInformer, log logr.Logger, ) (*ReportGenerator, error) { gen := &ReportGenerator{ diff --git a/pkg/userinfo/roleRef.go b/pkg/userinfo/roleRef.go index cd6b531a5f..08fd73a59f 100644 --- a/pkg/userinfo/roleRef.go +++ b/pkg/userinfo/roleRef.go @@ -10,7 +10,7 @@ import ( authenticationv1 "k8s.io/api/authentication/v1" rbacv1 "k8s.io/api/rbac/v1" labels "k8s.io/apimachinery/pkg/labels" - rbaclister "k8s.io/client-go/listers/rbac/v1" + rbacv1listers "k8s.io/client-go/listers/rbac/v1" "sigs.k8s.io/controller-runtime/pkg/log" ) @@ -22,7 +22,7 @@ const ( ) // GetRoleRef gets the list of roles and cluster roles for the incoming api-request -func GetRoleRef(rbLister rbaclister.RoleBindingLister, crbLister rbaclister.ClusterRoleBindingLister, request *admissionv1.AdmissionRequest, dynamicConfig config.Configuration) ([]string, []string, error) { +func GetRoleRef(rbLister rbacv1listers.RoleBindingLister, crbLister rbacv1listers.ClusterRoleBindingLister, request *admissionv1.AdmissionRequest, dynamicConfig config.Configuration) ([]string, []string, error) { keys := append(request.UserInfo.Groups, request.UserInfo.Username) if utils.SliceContains(keys, dynamicConfig.GetExcludeGroupRole()...) { return nil, nil, nil diff --git a/pkg/webhookconfig/configmanager.go b/pkg/webhookconfig/configmanager.go index b9115c102e..af89b5deb7 100644 --- a/pkg/webhookconfig/configmanager.go +++ b/pkg/webhookconfig/configmanager.go @@ -26,9 +26,9 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/sets" - adminformers "k8s.io/client-go/informers/admissionregistration/v1" + admissionregistrationv1informers "k8s.io/client-go/informers/admissionregistration/v1" "k8s.io/client-go/kubernetes" - admlisters "k8s.io/client-go/listers/admissionregistration/v1" + admissionregistrationv1listers "k8s.io/client-go/listers/admissionregistration/v1" "k8s.io/client-go/tools/cache" "k8s.io/client-go/util/workqueue" ) @@ -46,14 +46,14 @@ type webhookConfigManager struct { // informers pInformer kyvernoinformer.ClusterPolicyInformer npInformer kyvernoinformer.PolicyInformer - mutateInformer adminformers.MutatingWebhookConfigurationInformer - validateInformer adminformers.ValidatingWebhookConfigurationInformer + mutateInformer admissionregistrationv1informers.MutatingWebhookConfigurationInformer + validateInformer admissionregistrationv1informers.ValidatingWebhookConfigurationInformer // listers pLister kyvernolister.ClusterPolicyLister npLister kyvernolister.PolicyLister - mutateLister admlisters.MutatingWebhookConfigurationLister - validateLister admlisters.ValidatingWebhookConfigurationLister + mutateLister admissionregistrationv1listers.MutatingWebhookConfigurationLister + validateLister admissionregistrationv1listers.ValidatingWebhookConfigurationLister // queue queue workqueue.RateLimitingInterface @@ -82,8 +82,8 @@ func newWebhookConfigManager( kyvernoClient kyvernoclient.Interface, pInformer kyvernoinformer.ClusterPolicyInformer, npInformer kyvernoinformer.PolicyInformer, - mwcInformer adminformers.MutatingWebhookConfigurationInformer, - vwcInformer adminformers.ValidatingWebhookConfigurationInformer, + mwcInformer admissionregistrationv1informers.MutatingWebhookConfigurationInformer, + vwcInformer admissionregistrationv1informers.ValidatingWebhookConfigurationInformer, serverIP string, autoUpdateWebhooks bool, createDefaultWebhook chan<- string, diff --git a/pkg/webhookconfig/registration.go b/pkg/webhookconfig/registration.go index 07e9781214..ecd18ba665 100644 --- a/pkg/webhookconfig/registration.go +++ b/pkg/webhookconfig/registration.go @@ -19,11 +19,11 @@ import ( admissionregistrationv1 "k8s.io/api/admissionregistration/v1" errorsapi "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - adminformers "k8s.io/client-go/informers/admissionregistration/v1" - informers "k8s.io/client-go/informers/apps/v1" + admissionregistrationv1informers "k8s.io/client-go/informers/admissionregistration/v1" + appsv1informers "k8s.io/client-go/informers/apps/v1" "k8s.io/client-go/kubernetes" - admlisters "k8s.io/client-go/listers/admissionregistration/v1" - listers "k8s.io/client-go/listers/apps/v1" + admissionregistrationv1listers "k8s.io/client-go/listers/admissionregistration/v1" + appsv1listers "k8s.io/client-go/listers/apps/v1" rest "k8s.io/client-go/rest" ) @@ -44,9 +44,9 @@ type Register struct { clientConfig *rest.Config // listers - mwcLister admlisters.MutatingWebhookConfigurationLister - vwcLister admlisters.ValidatingWebhookConfigurationLister - kDeplLister listers.DeploymentLister + mwcLister admissionregistrationv1listers.MutatingWebhookConfigurationLister + vwcLister admissionregistrationv1listers.ValidatingWebhookConfigurationLister + kDeplLister appsv1listers.DeploymentLister // channels stopCh <-chan struct{} @@ -69,9 +69,9 @@ func NewRegister( client dclient.Interface, kubeClient kubernetes.Interface, kyvernoClient kyvernoclient.Interface, - mwcInformer adminformers.MutatingWebhookConfigurationInformer, - vwcInformer adminformers.ValidatingWebhookConfigurationInformer, - kDeplInformer informers.DeploymentInformer, + mwcInformer admissionregistrationv1informers.MutatingWebhookConfigurationInformer, + vwcInformer admissionregistrationv1informers.ValidatingWebhookConfigurationInformer, + kDeplInformer appsv1informers.DeploymentInformer, pInformer kyvernoinformer.ClusterPolicyInformer, npInformer kyvernoinformer.PolicyInformer, serverIP string, diff --git a/pkg/webhooks/resource/handlers.go b/pkg/webhooks/resource/handlers.go index 1c3afad24b..1e71dd2569 100644 --- a/pkg/webhooks/resource/handlers.go +++ b/pkg/webhooks/resource/handlers.go @@ -34,8 +34,8 @@ import ( admissionv1 "k8s.io/api/admission/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - corelister "k8s.io/client-go/listers/core/v1" - rbaclister "k8s.io/client-go/listers/rbac/v1" + corev1listers "k8s.io/client-go/listers/core/v1" + rbacv1listers "k8s.io/client-go/listers/rbac/v1" ) type handlers struct { @@ -51,9 +51,9 @@ type handlers struct { pCache policycache.Cache // listers - nsLister corelister.NamespaceLister - rbLister rbaclister.RoleBindingLister - crbLister rbaclister.ClusterRoleBindingLister + nsLister corev1listers.NamespaceLister + rbLister rbacv1listers.RoleBindingLister + crbLister rbacv1listers.ClusterRoleBindingLister urLister urlister.UpdateRequestNamespaceLister prGenerator policyreport.GeneratorInterface @@ -70,9 +70,9 @@ func NewHandlers( configuration config.Configuration, promConfig *metrics.PromConfig, pCache policycache.Cache, - nsLister corelister.NamespaceLister, - rbLister rbaclister.RoleBindingLister, - crbLister rbaclister.ClusterRoleBindingLister, + nsLister corev1listers.NamespaceLister, + rbLister rbacv1listers.RoleBindingLister, + crbLister rbacv1listers.ClusterRoleBindingLister, urLister urlister.UpdateRequestNamespaceLister, prGenerator policyreport.GeneratorInterface, urGenerator webhookgenerate.Interface, diff --git a/pkg/webhooks/resource/validate_audit.go b/pkg/webhooks/resource/validate_audit.go index 1638395e0f..d07ac13762 100644 --- a/pkg/webhooks/resource/validate_audit.go +++ b/pkg/webhooks/resource/validate_audit.go @@ -20,10 +20,10 @@ import ( admissionv1 "k8s.io/api/admission/v1" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/wait" - informers "k8s.io/client-go/informers/core/v1" - rbacinformer "k8s.io/client-go/informers/rbac/v1" - listerv1 "k8s.io/client-go/listers/core/v1" - rbaclister "k8s.io/client-go/listers/rbac/v1" + corev1informers "k8s.io/client-go/informers/core/v1" + rbacv1informers "k8s.io/client-go/informers/rbac/v1" + corev1listers "k8s.io/client-go/listers/core/v1" + rbacv1listers "k8s.io/client-go/listers/rbac/v1" "k8s.io/client-go/util/workqueue" ) @@ -48,9 +48,9 @@ type auditHandler struct { eventGen event.Interface prGenerator policyreport.GeneratorInterface - rbLister rbaclister.RoleBindingLister - crbLister rbaclister.ClusterRoleBindingLister - nsLister listerv1.NamespaceLister + rbLister rbacv1listers.RoleBindingLister + crbLister rbacv1listers.ClusterRoleBindingLister + nsLister corev1listers.NamespaceLister log logr.Logger configHandler config.Configuration @@ -61,9 +61,9 @@ type auditHandler struct { func NewValidateAuditHandler(pCache policycache.Cache, eventGen event.Interface, prGenerator policyreport.GeneratorInterface, - rbInformer rbacinformer.RoleBindingInformer, - crbInformer rbacinformer.ClusterRoleBindingInformer, - namespaces informers.NamespaceInformer, + rbInformer rbacv1informers.RoleBindingInformer, + crbInformer rbacv1informers.ClusterRoleBindingInformer, + namespaces corev1informers.NamespaceInformer, log logr.Logger, dynamicConfig config.Configuration, client dclient.Interface,