mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/kube-vip/kube-vip.git
synced 2026-09-20 08:03:47 +08:00
fix(e2e): guard etcd suite teardown after setup failure
Register the cluster handle before setup assertions so partial Kind creation can be cleaned up, while keeping teardown safe when setup fails before registration. Signed-off-by: Maximilian Rink <maximilian.rink@telekom.de>
This commit is contained in:
committed by
Marcel Fest
parent
2bc2df53fc
commit
6ee3024bc6
23
testing/e2e/etcd/cleanup_test.go
Normal file
23
testing/e2e/etcd/cleanup_test.go
Normal file
@@ -0,0 +1,23 @@
|
||||
//go:build e2e
|
||||
// +build e2e
|
||||
|
||||
package etcd_test
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
func TestCleanupWithoutCluster(t *testing.T) {
|
||||
RegisterTestingT(t)
|
||||
t.Setenv("E2E_PRESERVE_CLUSTER", "false")
|
||||
|
||||
test := &testConfig{
|
||||
kubeVipManifestPath: filepath.Join(t.TempDir(), "missing-manifest"),
|
||||
etcdCertsFolder: filepath.Join(t.TempDir(), "missing-certs"),
|
||||
}
|
||||
|
||||
test.cleanup()
|
||||
}
|
||||
@@ -40,24 +40,25 @@ type Cluster struct {
|
||||
provider *cluster.Provider
|
||||
}
|
||||
|
||||
func CreateCluster(ctx context.Context, spec *ClusterSpec) *Cluster {
|
||||
c := &Cluster{
|
||||
func NewCluster(spec *ClusterSpec) *Cluster {
|
||||
return &Cluster{
|
||||
ClusterSpec: spec,
|
||||
provider: cluster.NewProvider(
|
||||
cluster.ProviderWithLogger(spec.Logger),
|
||||
cluster.ProviderWithDocker(),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
c.provider = cluster.NewProvider(
|
||||
cluster.ProviderWithLogger(spec.Logger),
|
||||
cluster.ProviderWithDocker(),
|
||||
)
|
||||
|
||||
func (c *Cluster) Create(ctx context.Context) {
|
||||
c.Logger.Printf("Creating kind nodes")
|
||||
c.initKindCluster()
|
||||
|
||||
c.Logger.Printf("Loading kube-vip image into nodes")
|
||||
Expect(e2e.LoadDockerImageToKind(spec.Logger, spec.KubeVIPImage, spec.Name)).To(Succeed())
|
||||
Expect(e2e.LoadDockerImageToKind(c.Logger, c.KubeVIPImage, c.Name)).To(Succeed())
|
||||
|
||||
c.Logger.Printf("Loading traefik image into nodes")
|
||||
if err := e2e.LoadDockerImageToKind(spec.Logger, "ghcr.io/traefik/whoami:v1.11", spec.Name); err != nil {
|
||||
if err := e2e.LoadDockerImageToKind(c.Logger, "ghcr.io/traefik/whoami:v1.11", c.Name); err != nil {
|
||||
c.Logger.Warnf("failed to load image ghcr.io/traefik/whoami:v1.11 into kind cluster, image will be downloaded after pod deployment, error: %s", err.Error())
|
||||
}
|
||||
|
||||
@@ -77,8 +78,6 @@ func CreateCluster(ctx context.Context, spec *ClusterSpec) *Cluster {
|
||||
|
||||
c.Logger.Printf("Checking %d nodes etcd is available through VIP", c.ClusterSpec.Nodes)
|
||||
c.VerifyEtcdThroughVIP(ctx, 15*time.Second)
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Cluster) initKindCluster() {
|
||||
|
||||
@@ -36,7 +36,9 @@ func (t *testConfig) cleanup() {
|
||||
return
|
||||
}
|
||||
|
||||
t.cluster.Delete()
|
||||
if t.cluster != nil {
|
||||
t.cluster.Delete()
|
||||
}
|
||||
Expect(os.RemoveAll(t.kubeVipManifestPath)).To(Succeed())
|
||||
Expect(os.RemoveAll(t.etcdCertsFolder)).To(Succeed())
|
||||
}
|
||||
@@ -99,7 +101,8 @@ var _ = Describe("kube-vip with etcd leader election", func() {
|
||||
Logger: test.logger,
|
||||
}
|
||||
|
||||
test.cluster = etcd.CreateCluster(ctx, spec)
|
||||
test.cluster = etcd.NewCluster(spec)
|
||||
test.cluster.Create(ctx)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user