Skip to content

Commit 35a4723

Browse files
authored
[Release-1.29] Fix upgrade test, docker test cleanup (#11997)
* Fix upgrade test container version Signed-off-by: Derek Nola <[email protected]> * Force docker test cleanup in CI Signed-off-by: Derek Nola <[email protected]> * Bump skew test deployment time Signed-off-by: Derek Nola <[email protected]> --------- Signed-off-by: Derek Nola <[email protected]>
1 parent b0da678 commit 35a4723

File tree

10 files changed

+38
-29
lines changed

10 files changed

+38
-29
lines changed

scripts/test

+10-10
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,25 @@ export K3S_IMAGE="rancher/k3s:${VERSION_TAG}${SUFFIX}"
2626
# Run all tests on tag events, as we want test failures to block the release
2727
if [ "$ARCH" == 'arm' ] || [ "$DRONE_BUILD_EVENT" = 'tag' ]; then
2828

29-
go test ./tests/docker/basics/basics_test.go -k3sImage="$K3S_IMAGE"
29+
go test ./tests/docker/basics/basics_test.go -k3sImage="$K3S_IMAGE" -ci
3030
echo "Did go test basics $?"
3131

3232
# Extract v1.XX minor version for skew and upgrade tests
3333
minor_version=$(echo $VERSION_K8S | cut -d '.' -f1,2)
3434

35-
go test ./tests/docker/cacerts/cacerts_test.go -k3sImage="$K3S_IMAGE"
35+
go test ./tests/docker/cacerts/cacerts_test.go -k3sImage="$K3S_IMAGE" -ci
3636
echo "Did go test cacerts $?"
3737

38-
go test ./tests/docker/skew/skew_test.go -k3sImage="$K3S_IMAGE" -channel="$minor_version"
38+
go test ./tests/docker/skew/skew_test.go -k3sImage="$K3S_IMAGE" -channel="$minor_version" -ci
3939
echo "Did go test skew $?"
4040

41-
go test ./tests/docker/bootstraptoken/bootstraptoken_test.go -k3sImage="$K3S_IMAGE"
41+
go test ./tests/docker/bootstraptoken/bootstraptoken_test.go -k3sImage="$K3S_IMAGE" -ci
4242
echo "Did go test bootstraptoken $?"
4343

44-
go test ./tests/docker/upgrade/upgrade_test.go -k3sImage="$K3S_IMAGE" -channel="$minor_version"
44+
go test ./tests/docker/upgrade/upgrade_test.go -k3sImage="$K3S_IMAGE" -channel="$minor_version" -ci
4545
echo "Did go test upgrade $?"
4646

47-
go test ./tests/docker/lazypull/lazypull_test.go -k3sImage="$K3S_IMAGE"
47+
go test ./tests/docker/lazypull/lazypull_test.go -k3sImage="$K3S_IMAGE" -ci
4848
echo "Did go test lazypull $?"
4949

5050
fi
@@ -71,9 +71,9 @@ fi
7171
# ---
7272

7373
if [ "$DRONE_BUILD_EVENT" = 'cron' ]; then
74-
run-go-test ./test/docker/conformance/conformance_test.go -k3sImage="$K3S_IMAGE" -db sqlite -serial -ginkgo.v
74+
run-go-test ./tests/docker/conformance/conformance_test.go -k3sImage="$K3S_IMAGE" -db sqlite -serial -ginkgo.v -ci
7575
echo "Did go conformance sqlite serial $?"
76-
run-go-test ./test/docker/conformance/conformance_test.go -k3sImage="$K3S_IMAGE" -db etcd -serial -ginkgo.v
76+
run-go-test ./tests/docker/conformance/conformance_test.go -k3sImage="$K3S_IMAGE" -db etcd -serial -ginkgo.v -ci
7777
echo "Did go conformance etcd serial $?"
7878
test-run-sonobuoy mysql serial
7979
echo "Did test-run-sonobuoy-mysqk serial $?"
@@ -91,9 +91,9 @@ if [ "$DRONE_BUILD_EVENT" = 'cron' ]; then
9191

9292
E2E_OUTPUT=$artifacts test-run-sonobuoy parallel
9393
echo "Did test-run-sonobuoy parallel $?"
94-
run-go-test ./test/docker/conformance/conformance_test.go -k3sImage="$K3S_IMAGE" -db sqlite -ginkgo.v
94+
run-go-test ./tests/docker/conformance/conformance_test.go -k3sImage="$K3S_IMAGE" -db sqlite -ginkgo.v -ci
9595
echo "Did go conformance sqlite parallel $?"
96-
run-go-test ./test/docker/conformance/conformance_test.go -k3sImage="$K3S_IMAGE" -db etcd -ginkgo.v
96+
run-go-test ./tests/docker/conformance/conformance_test.go -k3sImage="$K3S_IMAGE" -db etcd -ginkgo.v -ci
9797
echo "Did go test conformance etcd parallel $?"
9898
test-run-sonobuoy mysql parallel
9999
echo "Did test-run-sonobuoy-mysql parallel $?"

tests/docker/basics/basics_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
)
1515

