@@ -18,6 +18,7 @@ import (
18
18
"errors"
19
19
"fmt"
20
20
"strings"
21
+ "time"
21
22
22
23
svcapitypes "github.com/aws-controllers-k8s/kafka-controller/apis/v1alpha1"
23
24
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare"
38
39
string (svcsdktypes .ClusterStateDeleting ),
39
40
string (svcsdktypes .ClusterStateFailed ),
40
41
}
42
+ RequeueAfterUpdateDuration = 15 * time .Second
41
43
)
42
44
43
45
var (
@@ -113,6 +115,18 @@ func clusterDeleting(r *resource) bool {
113
115
return cs == strings .ToLower (string (svcsdktypes .ClusterStateDeleting ))
114
116
}
115
117
118
+ // requeueAfterAsyncUpdate returns a `ackrequeue.RequeueNeededAfter` struct
119
+ // explaining the cluster cannot be modified until after the asynchronous update
120
+ // has (first, started and then) completed and the cluster reaches an active
121
+ // status.
122
+ func requeueAfterAsyncUpdate () * ackrequeue.RequeueNeededAfter {
123
+ return ackrequeue .NeededAfter (
124
+ fmt .Errorf ("cluster has started asynchronously updating, cannot be modified until '%s'" ,
125
+ "Active" ),
126
+ RequeueAfterUpdateDuration ,
127
+ )
128
+ }
129
+
116
130
func (rm * resourceManager ) customUpdate (
117
131
ctx context.Context ,
118
132
desired * resource ,
@@ -133,12 +147,6 @@ func (rm *resourceManager) customUpdate(
133
147
// Copy status from latest since it has the current cluster state
134
148
updatedRes .ko .Status = latest .ko .Status
135
149
136
- if clusterDeleting (latest ) {
137
- msg := "Cluster is currently being deleted"
138
- ackcondition .SetSynced (updatedRes , corev1 .ConditionFalse , & msg , nil )
139
- return updatedRes , requeueWaitWhileDeleting
140
- }
141
-
142
150
if ! clusterActive (latest ) {
143
151
msg := "Cluster is in '" + * latest .ko .Status .State + "' state"
144
152
ackcondition .SetSynced (updatedRes , corev1 .ConditionFalse , & msg , nil )
@@ -149,16 +157,120 @@ func (rm *resourceManager) customUpdate(
149
157
return updatedRes , requeueWaitUntilCanModify (latest )
150
158
}
151
159
152
- if delta .DifferentAt ("Spec.AssociatedSCRAMSecrets" ) {
160
+ switch {
161
+ case delta .DifferentAt ("Spec.ClientAuthentication" ):
162
+ input := & svcsdk.UpdateSecurityInput {}
163
+ if desired .ko .Status .CurrentVersion != nil {
164
+ input .CurrentVersion = desired .ko .Status .CurrentVersion
165
+ }
166
+ if desired .ko .Status .ACKResourceMetadata .ARN != nil {
167
+ input .ClusterArn = (* string )(desired .ko .Status .ACKResourceMetadata .ARN )
168
+ }
169
+ if desired .ko .Spec .ClientAuthentication != nil {
170
+ f0 := & svcsdktypes.ClientAuthentication {}
171
+ if desired .ko .Spec .ClientAuthentication .SASL != nil {
172
+ f0f0 := & svcsdktypes.Sasl {}
173
+ if desired .ko .Spec .ClientAuthentication .SASL .IAM != nil &&
174
+ desired .ko .Spec .ClientAuthentication .SASL .IAM .Enabled != nil {
175
+ f0f0f0 := & svcsdktypes.Iam {
176
+ Enabled : desired .ko .Spec .ClientAuthentication .SASL .IAM .Enabled ,
177
+ }
178
+ f0f0 .Iam = f0f0f0
179
+ }
180
+ if desired .ko .Spec .ClientAuthentication .SASL .SCRAM != nil &&
181
+ desired .ko .Spec .ClientAuthentication .SASL .SCRAM .Enabled != nil {
182
+ f0f0f1 := & svcsdktypes.Scram {
183
+ Enabled : desired .ko .Spec .ClientAuthentication .SASL .SCRAM .Enabled ,
184
+ }
185
+ f0f0 .Scram = f0f0f1
186
+ }
187
+ f0 .Sasl = f0f0
188
+ }
189
+ if desired .ko .Spec .ClientAuthentication .TLS != nil {
190
+ f0f1 := & svcsdktypes.Tls {}
191
+ if desired .ko .Spec .ClientAuthentication .TLS .CertificateAuthorityARNList != nil {
192
+ f0f1 .CertificateAuthorityArnList = aws .ToStringSlice (desired .ko .Spec .ClientAuthentication .TLS .CertificateAuthorityARNList )
193
+ }
194
+ if desired .ko .Spec .ClientAuthentication .TLS .Enabled != nil {
195
+ f0f1 .Enabled = desired .ko .Spec .ClientAuthentication .TLS .Enabled
196
+ }
197
+ f0 .Tls = f0f1
198
+ }
199
+ if desired .ko .Spec .ClientAuthentication .Unauthenticated != nil &&
200
+ desired .ko .Spec .ClientAuthentication .Unauthenticated .Enabled != nil {
201
+ f0 .Unauthenticated = & svcsdktypes.Unauthenticated {
202
+ Enabled : desired .ko .Spec .ClientAuthentication .Unauthenticated .Enabled ,
203
+ }
204
+ }
205
+ input .ClientAuthentication = f0
206
+ }
207
+
208
+ _ , err = rm .sdkapi .UpdateSecurity (ctx , input )
209
+ rm .metrics .RecordAPICall ("UPDATE" , "UpdateSecurity" , err )
210
+ if err != nil {
211
+ return nil , err
212
+ }
213
+ ackcondition .SetSynced (updatedRes , corev1 .ConditionFalse , nil , nil )
214
+ err = requeueAfterAsyncUpdate ()
215
+
216
+ case delta .DifferentAt ("Spec.AssociatedSCRAMSecrets" ):
153
217
err = rm .syncAssociatedScramSecrets (ctx , updatedRes , latest )
154
218
if err != nil {
155
219
return nil , err
156
220
}
221
+ // Set synced condition to True after successful update
222
+ ackcondition .SetSynced (updatedRes , corev1 .ConditionFalse , nil , nil )
223
+
224
+ case delta .DifferentAt ("Spec.BrokerNodeGroupInfo.StorageInfo.EBSStorageInfo.VolumeSize" ):
225
+ _ , err := rm .sdkapi .UpdateBrokerStorage (ctx , & svcsdk.UpdateBrokerStorageInput {
226
+ ClusterArn : (* string )(latest .ko .Status .ACKResourceMetadata .ARN ),
227
+ CurrentVersion : latest .ko .Status .CurrentVersion ,
228
+ TargetBrokerEBSVolumeInfo : []svcsdktypes.BrokerEBSVolumeInfo {
229
+ {
230
+ KafkaBrokerNodeId : aws .String ("ALL" ),
231
+ VolumeSizeGB : aws .Int32 (int32 (* desired .ko .Spec .BrokerNodeGroupInfo .StorageInfo .EBSStorageInfo .VolumeSize )),
232
+ },
233
+ },
234
+ })
235
+ rm .metrics .RecordAPICall ("UPDATE" , "UpdateBrokerStorage" , err )
236
+ if err != nil {
237
+ return nil , err
238
+ }
239
+ message := fmt .Sprintf ("kafka is updating broker storage" )
240
+ ackcondition .SetSynced (updatedRes , corev1 .ConditionFalse , & message , nil )
241
+ err = requeueAfterAsyncUpdate ()
242
+
243
+ case delta .DifferentAt ("Spec.BrokerNodeGroupInfo.InstanceType" ):
244
+ _ , err := rm .sdkapi .UpdateBrokerType (ctx , & svcsdk.UpdateBrokerTypeInput {
245
+ ClusterArn : (* string )(latest .ko .Status .ACKResourceMetadata .ARN ),
246
+ CurrentVersion : latest .ko .Status .CurrentVersion ,
247
+ TargetInstanceType : desired .ko .Spec .BrokerNodeGroupInfo .InstanceType ,
248
+ })
249
+ rm .metrics .RecordAPICall ("UPDATE" , "UpdateBrokerType" , err )
250
+ if err != nil {
251
+ return nil , err
252
+ }
253
+ message := fmt .Sprintf ("kafka is updating broker instanceType" )
254
+ ackcondition .SetSynced (updatedRes , corev1 .ConditionFalse , & message , nil )
255
+ err = requeueAfterAsyncUpdate ()
256
+
257
+ case delta .DifferentAt ("Spec.NumberOfBrokerNodes" ):
258
+ _ , err := rm .sdkapi .UpdateBrokerCount (ctx , & svcsdk.UpdateBrokerCountInput {
259
+ ClusterArn : (* string )(latest .ko .Status .ACKResourceMetadata .ARN ),
260
+ CurrentVersion : latest .ko .Status .CurrentVersion ,
261
+ TargetNumberOfBrokerNodes : aws .Int32 (int32 (* desired .ko .Spec .NumberOfBrokerNodes )),
262
+ })
263
+ rm .metrics .RecordAPICall ("UPDATE" , "UpdateBrokerCount" , err )
264
+ if err != nil {
265
+ return nil , err
266
+ }
267
+ message := fmt .Sprintf ("kafka is updating broker instanceType" )
268
+ ackcondition .SetSynced (updatedRes , corev1 .ConditionFalse , & message , nil )
269
+ err = requeueAfterAsyncUpdate ()
270
+
157
271
}
158
272
159
- // Set synced condition to True after successful update
160
- ackcondition .SetSynced (updatedRes , corev1 .ConditionTrue , nil , nil )
161
- return updatedRes , nil
273
+ return updatedRes , err
162
274
}
163
275
164
276
// syncAssociatedScramSecrets examines the Secret ARNs in the supplied Cluster
0 commit comments