Skip to content

Commit

Permalink
Remove unused pipeline clients from Triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
dibyom committed Apr 10, 2020
1 parent e79f300 commit 50252a3
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 49 deletions.
2 changes: 0 additions & 2 deletions cmd/eventlistenersink/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pkg/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 0 additions & 12 deletions pkg/reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions pkg/reconciler/v1alpha1/eventlistener/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -44,17 +42,13 @@ 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)
serviceInformer := serviceinformer.Get(ctx)

opt := reconciler.Options{
KubeClientSet: kubeclientset,
PipelineClientSet: pipelineclientset,
ResourceClientSet: resourceclientset,
TriggersClientSet: triggersclientset,
ConfigMapWatcher: cmw,
Logger: logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 0 additions & 14 deletions pkg/sink/initialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
4 changes: 0 additions & 4 deletions pkg/sink/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
19 changes: 10 additions & 9 deletions pkg/sink/sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))

Expand All @@ -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
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)
}

Expand Down
17 changes: 17 additions & 0 deletions pkg/system/system.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 50252a3

Please sign in to comment.