From 50252a3e109e22fca1205fa2e2cf4191a58deed3 Mon Sep 17 00:00:00 2001 From: Dibyo Mukherjee Date: Fri, 10 Apr 2020 18:07:40 -0400 Subject: [PATCH] Remove unused pipeline clients from Triggers --- cmd/eventlistenersink/main.go | 2 -- pkg/logging/logging.go | 2 +- pkg/reconciler/reconciler.go | 12 ------------ .../v1alpha1/eventlistener/controller.go | 6 ------ .../eventlistener/eventlistener_test.go | 2 +- pkg/sink/initialization.go | 14 -------------- pkg/sink/sink.go | 4 ---- pkg/sink/sink_test.go | 19 ++++++++++--------- pkg/system/system.go | 17 +++++++++++++++++ 9 files changed, 29 insertions(+), 49 deletions(-) create mode 100644 pkg/system/system.go diff --git a/cmd/eventlistenersink/main.go b/cmd/eventlistenersink/main.go index bab92f7f93..e3477f6dca 100644 --- a/cmd/eventlistenersink/main.go +++ b/cmd/eventlistenersink/main.go @@ -86,8 +86,6 @@ func main() { DiscoveryClient: sinkClients.DiscoveryClient, DynamicClient: dynamicCS, TriggersClient: sinkClients.TriggersClient, - PipelineClient: sinkClients.PipelineClient, - ResourceClient: sinkClients.ResourceClient, HTTPClient: http.DefaultClient, EventListenerName: sinkArgs.ElName, EventListenerNamespace: sinkArgs.ElNamespace, diff --git a/pkg/logging/logging.go b/pkg/logging/logging.go index c6b757ae68..37e44b3b35 100644 --- a/pkg/logging/logging.go +++ b/pkg/logging/logging.go @@ -20,7 +20,7 @@ import ( "flag" "log" - "github.com/tektoncd/pipeline/pkg/system" + "github.com/tektoncd/triggers/pkg/system" "go.uber.org/zap" "k8s.io/client-go/kubernetes" "knative.dev/pkg/configmap" diff --git a/pkg/reconciler/reconciler.go b/pkg/reconciler/reconciler.go index d787df5cd1..98cb580936 100644 --- a/pkg/reconciler/reconciler.go +++ b/pkg/reconciler/reconciler.go @@ -19,8 +19,6 @@ package reconciler import ( "time" - pipelineclientset "github.com/tektoncd/pipeline/pkg/client/clientset/versioned" - resourceclientset "github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned" triggersclientset "github.com/tektoncd/triggers/pkg/client/clientset/versioned" triggersScheme "github.com/tektoncd/triggers/pkg/client/clientset/versioned/scheme" "go.uber.org/zap" @@ -39,8 +37,6 @@ import ( // creating our controllers. type Options struct { KubeClientSet kubernetes.Interface - PipelineClientSet pipelineclientset.Interface - ResourceClientSet resourceclientset.Interface TriggersClientSet triggersclientset.Interface CachingClientSet cachingclientset.Interface @@ -64,12 +60,6 @@ type Base struct { // KubeClientSet allows us to talk to the k8s for core APIs KubeClientSet kubernetes.Interface - // PipelineClientSet allows us to configure pipeline objects - PipelineClientSet pipelineclientset.Interface - - // ResourceClientSet allows us to configure pipeline resource objects - ResourceClientSet resourceclientset.Interface - // TriggersClientSet allows us to configure triggers objects TriggersClientSet triggersclientset.Interface @@ -114,8 +104,6 @@ func NewBase(opt Options, controllerAgentName string) *Base { base := &Base{ KubeClientSet: opt.KubeClientSet, - PipelineClientSet: opt.PipelineClientSet, - ResourceClientSet: opt.ResourceClientSet, TriggersClientSet: opt.TriggersClientSet, CachingClientSet: opt.CachingClientSet, ConfigMapWatcher: opt.ConfigMapWatcher, diff --git a/pkg/reconciler/v1alpha1/eventlistener/controller.go b/pkg/reconciler/v1alpha1/eventlistener/controller.go index 0890d47e35..fd4aae8909 100644 --- a/pkg/reconciler/v1alpha1/eventlistener/controller.go +++ b/pkg/reconciler/v1alpha1/eventlistener/controller.go @@ -21,8 +21,6 @@ import ( "os" "time" - pipelineclient "github.com/tektoncd/pipeline/pkg/client/injection/client" - resourceclient "github.com/tektoncd/pipeline/pkg/client/resource/injection/client" "github.com/tektoncd/triggers/pkg/apis/triggers/v1alpha1" triggersclient "github.com/tektoncd/triggers/pkg/client/injection/client" eventlistenerinformer "github.com/tektoncd/triggers/pkg/client/injection/informers/triggers/v1alpha1/eventlistener" @@ -44,8 +42,6 @@ const ( func NewController(ctx context.Context, cmw configmap.Watcher) *controller.Impl { logger := logging.FromContext(ctx) kubeclientset := kubeclient.Get(ctx) - pipelineclientset := pipelineclient.Get(ctx) - resourceclientset := resourceclient.Get(ctx) triggersclientset := triggersclient.Get(ctx) eventListenerInformer := eventlistenerinformer.Get(ctx) deploymentInformer := deployinformer.Get(ctx) @@ -53,8 +49,6 @@ func NewController(ctx context.Context, cmw configmap.Watcher) *controller.Impl opt := reconciler.Options{ KubeClientSet: kubeclientset, - PipelineClientSet: pipelineclientset, - ResourceClientSet: resourceclientset, TriggersClientSet: triggersclientset, ConfigMapWatcher: cmw, Logger: logger, diff --git a/pkg/reconciler/v1alpha1/eventlistener/eventlistener_test.go b/pkg/reconciler/v1alpha1/eventlistener/eventlistener_test.go index 2fd85b4ffe..b2e0cc03fc 100644 --- a/pkg/reconciler/v1alpha1/eventlistener/eventlistener_test.go +++ b/pkg/reconciler/v1alpha1/eventlistener/eventlistener_test.go @@ -25,8 +25,8 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/tektoncd/pipeline/pkg/system" "github.com/tektoncd/triggers/pkg/apis/triggers/v1alpha1" + "github.com/tektoncd/triggers/pkg/system" "github.com/tektoncd/triggers/test" bldr "github.com/tektoncd/triggers/test/builder" appsv1 "k8s.io/api/apps/v1" diff --git a/pkg/sink/initialization.go b/pkg/sink/initialization.go index 8149ff21c9..d0979d0c82 100644 --- a/pkg/sink/initialization.go +++ b/pkg/sink/initialization.go @@ -19,8 +19,6 @@ package sink import ( "flag" - pipelineclientset "github.com/tektoncd/pipeline/pkg/client/clientset/versioned" - resourceclientset "github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned" triggersclientset "github.com/tektoncd/triggers/pkg/client/clientset/versioned" "golang.org/x/xerrors" discoveryclient "k8s.io/client-go/discovery" @@ -60,8 +58,6 @@ type Clients struct { DiscoveryClient discoveryclient.DiscoveryInterface RESTClient restclient.Interface TriggersClient triggersclientset.Interface - PipelineClient pipelineclientset.Interface - ResourceClient resourceclientset.Interface } // GetArgs returns the flagged Args @@ -97,20 +93,10 @@ func ConfigureClients() (Clients, error) { if err != nil { return Clients{}, xerrors.Errorf("Failed to create TriggersClient: %s", err) } - pipelineclient, err := pipelineclientset.NewForConfig(clusterConfig) - if err != nil { - return Clients{}, xerrors.Errorf("Failed to create PipelineClient: %s", err) - } - resourceclient, err := resourceclientset.NewForConfig(clusterConfig) - if err != nil { - return Clients{}, xerrors.Errorf("Failed to create ResourceClient: %s", err) - } return Clients{ DiscoveryClient: kubeClient.Discovery(), RESTClient: kubeClient.RESTClient(), TriggersClient: triggersClient, - PipelineClient: pipelineclient, - ResourceClient: resourceclient, }, nil } diff --git a/pkg/sink/sink.go b/pkg/sink/sink.go index 2f4c3638c2..5a01064d38 100644 --- a/pkg/sink/sink.go +++ b/pkg/sink/sink.go @@ -24,8 +24,6 @@ import ( "io/ioutil" "net/http" - pipelineclientset "github.com/tektoncd/pipeline/pkg/client/clientset/versioned" - resourceclientset "github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned" triggersv1 "github.com/tektoncd/triggers/pkg/apis/triggers/v1alpha1" triggersclientset "github.com/tektoncd/triggers/pkg/client/clientset/versioned" "github.com/tektoncd/triggers/pkg/interceptors" @@ -50,8 +48,6 @@ type Sink struct { TriggersClient triggersclientset.Interface DiscoveryClient discoveryclient.ServerResourcesInterface DynamicClient dynamic.Interface - PipelineClient pipelineclientset.Interface - ResourceClient resourceclientset.Interface HTTPClient *http.Client EventListenerName string EventListenerNamespace string diff --git a/pkg/sink/sink_test.go b/pkg/sink/sink_test.go index 716df72258..c84c47edbb 100644 --- a/pkg/sink/sink_test.go +++ b/pkg/sink/sink_test.go @@ -40,7 +40,6 @@ import ( "github.com/gorilla/mux" pipelinev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "github.com/tektoncd/pipeline/pkg/logging" triggersv1 "github.com/tektoncd/triggers/pkg/apis/triggers/v1alpha1" dynamicclientset "github.com/tektoncd/triggers/pkg/client/dynamic/clientset" "github.com/tektoncd/triggers/pkg/client/dynamic/clientset/tekton" @@ -86,7 +85,8 @@ func getSinkAssets(t *testing.T, resources test.Resources, elName string, auth A clients := test.SeedResources(t, ctx, resources) test.AddTektonResources(clients.Kube) - logger, _ := logging.NewLogger("", "") + logger, _ := zap.NewProduction() + dynamicClient := fakedynamic.NewSimpleDynamicClient(runtime.NewScheme()) dynamicSet := dynamicclientset.New(tekton.WithClient(dynamicClient)) @@ -97,7 +97,7 @@ func getSinkAssets(t *testing.T, resources test.Resources, elName string, auth A DiscoveryClient: clients.Kube.Discovery(), KubeClientSet: clients.Kube, TriggersClient: clients.Triggers, - Logger: logger, + Logger: logger.Sugar(), Auth: auth, } return r, dynamicClient @@ -555,10 +555,11 @@ func TestExecuteInterceptor(t *testing.T) { Proxy: http.ProxyURL(u), } - logger, _ := logging.NewLogger("", "") + logger, _ := zap.NewProduction() + r := Sink{ HTTPClient: srv.Client(), - Logger: logger, + Logger: logger.Sugar(), } a := &triggersv1.EventInterceptor{ @@ -590,7 +591,7 @@ func TestExecuteInterceptor(t *testing.T) { if err != nil { t.Fatalf("http.NewRequest: %v", err) } - resp, header, err := r.executeInterceptors(trigger, req, []byte(`{}`), logger) + resp, header, err := r.executeInterceptors(trigger, req, []byte(`{}`), logger.Sugar()) if err != nil { t.Fatalf("executeInterceptors: %v", err) } @@ -638,10 +639,10 @@ func TestExecuteInterceptor_error(t *testing.T) { Proxy: http.ProxyURL(u), } - logger, _ := logging.NewLogger("", "") + logger, _ := zap.NewProduction() s := Sink{ HTTPClient: client, - Logger: logger, + Logger: logger.Sugar(), } trigger := &triggersv1.EventListenerTrigger{ @@ -671,7 +672,7 @@ func TestExecuteInterceptor_error(t *testing.T) { if err != nil { t.Fatalf("http.NewRequest: %v", err) } - if resp, _, err := s.executeInterceptors(trigger, req, nil, logger); err == nil { + if resp, _, err := s.executeInterceptors(trigger, req, nil, logger.Sugar()); err == nil { t.Errorf("expected error, got: %+v, %v", string(resp), err) } diff --git a/pkg/system/system.go b/pkg/system/system.go new file mode 100644 index 0000000000..f6e1bcf23f --- /dev/null +++ b/pkg/system/system.go @@ -0,0 +1,17 @@ +package system + +import "os" + +const ( + DefaultNamespace = "tekton-pipelines" + SystemNamespaceEnvVar = "SYSTEM_NAMESPACE" +) + +// GetNamespace holds the K8s namespace where our system components run. +func GetNamespace() string { + systemNamespace := os.Getenv(SystemNamespaceEnvVar) + if systemNamespace == "" { + return DefaultNamespace + } + return systemNamespace +}