Skip to content

Commit

Permalink
Use system.DefaultNamespace for interceptor urls
Browse files Browse the repository at this point in the history
SYSTEM_NAMESPACE is set to the namespace of the EventListener by the reconciler
which means that with the current logic the interceptor url is wrong. Use
default namespace to always use `tekton-pipelines` as the namespace. This is
hardcoded and the logic is temporary till we implement #868.

Also, actually wire up the HTTP handler in the interceptors server.
  • Loading branch information
dibyom authored and tekton-robot committed Jan 11, 2021
1 parent d74327a commit 608bc75
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 38 deletions.
1 change: 1 addition & 0 deletions cmd/interceptors/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func main() {
ReadTimeout: readTimeout,
WriteTimeout: writeTimeout,
IdleTimeout: idleTimeout,
Handler: mux,
}

logger.Infof("Listen and serve on port %d", Port)
Expand Down
2 changes: 1 addition & 1 deletion pkg/interceptors/interceptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func ResolveURL(i *triggersv1.TriggerInterceptor) *url.URL {
}
return &url.URL{
Scheme: "http",
Host: fmt.Sprintf("%s.%s.svc", CoreInterceptorsHost, system.GetNamespace()),
Host: fmt.Sprintf("%s.%s.svc", CoreInterceptorsHost, system.DefaultNamespace),
Path: path,
}
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/interceptors/interceptors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,27 +304,27 @@ func TestResolvePath(t *testing.T) {
in: triggersv1.EventInterceptor{
CEL: &triggersv1.CELInterceptor{},
},
want: "http://tekton-triggers-core-interceptors.knative-testing.svc/cel",
want: "http://tekton-triggers-core-interceptors.tekton-pipelines.svc/cel",
}, {
in: triggersv1.EventInterceptor{
GitLab: &triggersv1.GitLabInterceptor{},
},
want: "http://tekton-triggers-core-interceptors.knative-testing.svc/gitlab",
want: "http://tekton-triggers-core-interceptors.tekton-pipelines.svc/gitlab",
}, {
in: triggersv1.EventInterceptor{
GitHub: &triggersv1.GitHubInterceptor{},
},
want: "http://tekton-triggers-core-interceptors.knative-testing.svc/github",
want: "http://tekton-triggers-core-interceptors.tekton-pipelines.svc/github",
}, {
in: triggersv1.EventInterceptor{
Bitbucket: &triggersv1.BitbucketInterceptor{},
},
want: "http://tekton-triggers-core-interceptors.knative-testing.svc/bitbucket",
want: "http://tekton-triggers-core-interceptors.tekton-pipelines.svc/bitbucket",
}, {
in: triggersv1.EventInterceptor{
Webhook: &triggersv1.WebhookInterceptor{},
},
want: "http://tekton-triggers-core-interceptors.knative-testing.svc",
want: "http://tekton-triggers-core-interceptors.tekton-pipelines.svc",
}} {
t.Run(tc.want, func(t *testing.T) {
got := interceptors.ResolveURL(&tc.in)
Expand Down
77 changes: 45 additions & 32 deletions test/eventlistener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
"strings"
"testing"

"knative.dev/pkg/ptr"

"k8s.io/client-go/kubernetes"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -278,42 +280,53 @@ func TestEventListenerCreate(t *testing.T) {
}
impersonateRBAC(t, sa.Name, namespace, c.KubeClient)

// EventListener
el, err := c.TriggersClient.TriggersV1alpha1().EventListeners(namespace).Create(context.Background(),
bldr.EventListener("my-eventlistener", namespace,
bldr.EventListenerMeta(
bldr.Label("triggers", "eventlistener"),
),
bldr.EventListenerSpec(
bldr.EventListenerResources(
bldr.EventListenerKubernetesResources(
bldr.EventListenerPodSpec(duckv1.WithPodSpec{
Template: duckv1.PodSpecable{
Spec: corev1.PodSpec{
ServiceAccountName: sa.Name,
NodeSelector: map[string]string{"beta.kubernetes.io/os": "linux"},
Tolerations: []corev1.Toleration{{
Key: "key",
Operator: "Equal",
Value: "value",
Effect: "NoSchedule",
}},
},
el, err := c.TriggersClient.TriggersV1alpha1().EventListeners(namespace).Create(context.Background(), &triggersv1.EventListener{
ObjectMeta: metav1.ObjectMeta{
Name: "my-eventlistener",
Namespace: namespace,
},
Spec: triggersv1.EventListenerSpec{
Triggers: []triggersv1.EventListenerTrigger{{
Bindings: []*triggersv1.EventListenerBinding{{
Ref: tb.Name,
Kind: triggersv1.NamespacedTriggerBindingKind,
}, {
Ref: ctb.Name,
Kind: triggersv1.ClusterTriggerBindingKind,
}},
Template: &triggersv1.EventListenerTemplate{
Ref: ptr.String(tt.Name),
},
Interceptors: []*triggersv1.EventInterceptor{{
CEL: &triggersv1.CELInterceptor{
Filter: `body.action == "edited"`,
},
}},
}},
Replicas: ptr.Int32(3),
Resources: triggersv1.Resources{
KubernetesResource: &triggersv1.KubernetesResource{
WithPodSpec: duckv1.WithPodSpec{
Template: duckv1.PodSpecable{
Spec: corev1.PodSpec{
ServiceAccountName: sa.Name,
NodeSelector: map[string]string{"beta.kubernetes.io/os": "linux"},
Tolerations: []corev1.Toleration{{
Key: "key",
Operator: "Equal",
Value: "value",
Effect: "NoSchedule",
}},
},
}),
),
),
bldr.EventListenerReplicas(3),
bldr.EventListenerTrigger(tt.Name, "",
bldr.EventListenerTriggerBinding(tb.Name, "", "v1alpha1"),
bldr.EventListenerTriggerBinding(ctb.Name, "ClusterTriggerBinding", "v1alpha1"),
),
),
), metav1.CreateOptions{})
},
},
},
},
},
}, metav1.CreateOptions{})
if err != nil {
t.Fatalf("Failed to create EventListener: %s", err)
}

// Verify the EventListener to be ready
if err := WaitFor(eventListenerReady(t, c, namespace, el.Name)); err != nil {
t.Fatalf("EventListener not ready: %s", err)
Expand Down

0 comments on commit 608bc75

Please sign in to comment.