@@ -54,31 +54,51 @@ var _ = Describe("CreateOrUpdateClusterStateConfigMap handlers", func() {
54
54
55
55
It ("should successfully ensure the configmap" , func () {
56
56
cm := & corev1.ConfigMap {}
57
-
58
- By ("creating the configmap for initial cluster" )
59
- err := CreateOrUpdateClusterStateConfigMap (ctx , etcdcluster , k8sClient , k8sClient .Scheme ())
60
- Expect (err ).NotTo (HaveOccurred ())
61
-
62
- err = k8sClient .Get (ctx , typeNamespacedName , cm )
63
- cmUid := cm .UID
64
- Expect (err ).NotTo (HaveOccurred ())
65
- Expect (cm .Data ["ETCD_INITIAL_CLUSTER_STATE" ]).To (Equal ("new" ))
66
-
67
- By ("updating the configmap for initialized cluster" )
68
- SetCondition (etcdcluster , NewCondition (etcdaenixiov1alpha1 .EtcdConditionReady ).
69
- WithStatus (true ).Complete ())
70
- err = CreateOrUpdateClusterStateConfigMap (ctx , etcdcluster , k8sClient , k8sClient .Scheme ())
71
- Expect (err ).NotTo (HaveOccurred ())
72
-
73
- err = k8sClient .Get (ctx , typeNamespacedName , cm )
74
- Expect (err ).NotTo (HaveOccurred ())
75
- Expect (cm .Data ["ETCD_INITIAL_CLUSTER_STATE" ]).To (Equal ("existing" ))
76
- // Check that we are updating the same configmap
77
- Expect (cm .UID ).To (Equal (cmUid ))
78
-
79
- By ("deleting the configmap" )
80
-
81
- Expect (k8sClient .Delete (ctx , cm )).To (Succeed ())
57
+ var err error
58
+ var cmUid types.UID
59
+ By ("creating the configmap for initial cluster" , func () {
60
+ err = CreateOrUpdateClusterStateConfigMap (ctx , etcdcluster , k8sClient , k8sClient .Scheme ())
61
+ Expect (err ).NotTo (HaveOccurred ())
62
+
63
+ err = k8sClient .Get (ctx , typeNamespacedName , cm )
64
+ cmUid = cm .UID
65
+ Expect (err ).NotTo (HaveOccurred ())
66
+ Expect (cm .Data ["ETCD_INITIAL_CLUSTER_STATE" ]).To (Equal ("new" ))
67
+ })
68
+
69
+ By ("updating the configmap for initialized cluster" , func () {
70
+ SetCondition (etcdcluster , NewCondition (etcdaenixiov1alpha1 .EtcdConditionReady ).
71
+ WithReason (string (etcdaenixiov1alpha1 .EtcdCondTypeStatefulSetReady )).
72
+ WithStatus (true ).
73
+ Complete ())
74
+ err = CreateOrUpdateClusterStateConfigMap (ctx , etcdcluster , k8sClient , k8sClient .Scheme ())
75
+ Expect (err ).NotTo (HaveOccurred ())
76
+
77
+ err = k8sClient .Get (ctx , typeNamespacedName , cm )
78
+ Expect (err ).NotTo (HaveOccurred ())
79
+ Expect (cm .Data ["ETCD_INITIAL_CLUSTER_STATE" ]).To (Equal ("existing" ))
80
+ // Check that we are updating the same configmap
81
+ Expect (cm .UID ).To (Equal (cmUid ))
82
+ })
83
+
84
+ By ("updating the configmap back to new" , func () {
85
+ SetCondition (etcdcluster , NewCondition (etcdaenixiov1alpha1 .EtcdConditionReady ).
86
+ WithReason (string (etcdaenixiov1alpha1 .EtcdCondTypeWaitingForFirstQuorum )).
87
+ WithStatus (true ).
88
+ Complete ())
89
+ err = CreateOrUpdateClusterStateConfigMap (ctx , etcdcluster , k8sClient , k8sClient .Scheme ())
90
+ Expect (err ).NotTo (HaveOccurred ())
91
+
92
+ err = k8sClient .Get (ctx , typeNamespacedName , cm )
93
+ Expect (err ).NotTo (HaveOccurred ())
94
+ Expect (cm .Data ["ETCD_INITIAL_CLUSTER_STATE" ]).To (Equal ("new" ))
95
+ // Check that we are updating the same configmap
96
+ Expect (cm .UID ).To (Equal (cmUid ))
97
+ })
98
+
99
+ By ("deleting the configmap" , func () {
100
+ Expect (k8sClient .Delete (ctx , cm )).To (Succeed ())
101
+ })
82
102
})
83
103
84
104
It ("should fail on creating the configMap with invalid owner reference" , func () {
0 commit comments