@@ -26,10 +26,66 @@ import (
26
26
"sigs.k8s.io/e2e-framework/pkg/envconf"
27
27
"sigs.k8s.io/e2e-framework/pkg/features"
28
28
29
+ ecv1alpha1 "go.etcd.io/etcd-operator/api/v1alpha1"
29
30
appsv1 "k8s.io/api/apps/v1"
30
31
corev1 "k8s.io/api/core/v1"
32
+ "k8s.io/apimachinery/pkg/api/errors"
33
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
31
34
)
32
35
36
+ // An Etcd cluster with zero member should not create its StatefulSet counterpart
37
+ func TestZeroMemberCluster (t * testing.T ) {
38
+ feature := features .New ("zero-member-cluster" )
39
+ etcdClusterName := "etcd-cluster-zero"
40
+ size := 0
41
+
42
+ etcdClusterSpec := & ecv1alpha1.EtcdCluster {
43
+ TypeMeta : metav1.TypeMeta {
44
+ APIVersion : "operator.etcd.io/v1alpha1" ,
45
+ Kind : "EtcdCluster" ,
46
+ },
47
+ ObjectMeta : metav1.ObjectMeta {
48
+ Name : etcdClusterName ,
49
+ Namespace : namespace ,
50
+ },
51
+ Spec : ecv1alpha1.EtcdClusterSpec {
52
+ Size : size ,
53
+ Version : "v3.5.18" ,
54
+ },
55
+ }
56
+
57
+ feature .Setup (func (ctx context.Context , t * testing.T , c * envconf.Config ) context.Context {
58
+
59
+ if err := c .Client ().Resources ().Create (ctx , etcdClusterSpec ); err != nil {
60
+ t .Fatalf ("fail to create Etcd cluster: %s" , err )
61
+ }
62
+
63
+ return ctx
64
+ })
65
+
66
+ feature .Assess ("statefulSet is not created when etcdCluster.Spec.Size is 0" ,
67
+ func (ctx context.Context , t * testing.T , c * envconf.Config ) context.Context {
68
+
69
+ var etcdCluster ecv1alpha1.EtcdCluster
70
+ if err := c .Client ().Resources ().Get (ctx , etcdClusterName , namespace , & etcdCluster ); err != nil {
71
+ t .Fatalf ("unable to fetch Etcd cluster: %s" , err )
72
+ }
73
+
74
+ var sts appsv1.StatefulSet
75
+ err := c .Client ().Resources ().Get (ctx , etcdClusterName , namespace , & sts )
76
+
77
+ if ! errors .IsNotFound (err ) {
78
+ t .Fatalf ("statefulSet found when Etcd Cluster size is zero: %s" , err )
79
+ }
80
+
81
+ return ctx
82
+ },
83
+ )
84
+
85
+ _ = testEnv .Test (t , feature .Feature ())
86
+
87
+ }
88
+
33
89
func TestClusterHealthy (t * testing.T ) {
34
90
feature := features .New ("etcd-operator-controller" )
35
91
0 commit comments