Skip to content

Commit ec13475

Browse files
authored
Refactor logs gather flow to support multiple clusters (openshift-service-mesh#452)
- Refactor logs gathering flow to support logs gather from multiple clusters. This is used in multi cluster scenario - Add "getSecret" function to fetch certs that are used in multicluster test. - Add name cluster to be specified during log gathering. Signed-off-by: Maxim Babushkin <[email protected]>
1 parent 1ac8e14 commit ec13475

File tree

11 files changed

+70
-44
lines changed

11 files changed

+70
-44
lines changed

tests/e2e/controlplane/control_plane_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,5 @@ func setup() {
6363
cl, err = k8sclient.InitK8sClient("")
6464
Expect(err).NotTo(HaveOccurred())
6565

66-
k = kubectl.New()
66+
k = kubectl.New("clControlPlane")
6767
}

tests/e2e/controlplane/control_plane_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ spec:
295295

296296
AfterAll(func(ctx SpecContext) {
297297
if CurrentSpecReport().Failed() {
298-
common.LogDebugInfo()
298+
common.LogDebugInfo(k)
299299
debugInfoLogged = true
300300
}
301301

@@ -314,7 +314,7 @@ spec:
314314

315315
AfterAll(func() {
316316
if CurrentSpecReport().Failed() && !debugInfoLogged {
317-
common.LogDebugInfo()
317+
common.LogDebugInfo(k)
318318
debugInfoLogged = true
319319
}
320320

tests/e2e/dualstack/dualstack_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,5 @@ func setup() {
6363
cl, err = k8sclient.InitK8sClient("")
6464
Expect(err).NotTo(HaveOccurred())
6565

66-
k = kubectl.New()
66+
k = kubectl.New("clDualStack")
6767
}

tests/e2e/dualstack/dualstack_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ spec:
280280

281281
AfterAll(func(ctx SpecContext) {
282282
if CurrentSpecReport().Failed() {
283-
common.LogDebugInfo()
283+
common.LogDebugInfo(k)
284284
debugInfoLogged = true
285285
}
286286

@@ -295,7 +295,7 @@ spec:
295295

296296
AfterAll(func() {
297297
if CurrentSpecReport().Failed() && !debugInfoLogged {
298-
common.LogDebugInfo()
298+
common.LogDebugInfo(k)
299299
debugInfoLogged = true
300300
}
301301

tests/e2e/multicluster/multicluster_multiprimary_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ spec:
253253

254254
AfterAll(func(ctx SpecContext) {
255255
if CurrentSpecReport().Failed() {
256-
common.LogDebugInfo()
256+
common.LogDebugInfo(k1)
257+
common.LogDebugInfo(k2)
257258
debugInfoLogged = true
258259
}
259260

@@ -277,7 +278,8 @@ spec:
277278

278279
AfterAll(func(ctx SpecContext) {
279280
if CurrentSpecReport().Failed() && !debugInfoLogged {
280-
common.LogDebugInfo()
281+
common.LogDebugInfo(k1)
282+
common.LogDebugInfo(k2)
281283
debugInfoLogged = true
282284
}
283285

tests/e2e/multicluster/multicluster_primaryremote_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ spec:
295295

296296
AfterAll(func(ctx SpecContext) {
297297
if CurrentSpecReport().Failed() {
298-
common.LogDebugInfo()
298+
common.LogDebugInfo(k1)
299+
common.LogDebugInfo(k2)
299300
debugInfoLogged = true
300301
}
301302

@@ -319,7 +320,8 @@ spec:
319320

320321
AfterAll(func(ctx SpecContext) {
321322
if CurrentSpecReport().Failed() && !debugInfoLogged {
322-
common.LogDebugInfo()
323+
common.LogDebugInfo(k1)
324+
common.LogDebugInfo(k2)
323325
debugInfoLogged = true
324326
}
325327

tests/e2e/multicluster/multicluster_suite_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,6 @@ func setup(t *testing.T) {
9999
exposeIstiodYAML = fmt.Sprintf("%s/docs/multicluster/expose-istiod.yaml", baseRepoDir)
100100

101101
// Initialize kubectl utilities, one for each cluster
102-
k1 = kubectl.New().WithKubeconfig(kubeconfig)
103-
k2 = kubectl.New().WithKubeconfig(kubeconfig2)
102+
k1 = kubectl.New("clPrimary").WithKubeconfig(kubeconfig)
103+
k2 = kubectl.New("clRemote").WithKubeconfig(kubeconfig2)
104104
}

tests/e2e/operator/operator_install_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ var _ = Describe("Operator", Ordered, func() {
100100

101101
AfterAll(func() {
102102
if CurrentSpecReport().Failed() {
103-
common.LogDebugInfo()
103+
common.LogDebugInfo(k)
104104
}
105105
})
106106
})
107107

108108
AfterAll(func() {
109109
if CurrentSpecReport().Failed() {
110-
common.LogDebugInfo()
110+
common.LogDebugInfo(k)
111111
}
112112

113113
if skipDeploy {

tests/e2e/operator/operator_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,5 @@ func setup() {
6262
GinkgoWriter.Println("Running on Kubernetes")
6363
}
6464

65-
k = kubectl.New()
65+
k = kubectl.New("clOperator")
6666
}

tests/e2e/util/common/e2e_utils.go

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ var (
5757
// - 1.24-alpha.feabc1234
5858
// matching only the version before first '_' which is used in the downstream builds, e.g. "1.23.2_ossm_tp.2"
5959
istiodVersionRegex = regexp.MustCompile(`Version:"([^"_]*)[^"]*"`)
60-
61-
k = kubectl.New()
6260
)
6361

6462
// GetObject returns the object with the given key
@@ -131,73 +129,80 @@ func CheckNamespaceEmpty(ctx SpecContext, cl client.Client, ns string) {
131129
}).Should(BeEmpty(), "No Services should be present in the namespace")
132130
}
133131

134-
func LogDebugInfo() {
132+
func LogDebugInfo(k kubectl.Kubectl) {
135133
// General debugging information to help diagnose the failure
136134
// TODO: Add the creation of file with this information to be attached to the test report
137135

138136
GinkgoWriter.Println()
139-
GinkgoWriter.Println("The test run has failures and the debug information is as follows:")
137+
GinkgoWriter.Println("The test run has failures and the debug information is as follows from cluster: %q:", k.GetClusterName())
138+
GinkgoWriter.Println("=========================================================")
139+
logOperatorDebugInfo(k)
140140
GinkgoWriter.Println("=========================================================")
141-
logOperatorDebugInfo()
141+
logIstioDebugInfo(k)
142142
GinkgoWriter.Println("=========================================================")
143-
logIstioDebugInfo()
143+
logCNIDebugInfo(k)
144144
GinkgoWriter.Println("=========================================================")
145-
logCNIDebugInfo()
145+
logCertsDebugInfo(k)
146146
GinkgoWriter.Println("=========================================================")
147147
}
148148

149-
func logOperatorDebugInfo() {
150-
k := k.WithNamespace(OperatorNamespace)
149+
func logOperatorDebugInfo(k kubectl.Kubectl) {
150+
k = k.WithNamespace(OperatorNamespace)
151151
operator, err := k.GetYAML("deployment", deploymentName)
152-
logDebugElement("Operator Deployment YAML", operator, err)
152+
logDebugElement("=====Operator Deployment YAML=====", operator, err)
153153

154154
logs, err := k.Logs("deploy/"+deploymentName, ptr.Of(120*time.Second))
155-
logDebugElement("Operator logs", logs, err)
155+
logDebugElement("=====Operator logs=====", logs, err)
156156

157157
events, err := k.GetEvents()
158-
logDebugElement("Events in "+OperatorNamespace, events, err)
158+
logDebugElement("=====Events in "+OperatorNamespace+"=====", events, err)
159159

160160
// Temporary information to gather more details about failure
161161
pods, err := k.GetPods("", "-o wide")
162-
logDebugElement("Pods in "+OperatorNamespace, pods, err)
162+
logDebugElement("=====Pods in "+OperatorNamespace+"=====", pods, err)
163163

164164
describe, err := k.Describe("deployment", deploymentName)
165-
logDebugElement("Operator Deployment describe", describe, err)
165+
logDebugElement("=====Operator Deployment describe=====", describe, err)
166166
}
167167

168-
func logIstioDebugInfo() {
168+
func logIstioDebugInfo(k kubectl.Kubectl) {
169169
resource, err := k.GetYAML("istio", istioName)
170-
logDebugElement("Istio YAML", resource, err)
170+
logDebugElement("=====Istio YAML=====", resource, err)
171171

172172
output, err := k.WithNamespace(controlPlaneNamespace).GetPods("", "-o wide")
173-
logDebugElement("Pods in "+controlPlaneNamespace, output, err)
173+
logDebugElement("=====Pods in "+controlPlaneNamespace+"=====", output, err)
174174

175175
logs, err := k.WithNamespace(controlPlaneNamespace).Logs("deploy/istiod", ptr.Of(120*time.Second))
176-
logDebugElement("Istiod logs", logs, err)
176+
logDebugElement("=====Istiod logs=====", logs, err)
177177

178178
events, err := k.WithNamespace(controlPlaneNamespace).GetEvents()
179-
logDebugElement("Events in "+controlPlaneNamespace, events, err)
179+
logDebugElement("=====Events in "+controlPlaneNamespace+"=====", events, err)
180180
}
181181

182-
func logCNIDebugInfo() {
182+
func logCNIDebugInfo(k kubectl.Kubectl) {
183183
resource, err := k.GetYAML("istiocni", istioCniName)
184-
logDebugElement("IstioCNI YAML", resource, err)
184+
logDebugElement("=====IstioCNI YAML=====", resource, err)
185185

186186
ds, err := k.WithNamespace(istioCniNamespace).GetYAML("daemonset", "istio-cni-node")
187-
logDebugElement("Istio CNI DaemonSet YAML", ds, err)
187+
logDebugElement("=====Istio CNI DaemonSet YAML=====", ds, err)
188188

189189
events, err := k.WithNamespace(istioCniNamespace).GetEvents()
190-
logDebugElement("Events in "+istioCniNamespace, events, err)
190+
logDebugElement("=====Events in "+istioCniNamespace+"=====", events, err)
191191

192192
// Temporary information to gather more details about failure
193193
pods, err := k.WithNamespace(istioCniNamespace).GetPods("", "-o wide")
194-
logDebugElement("Pods in "+istioCniNamespace, pods, err)
194+
logDebugElement("=====Pods in "+istioCniNamespace+"=====", pods, err)
195195

196196
describe, err := k.WithNamespace(istioCniNamespace).Describe("daemonset", "istio-cni-node")
197-
logDebugElement("Istio CNI DaemonSet describe", describe, err)
197+
logDebugElement("=====Istio CNI DaemonSet describe=====", describe, err)
198198

199199
logs, err := k.WithNamespace(istioCniNamespace).Logs("daemonset/istio-cni-node", ptr.Of(120*time.Second))
200-
logDebugElement("Istio CNI logs", logs, err)
200+
logDebugElement("=====Istio CNI logs=====", logs, err)
201+
}
202+
203+
func logCertsDebugInfo(k kubectl.Kubectl) {
204+
certs, err := k.WithNamespace(controlPlaneNamespace).GetSecret("cacerts")
205+
logDebugElement("=====CA certs=====", certs, err)
201206
}
202207

203208
func logDebugElement(caption string, info string, err error) {
@@ -211,7 +216,7 @@ func logDebugElement(caption string, info string, err error) {
211216
}
212217

213218
func GetVersionFromIstiod() (*semver.Version, error) {
214-
k := kubectl.New()
219+
k := kubectl.New("testCluster")
215220
output, err := k.WithNamespace(controlPlaneNamespace).Exec("deploy/istiod", "", "pilot-discovery version")
216221
if err != nil {
217222
return nil, fmt.Errorf("error getting version from istiod: %w", err)

0 commit comments

Comments
 (0)