@@ -32,6 +32,7 @@ import (
32
32
. "github.com/onsi/gomega"
33
33
corev1 "k8s.io/api/core/v1"
34
34
apimachinerytypes "k8s.io/apimachinery/pkg/types"
35
+ "k8s.io/utils/ptr"
35
36
crclient "sigs.k8s.io/controller-runtime/pkg/client"
36
37
37
38
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
@@ -74,14 +75,19 @@ func getASGName(clusterName string) string {
74
75
}
75
76
76
77
func verifyClusterActiveAndOwned (eksClusterName string , sess client.ConfigProvider ) {
77
- cluster , err := getEKSCluster (eksClusterName , sess )
78
- Expect (err ).NotTo (HaveOccurred ())
78
+ var (
79
+ cluster * eks.Cluster
80
+ err error
81
+ )
82
+ Eventually (func () error {
83
+ cluster , err = getEKSCluster (eksClusterName , sess )
84
+ return err
85
+ }, 2 * time .Minute , 5 * time .Second ).Should (Succeed (), fmt .Sprintf ("eventually failed trying to get EKS Cluster %q" , eksClusterName ))
79
86
80
87
tagName := infrav1 .ClusterTagKey (eksClusterName )
81
88
tagValue , ok := cluster .Tags [tagName ]
82
89
Expect (ok ).To (BeTrue (), "expecting the cluster owned tag to exist" )
83
90
Expect (* tagValue ).To (BeEquivalentTo (string (infrav1 .ResourceLifecycleOwned )))
84
-
85
91
Expect (* cluster .Status ).To (BeEquivalentTo (eks .ClusterStatusActive ))
86
92
}
87
93
@@ -102,6 +108,7 @@ func getEKSClusterAddon(eksClusterName, addonName string, sess client.ConfigProv
102
108
AddonName : & addonName ,
103
109
ClusterName : & eksClusterName ,
104
110
}
111
+
105
112
describeOutput , err := eksClient .DescribeAddon (describeInput )
106
113
if err != nil {
107
114
return nil , fmt .Errorf ("describing eks addon %s: %w" , addonName , err )
@@ -112,16 +119,16 @@ func getEKSClusterAddon(eksClusterName, addonName string, sess client.ConfigProv
112
119
113
120
func verifySecretExists (ctx context.Context , secretName , namespace string , k8sclient crclient.Client ) {
114
121
secret := & corev1.Secret {}
115
- err := k8sclient . Get ( ctx , apimachinerytypes. NamespacedName { Name : secretName , Namespace : namespace }, secret )
116
-
117
- Expect ( err ). ShouldNot ( HaveOccurred ( ))
122
+ Eventually ( func () error {
123
+ return k8sclient . Get ( ctx , apimachinerytypes. NamespacedName { Name : secretName , Namespace : namespace }, secret )
124
+ }, 2 * time . Minute , 5 * time . Second ). Should ( Succeed (), fmt . Sprintf ( "eventually failed trying to verify Secret %q exists" , secretName ))
118
125
}
119
126
120
127
func verifyConfigMapExists (ctx context.Context , name , namespace string , k8sclient crclient.Client ) {
121
128
cm := & corev1.ConfigMap {}
122
129
Eventually (func () error {
123
130
return k8sclient .Get (ctx , apimachinerytypes.NamespacedName {Name : name , Namespace : namespace }, cm )
124
- }, 2 * time .Minute , 5 * time .Second ).Should (Succeed ())
131
+ }, 2 * time .Minute , 5 * time .Second ).Should (Succeed (), fmt . Sprintf ( "eventually failed trying to verify ConfigMap %q exists" , name ) )
125
132
}
126
133
127
134
func VerifyRoleExistsAndOwned (roleName string , eksClusterName string , checkOwned bool , sess client.ConfigProvider ) {
@@ -130,8 +137,15 @@ func VerifyRoleExistsAndOwned(roleName string, eksClusterName string, checkOwned
130
137
RoleName : aws .String (roleName ),
131
138
}
132
139
133
- output , err := iamClient .GetRole (input )
134
- Expect (err ).ShouldNot (HaveOccurred ())
140
+ var (
141
+ output * iam.GetRoleOutput
142
+ err error
143
+ )
144
+
145
+ Eventually (func () error {
146
+ output , err = iamClient .GetRole (input )
147
+ return err
148
+ }, 2 * time .Minute , 5 * time .Second ).Should (Succeed (), fmt .Sprintf ("eventually failed trying to get IAM Role %q" , roleName ))
135
149
136
150
if checkOwned {
137
151
found := false
@@ -152,9 +166,24 @@ func verifyManagedNodeGroup(eksClusterName, nodeGroupName string, checkOwned boo
152
166
ClusterName : aws .String (eksClusterName ),
153
167
NodegroupName : aws .String (nodeGroupName ),
154
168
}
155
- result , err := eksClient .DescribeNodegroup (input )
156
- Expect (err ).NotTo (HaveOccurred ())
157
- Expect (* result .Nodegroup .Status ).To (BeEquivalentTo (eks .NodegroupStatusActive ))
169
+ var (
170
+ result * eks.DescribeNodegroupOutput
171
+ err error
172
+ )
173
+
174
+ Eventually (func () error {
175
+ result , err = eksClient .DescribeNodegroup (input )
176
+ if err != nil {
177
+ return fmt .Errorf ("error describing nodegroup: %w" , err )
178
+ }
179
+
180
+ nodeGroupStatus := ptr .Deref (result .Nodegroup .Status , "" )
181
+ if nodeGroupStatus != eks .NodegroupStatusActive {
182
+ return fmt .Errorf ("expected nodegroup.Status to be %q, was %q instead" , eks .NodegroupStatusActive , nodeGroupStatus )
183
+ }
184
+
185
+ return nil
186
+ }, 2 * time .Minute , 5 * time .Second ).Should (Succeed (), "eventually failed trying to describe EKS Node group" )
158
187
159
188
if checkOwned {
160
189
tagName := infrav1 .ClusterAWSCloudProviderTagKey (eksClusterName )
@@ -172,8 +201,16 @@ func verifyASG(eksClusterName, asgName string, checkOwned bool, sess client.Conf
172
201
},
173
202
}
174
203
175
- result , err := asgClient .DescribeAutoScalingGroups (input )
176
- Expect (err ).NotTo (HaveOccurred ())
204
+ var (
205
+ result * autoscaling.DescribeAutoScalingGroupsOutput
206
+ err error
207
+ )
208
+
209
+ Eventually (func () error {
210
+ result , err = asgClient .DescribeAutoScalingGroups (input )
211
+ return err
212
+ }, 2 * time .Minute , 5 * time .Second ).Should (Succeed ())
213
+
177
214
for _ , instance := range result .AutoScalingGroups [0 ].Instances {
178
215
Expect (* instance .LifecycleState ).To (Equal ("InService" ), "expecting the instance in service" )
179
216
}
0 commit comments