1616
var k3sImage = flag.String("k3sImage", "", "The image used to provision containers")
17+
var ci = flag.Bool("ci", false, "running on CI, forced cleanup")
1718
var config *tester.TestConfig
1819

1920
func Test_DockerBasic(t *testing.T) {
@@ -74,8 +75,8 @@ var _ = AfterEach(func() {
7475
})
7576

7677
var _ = AfterSuite(func() {
77-
if config != nil && !failed {
78-
config.Cleanup()
78+
if config != nil && (*ci || !failed) {
79+
Expect(config.Cleanup()).To(Succeed())
7980
}
8081
})
8182

tests/docker/bootstraptoken/bootstraptoken_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
)
1313

1414
var k3sImage = flag.String("k3sImage", "", "The k3s image used to provision containers")
15+
var ci = flag.Bool("ci", false, "running on CI, forced cleanup")
1516
var config *tester.TestConfig
1617

1718
func Test_DockerBootstrapToken(t *testing.T) {
@@ -62,7 +63,7 @@ var _ = AfterEach(func() {
6263
})
6364

6465
var _ = AfterSuite(func() {
65-
if config != nil && !failed {
66-
config.Cleanup()
66+
if config != nil && (*ci || !failed) {
67+
Expect(config.Cleanup()).To(Succeed())
6768
}
6869
})

tests/docker/cacerts/cacerts_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
)
1616

1717
var k3sImage = flag.String("k3sImage", "", "The k3s image used to provision containers")
18+
var ci = flag.Bool("ci", false, "running on CI, forced cleanup")
1819
var config *tester.TestConfig
1920
var testID string
2021

tests/docker/conformance/conformance_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
var k3sImage = flag.String("k3sImage", "", "The k3s image used to provision containers")
2121
var db = flag.String("db", "", "The database to use for the tests (sqlite, etcd, mysql, postgres)")
2222
var serial = flag.Bool("serial", false, "Run the Serial Conformance Tests")
23+
var ci = flag.Bool("ci", false, "running on CI, forced cleanup")
2324
var config *tester.TestConfig
2425

2526
func Test_DockerConformance(t *testing.T) {
@@ -123,8 +124,8 @@ var _ = AfterEach(func() {
123124
})
124125

125126
var _ = AfterSuite(func() {
126-
if config != nil && !failed {
127-
config.Cleanup()
127+
if config != nil && (*ci || !failed) {
128+
Expect(config.Cleanup()).To(Succeed())
128129
}
129130
})
130131

tests/docker/etcd/etcd_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
)
1313

1414
var k3sImage = flag.String("k3sImage", "", "The k3s image used to provision containers")
15+
var ci = flag.Bool("ci", false, "running on CI, forced cleanup")
1516
var config *tester.TestConfig
1617

1718
func Test_DockerEtcd(t *testing.T) {
@@ -72,7 +73,7 @@ var _ = AfterEach(func() {
7273
})
7374

7475
var _ = AfterSuite(func() {
75-
if config != nil && !failed {
76-
config.Cleanup()
76+
if config != nil && (*ci || !failed) {
77+
Expect(config.Cleanup()).To(Succeed())
7778
}
7879
})

tests/docker/lazypull/lazypull_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
)
1414

1515
var k3sImage = flag.String("k3sImage", "", "The k3s image used to provision containers")
16+
var ci = flag.Bool("ci", false, "running on CI, forced cleanup")
1617
var config *tester.TestConfig
1718

1819
func Test_DockerLazyPull(t *testing.T) {
@@ -71,8 +72,8 @@ var _ = AfterEach(func() {
7172
})
7273

7374
var _ = AfterSuite(func() {
74-
if config != nil && !failed {
75-
config.Cleanup()
75+
if config != nil && (*ci || !failed) {
76+
Expect(config.Cleanup()).To(Succeed())
7677
}
7778
})
7879

tests/docker/skew/skew_test.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
// the current commit build of K3s defined by <k3sImage>
1818
var k3sImage = flag.String("k3sImage", "", "The current commit build of K3s")
1919
var channel = flag.String("channel", "latest", "The release channel to test")
20+
var ci = flag.Bool("ci", false, "running on CI, forced cleanup")
2021
var config *tester.TestConfig
2122

2223
func Test_DockerSkew(t *testing.T) {
@@ -64,7 +65,7 @@ var _ = Describe("Skew Tests", Ordered, func() {
6465
Expect(config.ProvisionAgents(1)).To(Succeed())
6566
Eventually(func() error {
6667
return tests.CheckDeployments([]string{"coredns", "local-path-provisioner", "metrics-server", "traefik"}, config.KubeconfigFile)
67-
}, "60s", "5s").Should(Succeed())
68+
}, "180s", "5s").Should(Succeed())
6869
})
6970
It("should match respective versions", func() {
7071
for _, server := range config.Servers {
@@ -109,7 +110,7 @@ var _ = Describe("Skew Tests", Ordered, func() {
109110
Expect(config.ProvisionServers(3)).To(Succeed())
110111
Eventually(func() error {
111112
return tests.CheckDeployments([]string{"coredns", "local-path-provisioner", "metrics-server", "traefik"}, config.KubeconfigFile)
112-
}, "90s", "5s").Should(Succeed())
113+
}, "180s", "5s").Should(Succeed())
113114
Eventually(func(g Gomega) {
114115
g.Expect(tests.ParseNodes(config.KubeconfigFile)).To(HaveLen(3))
115116
g.Expect(tests.NodesReady(config.KubeconfigFile, config.GetNodeNames())).To(Succeed())
@@ -143,7 +144,7 @@ var _ = AfterEach(func() {
143144
})
144145

145146
var _ = AfterSuite(func() {
146-
if config != nil && !failed {
147-
config.Cleanup()
147+
if config != nil && (*ci || !failed) {
148+
Expect(config.Cleanup()).To(Succeed())
148149
}
149150
})

tests/docker/test-helpers.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ func (config *TestConfig) RemoveNode(nodeName string) error {
355355
if _, err := RunCommand(cmd); err != nil {
356356
return fmt.Errorf("failed to remove node %s: %v", nodeName, err)
357357
}
358+
fmt.Println("Stopped and removed", nodeName)
358359
return nil
359360
}
360361

@@ -379,13 +380,15 @@ func (config *TestConfig) Cleanup() error {
379380
errs = append(errs, err)
380381
}
381382
}
383+
config.Servers = nil
382384

383385
// Stop and remove all agents
384386
for _, agent := range config.Agents {
385387
if err := config.RemoveNode(agent.Name); err != nil {
386388
errs = append(errs, err)
387389
}
388390
}
391+
config.Agents = nil
389392

390393
// Stop DB if it was started
391394
if config.DBType == "mysql" || config.DBType == "postgres" {
@@ -407,8 +410,6 @@ func (config *TestConfig) Cleanup() error {
407410
if config.TestDir != "" {
408411
return os.RemoveAll(config.TestDir)
409412
}
410-
config.Agents = nil
411-
config.Servers = nil
412413
return nil
413414
}
414415

tests/docker/upgrade/upgrade_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
// the current commit build of K3s defined by <k3sImage>
2020
var k3sImage = flag.String("k3sImage", "", "The current commit build of K3s")
2121
var channel = flag.String("channel", "latest", "The release channel to test")
22+
var ci = flag.Bool("ci", false, "running on CI, forced cleanup")
2223
var config *tester.TestConfig
2324

2425
var numServers = 1
@@ -127,7 +128,7 @@ var _ = Describe("Upgrade Tests", Ordered, func() {
127128
cVersion = strings.Replace(cVersion, "-amd64", "", 1)
128129
cVersion = strings.Replace(cVersion, "-arm64", "", 1)
129130
cVersion = strings.Replace(cVersion, "-arm", "", 1)
130-
cVersion = strings.Replace(cVersion, "-", "+", 1)
131+
cVersion = strings.Replace(cVersion, "-k3s", "+k3s", 1)
131132
Expect(out).To(ContainSubstring(cVersion))
132133
}
133134
})
@@ -146,7 +147,7 @@ var _ = AfterEach(func() {
146147
})
147148

148149
var _ = AfterSuite(func() {
149-
if config != nil && !failed {
150-
config.Cleanup()
150+
if config != nil && (*ci || !failed) {
151+
Expect(config.Cleanup()).To(Succeed())
151152
}
152153
})

0 commit comments

Comments
 (0)