topgun/k8s: Test external team namespaces
Added tests for consuming creds from an external namespace.
fixes: concourse/concourse#3107
@@ -20,13 +20,17 @@ var _ = Describe("Kubernetes credential management", func() {
namespace string
username = "test"
password = "test"
+ extraArgs []string
)
BeforeEach(func(){
releaseName = fmt.Sprintf("topgun-k8s-cm-%d-%d", GinkgoRandomSeed(), GinkgoParallelNode())
namespace = releaseName
+ })
+
+ JustBeforeEach(func() {
- deployConcourseChart(releaseName, "--set=worker.replicas=1")
+ deployConcourseChart(releaseName, append([]string{"--set=worker.replicas=1"}, extraArgs...)...)
waitAllPodsInNamespaceToBeReady(namespace)
@@ -71,7 +75,40 @@ var _ = Describe("Kubernetes credential management", func() {
})
Context("Consuming per-team k8s secrets", func() {
+ JustBeforeEach(func() {
+ // ((foo)) --> bar
+ createCredentialSecret(releaseName, "foo", "main", map[string]string{"value": "bar"})
+
+ // ((caz.baz)) --> zaz
+ createCredentialSecret(releaseName, "caz", "main", map[string]string{"baz": "zaz"})
+
+ fly.Run("set-pipeline", "-n", "-c", "../pipelines/minimal-credential-management.yml", "-p", "pipeline")
+ session := fly.Start("get-pipeline", "-p", "pipeline")
+ Wait(session)
+
+ Expect(string(session.Out.Contents())).ToNot(ContainSubstring("bar"))
+ Expect(string(session.Out.Contents())).ToNot(ContainSubstring("zaz"))
+
+ fly.Run("unpause-pipeline", "-p", "pipeline")
+ })
+
+ It("Gets credentials set by consuming k8s secrets", func() {
+ session := fly.Start("trigger-job", "-j", "pipeline/unit", "-w")
+ Wait(session)
+
+ Expect(string(session.Out.Contents())).To(ContainSubstring("bar"))
+ Expect(string(session.Out.Contents())).To(ContainSubstring("zaz"))
+ })
+ })
+
+ Context("consuming creds from pre-created namespace for a team", func() {
BeforeEach(func() {
+ Run(nil, "kubectl", "create", "namespace", releaseName+"-main")
+ extraArgs = []string{
+ "--set=concourse.web.kubernetes.createTeamNamespaces=false",
+ }
+ })
+ JustBeforeEach(func() {
// ((foo)) --> bar
createCredentialSecret(releaseName, "foo", "main", map[string]string{"value": "bar"})
@@ -95,16 +132,21 @@ var _ = Describe("Kubernetes credential management", func() {
Expect(string(session.Out.Contents())).To(ContainSubstring("bar"))
Expect(string(session.Out.Contents())).To(ContainSubstring("zaz"))
})
+
+ AfterEach(func(){
+ Run(nil, "kubectl", "delete", "namespace", releaseName+"-main", "--wait=false")
+ })
})
AfterEach(func() {
helmDestroy(releaseName)
Wait(proxySession.Interrupt())
- Wait(Start(nil, "kubectl", "delete", "namespace", namespace, "--wait=false"))
+ Run(nil, "kubectl", "delete", "namespace", namespace, "--wait=false")
})
})
+
func createCredentialSecret(releaseName, secretName, team string, kv map[string]string) {
args := []string{
"create",
@@ -118,5 +160,5 @@ func createCredentialSecret(releaseName, secretName, team string, kv map[string]
args = append(args, "--from-literal="+key+"="+value)
}
- Wait(Start(nil, "kubectl", args...))
+ Run(nil, "kubectl", args...)
}
