Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit 98d8904

Browse files
authored
Merge pull request #4073 from jaellio/e2eIgnoreNamespace
feat(e2e): ensures namespace ignore label takes precedence
2 parents 22f7049 + e49b267 commit 98d8904

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package e2e
2+
3+
import (
4+
"context"
5+
"time"
6+
7+
. "github.com/onsi/ginkgo"
8+
. "github.com/onsi/gomega"
9+
corev1 "k8s.io/api/core/v1"
10+
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11+
12+
"github.com/openservicemesh/osm/pkg/constants"
13+
. "github.com/openservicemesh/osm/tests/framework"
14+
)
15+
16+
var _ = OSMDescribe("Ignore Namespaces",
17+
OSMDescribeInfo{
18+
Tier: 1,
19+
Bucket: 2,
20+
},
21+
func() {
22+
Context("Ignore Label", func() {
23+
const ignoreNs = "ignore"
24+
25+
It("Tests the ignore label on a namespace disables sidecar injection", func() {
26+
// Install OSM
27+
installOpts := Td.GetOSMInstallOpts()
28+
installOpts.EnablePermissiveMode = true
29+
Expect(Td.InstallOSM(installOpts)).To(Succeed())
30+
31+
// Create test NS in mesh with ignore label
32+
Expect(Td.CreateNs(ignoreNs, map[string]string{constants.IgnoreLabel: "true"})).To(Succeed())
33+
34+
// Add test NS to mesh with sidecar injection enabled
35+
Expect(Td.AddNsToMesh(true, ignoreNs)).To(Succeed())
36+
37+
By("Ensuring a pod is not injected with a sidecar when added to namespace the ignore, and sidecar injection labels set")
38+
39+
// Get simple Pod definitions
40+
svcAccDef, podDef, svcDef, err := Td.SimplePodApp(
41+
SimplePodAppDef{
42+
Name: "pod1",
43+
Namespace: ignoreNs,
44+
Command: []string{"/bin/bash", "-c", "--"},
45+
Args: []string{"while true; do sleep 30; done;"},
46+
Image: "songrgg/alpine-debug",
47+
Ports: []int{80},
48+
OS: Td.ClusterOS,
49+
})
50+
Expect(err).NotTo(HaveOccurred())
51+
52+
_, err = Td.CreateServiceAccount(ignoreNs, &svcAccDef)
53+
Expect(err).NotTo(HaveOccurred())
54+
pod, err := Td.CreatePod(ignoreNs, podDef)
55+
Expect(err).NotTo(HaveOccurred())
56+
_, err = Td.CreateService(ignoreNs, svcDef)
57+
Expect(err).NotTo(HaveOccurred())
58+
59+
Expect(Td.WaitForPodsRunningReady(ignoreNs, 90*time.Second, 1, nil)).To(Succeed())
60+
61+
pod, err = Td.Client.CoreV1().Pods(ignoreNs).Get(context.Background(), pod.Name, v1.GetOptions{})
62+
Expect(err).NotTo(HaveOccurred())
63+
64+
Expect(hasSidecar(pod.Spec.Containers)).To(BeFalse())
65+
})
66+
})
67+
})
68+
69+
func hasSidecar(containers []corev1.Container) bool {
70+
for _, container := range containers {
71+
if container.Name == constants.EnvoyContainerName {
72+
return true
73+
}
74+
}
75+
return false
76+
}

0 commit comments

Comments
 (0)