This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 276
/
Copy pathe2e_statefulsets_test.go
153 lines (125 loc) · 4.14 KB
/
e2e_statefulsets_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package e2e
import (
"context"
"strings"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/rs/zerolog/log"
"github.com/servicemeshinterface/smi-sdk-go/pkg/apis/access/v1alpha3"
"github.com/servicemeshinterface/smi-sdk-go/pkg/apis/specs/v1alpha4"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart/loader"
"helm.sh/helm/v3/pkg/cli"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/openservicemesh/osm/pkg/apis/config/v1alpha2"
. "github.com/openservicemesh/osm/tests/framework"
)
var _ = OSMDescribe("Test traffic among Statefulset members",
OSMDescribeInfo{
Tier: 1,
Bucket: 12,
OS: OSCrossPlatform,
},
func() {
Context("Statefulsets", func() {
It("pods succeed while establishing consensus", func() {
// Install OSM (with proxyMode = podIP)
Expect(Td.InstallOSM(Td.GetOSMInstallOpts(WithLocalProxyMode(v1alpha2.LocalProxyModePodIP)))).To(Succeed())
const testNS = "zookeeper"
// Create Test NS
Expect(Td.CreateNs(testNS, nil)).To(Succeed())
Expect(Td.AddNsToMesh(true, testNS)).To(Succeed())
helmCfg := &action.Configuration{}
Expect(helmCfg.Init(Td.Env.RESTClientGetter(), testNS, "secret", log.Info().Msgf)).To(Succeed())
install := action.NewInstall(helmCfg)
install.ReleaseName = "kafka"
install.Namespace = testNS
install.Timeout = 30 * time.Second
saName := "zookeeper"
replicaCount := 3
cli := cli.New()
chartPath, err := install.LocateChart("https://charts.bitnami.com/bitnami/zookeeper-9.0.2.tgz", cli)
Expect(err).NotTo(HaveOccurred())
chart, err := loader.Load(chartPath)
Expect(err).NotTo(HaveOccurred())
if Td.DeployOnOpenShift {
err = Td.AddOpenShiftSCC("privileged", saName, testNS)
Expect(err).NotTo(HaveOccurred())
}
// Install zookeeper
_, err = install.Run(chart, map[string]interface{}{
"replicaCount": replicaCount,
"serviceAccount": map[string]interface{}{
"create": true,
"name": saName,
},
})
Expect(err).NotTo(HaveOccurred())
// Create SMI resources for Zookeeper
_, err = Td.CreateTCPRoute(testNS, v1alpha4.TCPRoute{
ObjectMeta: metav1.ObjectMeta{
Namespace: testNS,
Name: "zookeeper",
},
Spec: v1alpha4.TCPRouteSpec{
Matches: v1alpha4.TCPMatch{
Ports: []int{2181, 3181, 2888, 3888},
},
},
})
Expect(err).NotTo(HaveOccurred())
_, err = Td.CreateTrafficTarget(testNS, v1alpha3.TrafficTarget{
ObjectMeta: metav1.ObjectMeta{
Namespace: testNS,
Name: "zookeeper",
},
Spec: v1alpha3.TrafficTargetSpec{
Sources: []v1alpha3.IdentityBindingSubject{
{
Kind: "ServiceAccount",
Name: saName,
Namespace: testNS,
},
},
Destination: v1alpha3.IdentityBindingSubject{
Kind: "ServiceAccount",
Name: saName,
Namespace: testNS,
},
Rules: []v1alpha3.TrafficTargetRule{
{
Kind: "TCPRoute",
Name: "zookeeper",
},
},
},
})
Expect(err).NotTo(HaveOccurred())
Expect(Td.WaitForPodsRunningReady(testNS, 90*time.Second, replicaCount, nil)).To(Succeed())
pods, err := Td.Client.CoreV1().Pods(testNS).List(context.TODO(), metav1.ListOptions{})
Expect(err).NotTo(HaveOccurred())
// this command will exit 1 if connectivity isn't established
cmd := "/opt/bitnami/zookeeper/bin/zkServer.sh status"
cond := Td.WaitForRepeatedSuccess(func() bool {
results := map[string]error{}
for _, po := range pods.Items {
stdout, stderr, err := Td.RunRemote(testNS, po.GetName(), "zookeeper", strings.Fields(cmd))
Td.T.Logf("> (%s) Stdout %s | Stderr: %s", po.GetName(), stdout, stderr)
results[po.GetName()] = err
}
hadErr := false
for podName, err := range results {
if err != nil {
Td.T.Logf("> (%s) ZK status check failed: expected nil err, got %s", podName, err)
hadErr = true
continue
}
Td.T.Logf("> (%s) ZK status check succeeded!", podName)
}
return !hadErr
}, 1, 90*time.Second)
Expect(cond).To(BeTrue())
})
})
})