Skip to content

Commit

Permalink
Send Tekton installation namespace to EL
Browse files Browse the repository at this point in the history
The EventListener did not have knowledge of which namespace Triggers was
installed in. Instead it always assumed it was `tekton-pipelines` leading to
the bug described in #923.  This commit fixes this by having the Reconciler
send the installation namespace as a environment variable set on the
EventListener's pod.

NOTE: This fix is temporary and should not be necessary once #868 is
implemented since then we will resolve the Interceptor's address using
information from its CRD.

Fixes #923

Signed-off-by: Dibyo Mukherjee <[email protected]>
  • Loading branch information
dibyom authored and tekton-robot committed Jan 27, 2021
1 parent e22be40 commit 97f7fcc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pkg/interceptors/interceptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ import (
"io/ioutil"
"net/http"
"net/url"
"os"
"path"

"github.com/tektoncd/triggers/pkg/system"

"google.golang.org/grpc/codes"

triggersv1 "github.com/tektoncd/triggers/pkg/apis/triggers/v1alpha1"
Expand Down Expand Up @@ -188,7 +187,7 @@ func ResolveURL(i *triggersv1.TriggerInterceptor) *url.URL {
}
return &url.URL{
Scheme: "http",
Host: fmt.Sprintf("%s.%s.svc", CoreInterceptorsHost, system.DefaultNamespace),
Host: fmt.Sprintf("%s.%s.svc", CoreInterceptorsHost, os.Getenv("TEKTON_INSTALL_NAMESPACE")),
Path: path,
}
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/interceptors/interceptors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"os"
"strings"
"testing"

Expand Down Expand Up @@ -327,12 +328,27 @@ func TestResolvePath(t *testing.T) {
want: "http://tekton-triggers-core-interceptors.tekton-pipelines.svc",
}} {
t.Run(tc.want, func(t *testing.T) {
os.Setenv("TEKTON_INSTALL_NAMESPACE", "tekton-pipelines")
t.Cleanup(func() { os.Unsetenv("TEKTON_INSTALL_NAMESPACE") })
got := interceptors.ResolveURL(&tc.in)
if tc.want != got.String() {
t.Fatalf("ResolveURL() want: %s; got: %s", tc.want, got)
}
})
}

t.Run("different namespaces", func(t *testing.T) {
os.Setenv("TEKTON_INSTALL_NAMESPACE", "another-namespace")
t.Cleanup(func() { os.Unsetenv("TEKTON_INSTALL_NAMESPACE") })
in := &triggersv1.EventInterceptor{
Bitbucket: &triggersv1.BitbucketInterceptor{},
}
got := interceptors.ResolveURL(in)
want := "http://tekton-triggers-core-interceptors.another-namespace.svc/bitbucket"
if want != got.String() {
t.Fatalf("ResolveURL() want: %s; got: %s", want, got)
}
})
}

// testServer creates a httptest server with the passed in handler and returns a http.Client that
Expand Down
4 changes: 4 additions & 0 deletions pkg/reconciler/v1alpha1/eventlistener/eventlistener.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/tektoncd/triggers/pkg/apis/triggers/v1alpha1"
listers "github.com/tektoncd/triggers/pkg/client/listers/triggers/v1alpha1"
"github.com/tektoncd/triggers/pkg/system"
"go.uber.org/zap"
"golang.org/x/xerrors"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -462,6 +463,9 @@ func getContainer(el *v1alpha1.EventListener, c Config) corev1.Container {
FieldPath: "metadata.namespace",
},
},
}, {
Name: "TEKTON_INSTALL_NAMESPACE",
Value: system.GetNamespace(),
}}

certEnv := map[string]*corev1.EnvVarSource{}
Expand Down
6 changes: 6 additions & 0 deletions pkg/reconciler/v1alpha1/eventlistener/eventlistener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ func makeDeployment(ops ...func(d *appsv1.Deployment)) *appsv1.Deployment {
FieldPath: "metadata.namespace",
},
},
}, {
Name: "TEKTON_INSTALL_NAMESPACE",
Value: "tekton-pipelines",
}},
}},
Volumes: []corev1.Volume{{
Expand Down Expand Up @@ -333,6 +336,9 @@ var withTLSConfig = func(d *appsv1.Deployment) {
FieldPath: "metadata.namespace",
},
},
}, {
Name: "TEKTON_INSTALL_NAMESPACE",
Value: "tekton-pipelines",
}, {
Name: "TLS_CERT",
ValueFrom: &corev1.EnvVarSource{
Expand Down

0 comments on commit 97f7fcc

Please sign in to comment.