Skip to content

Commit 34faaeb

Browse files
authored
test(e2e): improve universal app run (#13033)
## Motivation It was very hard to have a complete and readable state of things in the test report because we were executing one of ssh cmds in different places. We now keep a persistent ssh session for the whole time of the app which makes things easier to track and the output easier to consume. ## Implementation information the ssh package was completely redesigned to keep an ssh session rather than forking to execute `ssh` commands. This makes things easier to follow, easier to write lengthy scripts without caring about escaping things correctly for bash. Once this was done we could start a CP or run a DP with a single cmdLine instead of a list of complex calls. This makes the report a lot easier as it avoids a lot of noisy stuff. Other minor changes: - Stop doing retries inside the framework. Either we should retry because it's setup or simply in an eventually. Also stop using the retry from terratest as it's very verbose. - ignore for dockerfiles were including things that were not necessary, this made the building of images longer. - Once this change was done we could run into clock skews with tokens. So moved the token issuance date a few seconds in the past ## Supporting documentation Fix #13123 --------- Signed-off-by: Charly Molter <[email protected]>
1 parent 11a2a92 commit 34faaeb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+655
-695
lines changed

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ require (
214214
github.com/moby/patternmatcher v0.6.0 // indirect
215215
github.com/moby/spdystream v0.5.0 // indirect
216216
github.com/moby/sys/sequential v0.5.0 // indirect
217-
github.com/moby/sys/user v0.1.0 // indirect
217+
github.com/moby/sys/user v0.3.0 // indirect
218218
github.com/moby/sys/userns v0.1.0 // indirect
219219
github.com/moby/term v0.5.0 // indirect
220220
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
@@ -252,10 +252,9 @@ require (
252252
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
253253
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
254254
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.35.0 // indirect
255-
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 // indirect
256255
go.opentelemetry.io/otel/metric v1.35.0 // indirect
257256
go.uber.org/atomic v1.10.0 // indirect
258-
golang.org/x/crypto v0.36.0 // indirect
257+
golang.org/x/crypto v0.36.0
259258
golang.org/x/exp v0.0.0-20250128182459-e0ece0dbea4c
260259
golang.org/x/mod v0.24.0 // indirect
261260
golang.org/x/oauth2 v0.27.0 // indirect
@@ -277,6 +276,7 @@ require (
277276
github.com/blang/semver/v4 v4.0.0 // indirect
278277
github.com/google/cel-go v0.22.0 // indirect
279278
github.com/stoewer/go-strcase v1.3.0 // indirect
279+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 // indirect
280280
k8s.io/apiserver v0.32.3 // indirect
281281
k8s.io/component-base v0.32.3 // indirect
282282
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,8 @@ github.com/moby/sys/mountinfo v0.7.2 h1:1shs6aH5s4o5H2zQLn796ADW1wMrIwHsyJ2v9Kou
368368
github.com/moby/sys/mountinfo v0.7.2/go.mod h1:1YOa8w8Ih7uW0wALDUgT1dTTSBrZ+HiBLGws92L2RU4=
369369
github.com/moby/sys/sequential v0.5.0 h1:OPvI35Lzn9K04PBbCLW0g4LcFAJgHsvXsRyewg5lXtc=
370370
github.com/moby/sys/sequential v0.5.0/go.mod h1:tH2cOOs5V9MlPiXcQzRC+eEyab644PWKGRYaaV5ZZlo=
371-
github.com/moby/sys/user v0.1.0 h1:WmZ93f5Ux6het5iituh9x2zAG7NFY9Aqi49jjE1PaQg=
372-
github.com/moby/sys/user v0.1.0/go.mod h1:fKJhFOnsCN6xZ5gSfbM6zaHGgDJMrqt9/reuj4T7MmU=
371+
github.com/moby/sys/user v0.3.0 h1:9ni5DlcW5an3SvRSx4MouotOygvzaXbaSrc/wGDFWPo=
372+
github.com/moby/sys/user v0.3.0/go.mod h1:bG+tYYYJgaMtRKgEmuueC0hJEAZWwtIbZTB+85uoHjs=
373373
github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g=
374374
github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28=
375375
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=

pkg/core/tokens/issuer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ func (j *jwtTokenIssuer) Generate(ctx context.Context, claims Claims, validFor t
3737
return "", err
3838
}
3939

40-
now := core.Now()
40+
now := core.Now().Add(-5 * time.Second) // todo(jakubdyszkiewicz) parametrize via config and go through all clock skews in the project
4141
claims.SetRegisteredClaims(jwt.RegisteredClaims{
4242
ID: core.NewUUID(),
4343
IssuedAt: jwt.NewNumericDate(now),
44-
NotBefore: jwt.NewNumericDate(now.Add(time.Minute * -5)), // todo(jakubdyszkiewicz) parametrize via config and go through all clock skews in the project
45-
ExpiresAt: jwt.NewNumericDate(now.Add(validFor)),
44+
NotBefore: jwt.NewNumericDate(now),
45+
ExpiresAt: jwt.NewNumericDate(now.Add(validFor).Add(5 * time.Second)),
4646
})
4747

4848
token := jwt.NewWithClaims(jwt.SigningMethodRS256, claims)

pkg/util/files/files.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package files
22

33
import (
4+
"fmt"
5+
"io"
46
"io/fs"
57
"os"
68
"path/filepath"
@@ -49,3 +51,18 @@ func ToValidUnixFilename(input ...string) string {
4951

5052
return sanitized
5153
}
54+
55+
// CopyFile copies the file content to a new path.
56+
// This should be used with caution as it was first written for tests
57+
func CopyFile(src, dst string) error {
58+
srcFile, err := os.Open(src)
59+
if err != nil {
60+
return fmt.Errorf("failed to open src file:%s %w", src, err)
61+
}
62+
dstFile, err := os.Create(dst)
63+
if err != nil {
64+
return fmt.Errorf("failed to create dest file:%s %w", dst, err)
65+
}
66+
_, err = io.Copy(dstFile, srcFile)
67+
return err
68+
}

test/dockerfiles/universal.dockerignore

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111
!build/artifacts-linux-arm64/kumactl/kumactl
1212
!build/artifacts-linux-arm64/coredns/coredns
1313
!build/artifacts-linux-arm64/test-server/test-server
14-
!build/artifacts-darwin-arm64/kuma-cp/kuma-cp
15-
!build/artifacts-darwin-arm64/kuma-dp/kuma-dp
16-
!build/artifacts-darwin-arm64/envoy/*
17-
!build/artifacts-darwin-arm64/kumactl/kumactl
18-
!build/artifacts-darwin-arm64/coredns/coredns
19-
!build/artifacts-darwin-arm64/test-server/test-server
2014
!pkg/config/app/kuma-cp/kuma-cp.defaults.yaml
2115
!tools/releases/templates/LICENSE
2216
!tools/releases/templates/NOTICE

test/e2e_env/multizone/externalservices/externalservices_multizone_universal.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -155,42 +155,42 @@ routing:
155155
Expect(err).ToNot(HaveOccurred())
156156

157157
Eventually(func(g Gomega) {
158-
stdout, _, err := client.CollectResponse(
158+
stdout, stderr, err := client.CollectResponse(
159159
zone1, "demo-client", "external-service-1.mesh",
160160
client.WithVerbose(),
161161
)
162162
g.Expect(err).ToNot(HaveOccurred())
163-
g.Expect(stdout).To(ContainSubstring("HTTP/1.1 200 OK"))
163+
g.Expect(stderr).To(ContainSubstring("HTTP/1.1 200 OK"))
164164
g.Expect(stdout).ToNot(ContainSubstring("HTTPS"))
165165
}, "1m", "3s").Should(Succeed())
166166

167167
Eventually(func(g Gomega) {
168-
stdout, _, err := client.CollectResponse(
168+
stdout, stderr, err := client.CollectResponse(
169169
zone1, "demo-client", "kuma-es-4_es-http:80",
170170
client.WithVerbose(),
171171
)
172172
g.Expect(err).ToNot(HaveOccurred())
173-
g.Expect(stdout).To(ContainSubstring("HTTP/1.1 200 OK"))
173+
g.Expect(stderr).To(ContainSubstring("HTTP/1.1 200 OK"))
174174
g.Expect(stdout).ToNot(ContainSubstring("HTTPS"))
175175
}, "1m", "3s").Should(Succeed())
176176

177177
Eventually(func(g Gomega) {
178-
stdout, _, err := client.CollectResponse(
178+
stdout, stderr, err := client.CollectResponse(
179179
zone2, "demo-client", "external-service-1.mesh",
180180
client.WithVerbose(),
181181
)
182182
g.Expect(err).ToNot(HaveOccurred())
183-
g.Expect(stdout).To(ContainSubstring("HTTP/1.1 200 OK"))
183+
g.Expect(stderr).To(ContainSubstring("HTTP/1.1 200 OK"))
184184
g.Expect(stdout).ToNot(ContainSubstring("HTTPS"))
185185
}, "1m", "3s").Should(Succeed())
186186

187187
Eventually(func(g Gomega) {
188-
stdout, _, err := client.CollectResponse(
188+
stdout, stderr, err := client.CollectResponse(
189189
zone2, "demo-client", "kuma-es-4_es-http:80",
190190
client.WithVerbose(),
191191
)
192192
g.Expect(err).ToNot(HaveOccurred())
193-
g.Expect(stdout).To(ContainSubstring("HTTP/1.1 200 OK"))
193+
g.Expect(stderr).To(ContainSubstring("HTTP/1.1 200 OK"))
194194
g.Expect(stdout).ToNot(ContainSubstring("HTTPS"))
195195
}, "1m", "3s").Should(Succeed())
196196
})
@@ -219,22 +219,22 @@ routing:
219219

220220
// then accessing the secured external service succeeds
221221
Eventually(func(g Gomega) {
222-
stdout, _, err := client.CollectResponse(
222+
stdout, stderr, err := client.CollectResponse(
223223
zone1, "demo-client", "http://kuma-es-4_es-https:443",
224224
client.WithVerbose(),
225225
)
226226
g.Expect(err).ToNot(HaveOccurred())
227-
g.Expect(stdout).To(ContainSubstring("HTTP/1.1 200 OK"))
227+
g.Expect(stderr).To(ContainSubstring("HTTP/1.1 200 OK"))
228228
g.Expect(stdout).To(ContainSubstring("es-https"))
229229
}, "1m", "1s").Should(Succeed())
230230

231231
Eventually(func(g Gomega) {
232-
stdout, _, err := client.CollectResponse(
232+
stdout, stderr, err := client.CollectResponse(
233233
zone2, "demo-client", "http://kuma-es-4_es-https:443",
234234
client.WithVerbose(),
235235
)
236236
g.Expect(err).ToNot(HaveOccurred())
237-
g.Expect(stdout).To(ContainSubstring("HTTP/1.1 200 OK"))
237+
g.Expect(stderr).To(ContainSubstring("HTTP/1.1 200 OK"))
238238
g.Expect(stdout).To(ContainSubstring("es-https"))
239239
}, "1m", "3s").Should(Succeed())
240240
})

test/e2e_env/multizone/ownership/ownership.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,11 @@ func MultizoneUniversal() {
6262
}
6363

6464
killKumaDP := func(appname string) {
65-
_, _, err := zoneUniversal.Exec("", "", appname, "pkill", "-9", "envoy")
66-
Expect(err).ToNot(HaveOccurred())
65+
Expect(zoneUniversal.(*UniversalCluster).Kill(appname, "kuma-dp")).To(Succeed())
6766
}
6867

6968
killZone := func() {
70-
_, _, err := zoneUniversal.Exec("", "", AppModeCP, "pkill", "-9", "kuma-cp")
71-
Expect(err).ToNot(HaveOccurred())
69+
Expect(zoneUniversal.(*UniversalCluster).Kill(AppModeCP, "kuma-cp run")).To(Succeed())
7270
Eventually(func() (string, error) {
7371
return global.GetKumactlOptions().RunKumactlAndGetOutput("inspect", "zones")
7472
}, "30s", "1s").Should(ContainSubstring("Offline"))

test/e2e_env/multizone/resilience/resilience_multizone_universal.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ func ResilienceMultizoneUniversal() {
6565
return nil
6666
}, "30s", "1s").ShouldNot(HaveOccurred())
6767

68-
_, _, err := zone1.Exec("", "", AppModeCP, "pkill", "-9", "kuma-cp")
69-
Expect(err).ToNot(HaveOccurred())
68+
Expect(zone1.(*UniversalCluster).Kill(AppModeCP, "kuma-cp run")).To(Succeed())
7069

7170
Eventually(func() error {
7271
output, err := global.GetKumactlOptions().RunKumactlAndGetOutput("inspect", "zones")

test/e2e_env/multizone/resilience/resilience_multizone_universal_postgres.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,10 @@ func ResilienceMultizoneUniversalPostgres() {
9191
Expect(kumaCP).ToNot(BeNil())
9292

9393
// when global is killed
94-
_, _, err := global.Exec("", "", AppModeCP, "pkill", "-9", "kuma-cp")
95-
Expect(err).ToNot(HaveOccurred())
94+
Expect(global.(*UniversalCluster).Kill(AppModeCP, "kuma-cp run")).To(Succeed())
9695

9796
// and zone is killed while global is down
98-
_, _, err = zoneUniversal.Exec("", "", AppModeCP, "pkill", "-9", "kuma-cp")
99-
Expect(err).ToNot(HaveOccurred())
97+
Expect(zoneUniversal.(*UniversalCluster).Kill(AppModeCP, "kuma-cp run")).To(Succeed())
10098

10199
// and global is restarted
102100
Expect(kumaCP.ReStart()).Should(Succeed())
@@ -122,8 +120,7 @@ func ResilienceMultizoneUniversalPostgres() {
122120
Expect(kumaCP).ToNot(BeNil())
123121

124122
// when global is killed
125-
_, _, err := global.Exec("", "", AppModeCP, "pkill", "-9", "kuma-cp")
126-
Expect(err).ToNot(HaveOccurred())
123+
Expect(global.(*UniversalCluster).Kill(AppModeCP, "kuma-cp run")).To(Succeed())
127124

128125
// and global is restarted
129126
Expect(kumaCP.ReStart()).Should(Succeed())
@@ -133,8 +130,7 @@ func ResilienceMultizoneUniversalPostgres() {
133130
time.Sleep(10 * time.Second) // ZoneInsightFlushInterval
134131

135132
// and zone is killed
136-
_, _, err = zoneUniversal.Exec("", "", AppModeCP, "pkill", "-9", "kuma-cp")
137-
Expect(err).ToNot(HaveOccurred())
133+
Expect(zoneUniversal.(*UniversalCluster).Kill(AppModeCP, "kuma-cp run")).To(Succeed())
138134

139135
// then zone is offline
140136
Eventually(func() (string, error) {
@@ -156,12 +152,10 @@ func ResilienceMultizoneUniversalPostgres() {
156152
Expect(kumaCP).ToNot(BeNil())
157153

158154
// when Zone CP is killed
159-
_, _, err := zoneUniversal.Exec("", "", AppModeCP, "pkill", "-9", "kuma-cp")
160-
Expect(err).ToNot(HaveOccurred())
155+
Expect(zoneUniversal.(*UniversalCluster).Kill(AppModeCP, "kuma-cp run")).To(Succeed())
161156

162157
// and zone-ingress is killed while Zone CP is down
163-
_, _, err = zoneUniversal.Exec("", "", AppIngress, "pkill", "-9", "envoy")
164-
Expect(err).ToNot(HaveOccurred())
158+
Expect(zoneUniversal.(*UniversalCluster).Kill(AppIngress, "kuma-dp")).To(Succeed())
165159

166160
// and Zone CP is restarted
167161
Expect(kumaCP.ReStart()).Should(Succeed())
@@ -181,8 +175,7 @@ func ResilienceMultizoneUniversalPostgres() {
181175
}, "30s", "1s").Should(ContainSubstring("Online"))
182176

183177
// when Zone CP is killed
184-
_, _, err := zoneUniversal.Exec("", "", AppModeCP, "pkill", "-9", "kuma-cp")
185-
Expect(err).ToNot(HaveOccurred())
178+
Expect(zoneUniversal.(*UniversalCluster).Kill(AppModeCP, "kuma-cp run")).To(Succeed())
186179

187180
// then zone is offline immediately
188181
Eventually(func() (string, error) {

test/e2e_env/universal/auth/offline_auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ dpServer:
120120
token,
121121
[]string{},
122122
)
123+
Expect(err).ToNot(HaveOccurred())
123124

124125
// then the new admin can access secrets
125-
Expect(err).ToNot(HaveOccurred())
126126
Expect(kumactl.RunKumactl("get", "secrets")).To(Succeed())
127127
})
128128

0 commit comments

Comments
 (0)