mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
refactor: replace clientset by inteface (#3774)
Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
This commit is contained in:
parent
a592dad2aa
commit
6e07acdd87
15 changed files with 40 additions and 47 deletions
|
@ -232,7 +232,7 @@ func acquireLeader(ctx context.Context, kubeClient kubernetes.Interface) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func executeRequest(client *client.Client, kyvernoclient *kyvernoclient.Clientset, req request) error {
|
||||
func executeRequest(client *client.Client, kyvernoclient kyvernoclient.Interface, req request) error {
|
||||
switch req.kind {
|
||||
case policyReportKind:
|
||||
return removePolicyReport(client, req.kind)
|
||||
|
@ -283,7 +283,7 @@ func gen(done <-chan struct{}, stopCh <-chan struct{}, requests ...request) <-ch
|
|||
}
|
||||
|
||||
// processes the requests
|
||||
func process(client *client.Client, kyvernoclient *kyvernoclient.Clientset, done <-chan struct{}, stopCh <-chan struct{}, requests <-chan request) <-chan error {
|
||||
func process(client *client.Client, 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() {
|
||||
|
@ -464,7 +464,7 @@ func addSelectorLabel(client *client.Client, apiversion, kind, ns, name string)
|
|||
log.Log.Info("successfully updated resource labels", "kind", kind, "name", name)
|
||||
}
|
||||
|
||||
func convertGR(pclient *kyvernoclient.Clientset) error {
|
||||
func convertGR(pclient kyvernoclient.Interface) error {
|
||||
logger := log.Log.WithName("convertGenerateRequest")
|
||||
|
||||
var errors []error
|
||||
|
|
|
@ -37,7 +37,7 @@ type Controller struct {
|
|||
client *dclient.Client
|
||||
|
||||
// typed client for kyverno CRDs
|
||||
kyvernoClient *kyvernoclient.Clientset
|
||||
kyvernoClient kyvernoclient.Interface
|
||||
|
||||
pInformer kyvernoinformer.ClusterPolicyInformer
|
||||
urInformer urkyvernoinformer.UpdateRequestInformer
|
||||
|
@ -67,7 +67,7 @@ type Controller struct {
|
|||
//NewController returns a new controller instance to manage generate-requests
|
||||
func NewController(
|
||||
kubeClient kubernetes.Interface,
|
||||
kyvernoclient *kyvernoclient.Clientset,
|
||||
kyvernoclient kyvernoclient.Interface,
|
||||
client *dclient.Client,
|
||||
pInformer kyvernoinformer.ClusterPolicyInformer,
|
||||
npInformer kyvernoinformer.PolicyInformer,
|
||||
|
|
|
@ -41,7 +41,7 @@ type GenerateController struct {
|
|||
client *dclient.Client
|
||||
|
||||
// typed client for Kyverno CRDs
|
||||
kyvernoClient *kyvernoclient.Clientset
|
||||
kyvernoClient kyvernoclient.Interface
|
||||
|
||||
// urStatusControl is used to update UR status
|
||||
statusControl common.StatusControlInterface
|
||||
|
@ -68,7 +68,7 @@ type GenerateController struct {
|
|||
|
||||
//NewGenerateController returns an instance of the Generate-Request Controller
|
||||
func NewGenerateController(
|
||||
kyvernoClient *kyvernoclient.Clientset,
|
||||
kyvernoClient kyvernoclient.Interface,
|
||||
client *dclient.Client,
|
||||
policyLister kyvernolister.ClusterPolicyLister,
|
||||
npolicyLister kyvernolister.PolicyLister,
|
||||
|
|
|
@ -29,7 +29,7 @@ type MutateExistingController struct {
|
|||
client *dclient.Client
|
||||
|
||||
// typed client for Kyverno CRDs
|
||||
kyvernoClient *kyvernoclient.Clientset
|
||||
kyvernoClient kyvernoclient.Interface
|
||||
|
||||
// urStatusControl is used to update UR status
|
||||
statusControl common.StatusControlInterface
|
||||
|
@ -53,7 +53,7 @@ type MutateExistingController struct {
|
|||
|
||||
// NewMutateExistingController returns an instance of the MutateExistingController
|
||||
func NewMutateExistingController(
|
||||
kyvernoClient *kyvernoclient.Clientset,
|
||||
kyvernoClient kyvernoclient.Interface,
|
||||
client *dclient.Client,
|
||||
policyLister kyvernolister.ClusterPolicyLister,
|
||||
npolicyLister kyvernolister.PolicyLister,
|
||||
|
|
|
@ -38,7 +38,7 @@ type Controller struct {
|
|||
client *dclient.Client
|
||||
|
||||
// typed client for Kyverno CRDs
|
||||
kyvernoClient *kyvernoclient.Clientset
|
||||
kyvernoClient kyvernoclient.Interface
|
||||
|
||||
policyInformer kyvernoinformer.ClusterPolicyInformer
|
||||
|
||||
|
@ -71,7 +71,7 @@ type Controller struct {
|
|||
//NewController returns an instance of the Generate-Request Controller
|
||||
func NewController(
|
||||
kubeClient kubernetes.Interface,
|
||||
kyvernoClient *kyvernoclient.Clientset,
|
||||
kyvernoClient kyvernoclient.Interface,
|
||||
client *dclient.Client,
|
||||
policyInformer kyvernoinformer.ClusterPolicyInformer,
|
||||
npolicyInformer kyvernoinformer.PolicyInformer,
|
||||
|
|
|
@ -54,7 +54,7 @@ const (
|
|||
// in the system with the corresponding policy violations
|
||||
type PolicyController struct {
|
||||
client *client.Client
|
||||
kyvernoClient *kyvernoclient.Clientset
|
||||
kyvernoClient kyvernoclient.Interface
|
||||
pInformer kyvernoinformer.ClusterPolicyInformer
|
||||
npInformer kyvernoinformer.PolicyInformer
|
||||
|
||||
|
@ -97,7 +97,7 @@ type PolicyController struct {
|
|||
// NewPolicyController create a new PolicyController
|
||||
func NewPolicyController(
|
||||
kubeClient kubernetes.Interface,
|
||||
kyvernoClient *kyvernoclient.Clientset,
|
||||
kyvernoClient kyvernoclient.Interface,
|
||||
client *client.Client,
|
||||
pInformer kyvernoinformer.ClusterPolicyInformer,
|
||||
npInformer kyvernoinformer.PolicyInformer,
|
||||
|
@ -565,7 +565,7 @@ func getTrigger(rd kyverno.ResourceDescription) []*kyverno.ResourceSpec {
|
|||
return specs
|
||||
}
|
||||
|
||||
func deleteGR(kyvernoClient *kyvernoclient.Clientset, policyKey string, grList []*urkyverno.UpdateRequest, logger logr.Logger) {
|
||||
func deleteGR(kyvernoClient kyvernoclient.Interface, policyKey string, grList []*urkyverno.UpdateRequest, logger logr.Logger) {
|
||||
for _, v := range grList {
|
||||
if policyKey == v.Spec.Policy {
|
||||
err := kyvernoClient.KyvernoV1beta1().UpdateRequests(config.KyvernoNamespace).Delete(context.TODO(), v.GetName(), metav1.DeleteOptions{})
|
||||
|
@ -576,7 +576,7 @@ func deleteGR(kyvernoClient *kyvernoclient.Clientset, policyKey string, grList [
|
|||
}
|
||||
}
|
||||
|
||||
func updateUR(kyvernoClient *kyvernoclient.Clientset, policyKey string, grList []*urkyverno.UpdateRequest, logger logr.Logger) {
|
||||
func updateUR(kyvernoClient kyvernoclient.Interface, policyKey string, grList []*urkyverno.UpdateRequest, logger logr.Logger) {
|
||||
for _, gr := range grList {
|
||||
if policyKey == gr.Spec.Policy {
|
||||
grLabels := gr.Labels
|
||||
|
|
|
@ -78,7 +78,7 @@ func (pc *PolicyController) forceReconciliation(reconcileCh <-chan bool, stopCh
|
|||
}
|
||||
}
|
||||
|
||||
func cleanupReportChangeRequests(pclient *kyvernoclient.Clientset, rcrLister changerequestlister.ReportChangeRequestLister, crcrLister changerequestlister.ClusterReportChangeRequestLister) error {
|
||||
func cleanupReportChangeRequests(pclient kyvernoclient.Interface, rcrLister changerequestlister.ReportChangeRequestLister, crcrLister changerequestlister.ClusterReportChangeRequestLister) error {
|
||||
var errors []string
|
||||
|
||||
var gracePeriod int64 = 0
|
||||
|
@ -101,7 +101,7 @@ func cleanupReportChangeRequests(pclient *kyvernoclient.Clientset, rcrLister cha
|
|||
return fmt.Errorf("%v", strings.Join(errors, ";"))
|
||||
}
|
||||
|
||||
func eraseResultsEntries(pclient *kyvernoclient.Clientset, reportLister policyreportlister.PolicyReportLister, clusterReportLister policyreportlister.ClusterPolicyReportLister) error {
|
||||
func eraseResultsEntries(pclient kyvernoclient.Interface, reportLister policyreportlister.PolicyReportLister, clusterReportLister policyreportlister.ClusterPolicyReportLister) error {
|
||||
selector, err := metav1.LabelSelectorAsSelector(policyreport.LabelSelector)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to erase results entries %v", err)
|
||||
|
|
|
@ -25,7 +25,7 @@ type creator interface {
|
|||
}
|
||||
|
||||
type changeRequestCreator struct {
|
||||
client *policyreportclient.Clientset
|
||||
client policyreportclient.Interface
|
||||
|
||||
// addCache preserves requests that are to be added to report
|
||||
RCRCache *cache.Cache
|
||||
|
@ -41,7 +41,7 @@ type changeRequestCreator struct {
|
|||
log logr.Logger
|
||||
}
|
||||
|
||||
func newChangeRequestCreator(client *policyreportclient.Clientset, tickerInterval time.Duration, log logr.Logger) creator {
|
||||
func newChangeRequestCreator(client policyreportclient.Interface, tickerInterval time.Duration, log logr.Logger) creator {
|
||||
return &changeRequestCreator{
|
||||
client: client,
|
||||
RCRCache: cache.New(0, 24*time.Hour),
|
||||
|
|
|
@ -20,8 +20,8 @@ type PolicyReportEraser interface {
|
|||
EraseResultsEntries(erase EraseResultsEntries) error
|
||||
}
|
||||
|
||||
type CleanupReportChangeRequests = func(pclient *kyvernoclient.Clientset, rcrLister changerequestlister.ReportChangeRequestLister, crcrLister changerequestlister.ClusterReportChangeRequestLister) error
|
||||
type EraseResultsEntries = func(pclient *kyvernoclient.Clientset, reportLister policyreportlister.PolicyReportLister, clusterReportLister policyreportlister.ClusterPolicyReportLister) error
|
||||
type CleanupReportChangeRequests = func(pclient kyvernoclient.Interface, rcrLister changerequestlister.ReportChangeRequestLister, crcrLister changerequestlister.ClusterReportChangeRequestLister) error
|
||||
type EraseResultsEntries = func(pclient kyvernoclient.Interface, reportLister policyreportlister.PolicyReportLister, clusterReportLister policyreportlister.ClusterPolicyReportLister) error
|
||||
|
||||
func (g *ReportGenerator) CleanupReportChangeRequests(cleanup CleanupReportChangeRequests) error {
|
||||
return cleanup(g.pclient, g.reportChangeRequestLister, g.clusterReportChangeRequestLister)
|
||||
|
|
|
@ -50,7 +50,7 @@ var LabelSelector = &metav1.LabelSelector{
|
|||
|
||||
// ReportGenerator creates policy report
|
||||
type ReportGenerator struct {
|
||||
pclient *kyvernoclient.Clientset
|
||||
pclient kyvernoclient.Interface
|
||||
dclient *dclient.Client
|
||||
|
||||
clusterReportInformer policyreportinformer.ClusterPolicyReportInformer
|
||||
|
@ -75,7 +75,7 @@ type ReportGenerator struct {
|
|||
|
||||
// NewReportGenerator returns a new instance of policy report generator
|
||||
func NewReportGenerator(
|
||||
pclient *kyvernoclient.Clientset,
|
||||
pclient kyvernoclient.Interface,
|
||||
dclient *dclient.Client,
|
||||
clusterReportInformer policyreportinformer.ClusterPolicyReportInformer,
|
||||
reportInformer policyreportinformer.PolicyReportInformer,
|
||||
|
|
|
@ -48,7 +48,7 @@ type Generator struct {
|
|||
}
|
||||
|
||||
// NewReportChangeRequestGenerator returns a new instance of report request generator
|
||||
func NewReportChangeRequestGenerator(client *policyreportclient.Clientset,
|
||||
func NewReportChangeRequestGenerator(client policyreportclient.Interface,
|
||||
dclient *dclient.Client,
|
||||
reportReqInformer requestinformer.ReportChangeRequestInformer,
|
||||
clusterReportReqInformer requestinformer.ClusterReportChangeRequestInformer,
|
||||
|
|
|
@ -79,7 +79,7 @@ type manage interface {
|
|||
|
||||
func newWebhookConfigManager(
|
||||
client *client.Client,
|
||||
kyvernoClient *kyvernoclient.Clientset,
|
||||
kyvernoClient kyvernoclient.Interface,
|
||||
pInformer kyvernoinformer.ClusterPolicyInformer,
|
||||
npInformer kyvernoinformer.PolicyInformer,
|
||||
mwcInformer adminformers.MutatingWebhookConfigurationInformer,
|
||||
|
|
|
@ -69,7 +69,7 @@ func NewRegister(
|
|||
clientConfig *rest.Config,
|
||||
client *client.Client,
|
||||
kubeClient kubernetes.Interface,
|
||||
kyvernoClient *kyvernoclient.Clientset,
|
||||
kyvernoClient kyvernoclient.Interface,
|
||||
mwcInformer adminformers.MutatingWebhookConfigurationInformer,
|
||||
vwcInformer adminformers.ValidatingWebhookConfigurationInformer,
|
||||
kDeplInformer informers.DeploymentInformer,
|
||||
|
|
|
@ -39,24 +39,19 @@ import (
|
|||
|
||||
// WebhookServer contains configured TLS server with MutationWebhook.
|
||||
type WebhookServer struct {
|
||||
server *http.Server
|
||||
server *http.Server
|
||||
|
||||
// clients
|
||||
client *client.Client
|
||||
kyvernoClient *kyvernoclient.Clientset
|
||||
kyvernoClient kyvernoclient.Interface
|
||||
|
||||
// urLister can list/get update requests from the shared informer's store
|
||||
urLister urlister.UpdateRequestNamespaceLister
|
||||
|
||||
// list/get role binding resource
|
||||
rbLister rbaclister.RoleBindingLister
|
||||
|
||||
// list/get role binding resource
|
||||
rLister rbaclister.RoleLister
|
||||
|
||||
// list/get role binding resource
|
||||
crLister rbaclister.ClusterRoleLister
|
||||
|
||||
// list/get cluster role binding resource
|
||||
// listers
|
||||
urLister urlister.UpdateRequestNamespaceLister
|
||||
rbLister rbaclister.RoleBindingLister
|
||||
rLister rbaclister.RoleLister
|
||||
crLister rbaclister.ClusterRoleLister
|
||||
crbLister rbaclister.ClusterRoleBindingLister
|
||||
nsLister listerv1.NamespaceLister
|
||||
|
||||
// generate events
|
||||
eventGen event.Interface
|
||||
|
@ -82,8 +77,6 @@ type WebhookServer struct {
|
|||
// update request generator
|
||||
urGenerator webhookgenerate.Interface
|
||||
|
||||
nsLister listerv1.NamespaceLister
|
||||
|
||||
auditHandler AuditHandler
|
||||
|
||||
log logr.Logger
|
||||
|
@ -100,7 +93,7 @@ type WebhookServer struct {
|
|||
// NewWebhookServer creates new instance of WebhookServer accordingly to given configuration
|
||||
// Policy Controller and Kubernetes Client should be initialized in configuration
|
||||
func NewWebhookServer(
|
||||
kyvernoClient *kyvernoclient.Clientset,
|
||||
kyvernoClient kyvernoclient.Interface,
|
||||
client *client.Client,
|
||||
tlsPair *tlsutils.PemPair,
|
||||
urInformer urinformer.UpdateRequestInformer,
|
||||
|
|
|
@ -32,7 +32,7 @@ type info struct {
|
|||
|
||||
// Generator defines the implementation to mange update request resource
|
||||
type Generator struct {
|
||||
client *kyvernoclient.Clientset
|
||||
client kyvernoclient.Interface
|
||||
stopCh <-chan struct{}
|
||||
log logr.Logger
|
||||
|
||||
|
@ -40,7 +40,7 @@ type Generator struct {
|
|||
}
|
||||
|
||||
// NewGenerator returns a new instance of UpdateRequest resource generator
|
||||
func NewGenerator(client *kyvernoclient.Clientset, urInformer urkyvernoinformer.UpdateRequestInformer, stopCh <-chan struct{}, log logr.Logger) *Generator {
|
||||
func NewGenerator(client kyvernoclient.Interface, urInformer urkyvernoinformer.UpdateRequestInformer, stopCh <-chan struct{}, log logr.Logger) *Generator {
|
||||
gen := &Generator{
|
||||
client: client,
|
||||
stopCh: stopCh,
|
||||
|
@ -89,7 +89,7 @@ func (g *Generator) generate(i info) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func retryApplyResource(client *kyvernoclient.Clientset, urSpec urkyverno.UpdateRequestSpec,
|
||||
func retryApplyResource(client kyvernoclient.Interface, urSpec urkyverno.UpdateRequestSpec,
|
||||
log logr.Logger, action admissionv1.Operation, urLister urkyvernolister.UpdateRequestNamespaceLister) error {
|
||||
|
||||
if action == admissionv1.Delete && urSpec.Type == urkyverno.Generate {
|
||||
|
|
Loading…
Add table
Reference in a new issue