@@ -16,6 +16,7 @@ package domain
16
16
import (
17
17
"context"
18
18
"errors"
19
+ "fmt"
19
20
20
21
"github.com/aws-controllers-k8s/opensearchservice-controller/apis/v1alpha1"
21
22
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
@@ -46,21 +47,44 @@ func domainProcessing(r *resource) bool {
46
47
return * r .ko .Status .Processing
47
48
}
48
49
50
+ func isAutoTuneOptionReady (state string , errorMessage * string ) (bool , error ) {
51
+ switch svcsdktypes .AutoTuneState (state ) {
52
+ case svcsdktypes .AutoTuneStateEnabled , svcsdktypes .AutoTuneStateDisabled :
53
+ return true , nil
54
+
55
+ case svcsdktypes .AutoTuneStateError :
56
+ if errorMessage != nil {
57
+ return false , fmt .Errorf ("error: %s" , * errorMessage )
58
+ }
59
+ return false , fmt .Errorf ("there is an error when updating AutoTuneOptions" )
60
+
61
+ default :
62
+ return false , nil
63
+ }
64
+ }
65
+
49
66
func (rm * resourceManager ) customUpdateDomain (ctx context.Context , desired , latest * resource ,
50
67
delta * ackcompare.Delta ) (updated * resource , err error ) {
51
68
rlog := ackrtlog .FromContext (ctx )
52
69
exit := rlog .Trace ("rm.customUpdateDomain" )
53
70
defer exit (err )
54
71
72
+ if latest .ko .Spec .AutoTuneOptions != nil &&
73
+ latest .ko .Spec .AutoTuneOptions .DesiredState != nil {
74
+ if ready , _ := isAutoTuneOptionReady (* latest .ko .Spec .AutoTuneOptions .DesiredState , nil ); ! ready {
75
+ return latest , ackrequeue .Needed (fmt .Errorf ("autoTuneOption is updating" ))
76
+ }
77
+ }
78
+
55
79
if domainProcessing (latest ) {
56
80
msg := "Domain is currently processing configuration changes"
57
81
ackcondition .SetSynced (desired , corev1 .ConditionFalse , & msg , nil )
58
- return desired , requeueWaitWhileProcessing
82
+ return latest , requeueWaitWhileProcessing
59
83
}
60
84
if latest .ko .Status .UpgradeProcessing != nil && * latest .ko .Status .UpgradeProcessing {
61
85
msg := "Domain is currently upgrading software"
62
86
ackcondition .SetSynced (desired , corev1 .ConditionFalse , & msg , nil )
63
- return desired , requeueWaitWhileProcessing
87
+ return latest , requeueWaitWhileProcessing
64
88
}
65
89
66
90
if desired .ko .Spec .EngineVersion != nil && delta .DifferentAt ("Spec.EngineVersion" ) {
@@ -185,6 +209,7 @@ func (rm *resourceManager) customUpdateDomain(ctx context.Context, desired, late
185
209
}
186
210
ko .Spec .AutoTuneOptions = & v1alpha1.AutoTuneOptionsInput {
187
211
DesiredState : aws .String (string (resp .DomainConfig .AutoTuneOptions .Options .DesiredState )),
212
+ UseOffPeakWindow : resp .DomainConfig .AutoTuneOptions .Options .UseOffPeakWindow ,
188
213
MaintenanceSchedules : maintSchedules ,
189
214
}
190
215
} else {
@@ -205,11 +230,15 @@ func (rm *resourceManager) customUpdateDomain(ctx context.Context, desired, late
205
230
}
206
231
}
207
232
ko .Spec .ClusterConfig = & v1alpha1.ClusterConfig {
208
- ColdStorageOptions : csOptions ,
209
- DedicatedMasterEnabled : resp .DomainConfig .ClusterConfig .Options .DedicatedMasterEnabled ,
210
- WarmEnabled : resp .DomainConfig .ClusterConfig .Options .WarmEnabled ,
211
- ZoneAwarenessConfig : zaConfig ,
212
- ZoneAwarenessEnabled : resp .DomainConfig .ClusterConfig .Options .ZoneAwarenessEnabled ,
233
+ ColdStorageOptions : csOptions ,
234
+ DedicatedMasterCount : int64OrNil (resp .DomainConfig .ClusterConfig .Options .DedicatedMasterCount ),
235
+ DedicatedMasterEnabled : resp .DomainConfig .ClusterConfig .Options .DedicatedMasterEnabled ,
236
+ InstanceCount : int64OrNil (resp .DomainConfig .ClusterConfig .Options .InstanceCount ),
237
+ WarmCount : int64OrNil (resp .DomainConfig .ClusterConfig .Options .WarmCount ),
238
+ WarmEnabled : resp .DomainConfig .ClusterConfig .Options .WarmEnabled ,
239
+ ZoneAwarenessConfig : zaConfig ,
240
+ ZoneAwarenessEnabled : resp .DomainConfig .ClusterConfig .Options .ZoneAwarenessEnabled ,
241
+ MultiAZWithStandbyEnabled : resp .DomainConfig .ClusterConfig .Options .MultiAZWithStandbyEnabled ,
213
242
}
214
243
if resp .DomainConfig .ClusterConfig .Options .DedicatedMasterCount != nil {
215
244
ko .Spec .ClusterConfig .DedicatedMasterCount = aws .Int64 (int64 (* resp .DomainConfig .ClusterConfig .Options .DedicatedMasterCount ))
@@ -285,13 +314,53 @@ func (rm *resourceManager) customUpdateDomain(ctx context.Context, desired, late
285
314
} else {
286
315
ko .Spec .EngineVersion = nil
287
316
}
317
+ if resp .DomainConfig .IPAddressType != nil {
318
+ ko .Spec .IPAddressType = aws .String (string (resp .DomainConfig .IPAddressType .Options ))
319
+ } else {
320
+ ko .Spec .IPAddressType = nil
321
+ }
288
322
if resp .DomainConfig .NodeToNodeEncryptionOptions != nil {
289
323
ko .Spec .NodeToNodeEncryptionOptions = & v1alpha1.NodeToNodeEncryptionOptions {
290
324
Enabled : resp .DomainConfig .NodeToNodeEncryptionOptions .Options .Enabled ,
291
325
}
292
326
} else {
293
327
ko .Spec .NodeToNodeEncryptionOptions = nil
294
328
}
329
+ if resp .DomainConfig .SoftwareUpdateOptions != nil {
330
+ ko .Spec .SoftwareUpdateOptions = & v1alpha1.SoftwareUpdateOptions {
331
+ AutoSoftwareUpdateEnabled : resp .DomainConfig .SoftwareUpdateOptions .Options .AutoSoftwareUpdateEnabled ,
332
+ }
333
+ } else {
334
+ ko .Spec .SoftwareUpdateOptions = nil
335
+ }
336
+ if resp .DomainConfig .AIMLOptions != nil && resp .DomainConfig .AIMLOptions .Options != nil {
337
+ if resp .DomainConfig .AIMLOptions .Options .NaturalLanguageQueryGenerationOptions != nil {
338
+ ko .Spec .AIMLOptions = & v1alpha1.AIMLOptionsInput {
339
+ NATuralLanguageQueryGenerationOptions : & v1alpha1.NATuralLanguageQueryGenerationOptionsInput {
340
+ DesiredState : aws .String (string (resp .DomainConfig .AIMLOptions .Options .NaturalLanguageQueryGenerationOptions .DesiredState )),
341
+ },
342
+ }
343
+ }
344
+ } else {
345
+ ko .Spec .AIMLOptions = nil
346
+ }
347
+ if resp .DomainConfig .OffPeakWindowOptions != nil && resp .DomainConfig .OffPeakWindowOptions .Options != nil {
348
+ var offPeakWindow * v1alpha1.OffPeakWindow
349
+ if resp .DomainConfig .OffPeakWindowOptions .Options .OffPeakWindow != nil {
350
+ offPeakWindow = & v1alpha1.OffPeakWindow {
351
+ WindowStartTime : & v1alpha1.WindowStartTime {
352
+ Hours : aws .Int64 (resp .DomainConfig .OffPeakWindowOptions .Options .OffPeakWindow .WindowStartTime .Hours ),
353
+ Minutes : aws .Int64 (resp .DomainConfig .OffPeakWindowOptions .Options .OffPeakWindow .WindowStartTime .Minutes ),
354
+ },
355
+ }
356
+ }
357
+ ko .Spec .OffPeakWindowOptions = & v1alpha1.OffPeakWindowOptions {
358
+ Enabled : resp .DomainConfig .OffPeakWindowOptions .Options .Enabled ,
359
+ OffPeakWindow : offPeakWindow ,
360
+ }
361
+ } else {
362
+ ko .Spec .OffPeakWindowOptions = nil
363
+ }
295
364
296
365
rm .setStatusDefaults (ko )
297
366
@@ -401,6 +470,9 @@ func (rm *resourceManager) newCustomUpdateRequestPayload(
401
470
if desired .ko .Spec .AutoTuneOptions .DesiredState != nil {
402
471
f3 .DesiredState = svcsdktypes .AutoTuneDesiredState (* desired .ko .Spec .AutoTuneOptions .DesiredState )
403
472
}
473
+ if desired .ko .Spec .AutoTuneOptions .UseOffPeakWindow != nil {
474
+ f3 .UseOffPeakWindow = desired .ko .Spec .AutoTuneOptions .UseOffPeakWindow
475
+ }
404
476
if desired .ko .Spec .AutoTuneOptions .MaintenanceSchedules != nil {
405
477
f3f1 := []svcsdktypes.AutoTuneMaintenanceSchedule {}
406
478
for _ , f3f1iter := range desired .ko .Spec .AutoTuneOptions .MaintenanceSchedules {
@@ -471,6 +543,9 @@ func (rm *resourceManager) newCustomUpdateRequestPayload(
471
543
if desired .ko .Spec .ClusterConfig .ZoneAwarenessEnabled != nil {
472
544
f4 .ZoneAwarenessEnabled = desired .ko .Spec .ClusterConfig .ZoneAwarenessEnabled
473
545
}
546
+ if desired .ko .Spec .ClusterConfig .MultiAZWithStandbyEnabled != nil {
547
+ f4 .MultiAZWithStandbyEnabled = desired .ko .Spec .ClusterConfig .MultiAZWithStandbyEnabled
548
+ }
474
549
res .ClusterConfig = f4
475
550
}
476
551
@@ -586,5 +661,59 @@ func (rm *resourceManager) newCustomUpdateRequestPayload(
586
661
res .VPCOptions = f14
587
662
}
588
663
664
+ if desired .ko .Spec .IPAddressType != nil && delta .DifferentAt ("Spec.IPAddressType" ) {
665
+ res .IPAddressType = svcsdktypes .IPAddressType (* desired .ko .Spec .IPAddressType )
666
+ }
667
+
668
+ if desired .ko .Spec .SoftwareUpdateOptions != nil && delta .DifferentAt ("Spec.SoftwareUpdateOptions" ) {
669
+ f15 := & svcsdktypes.SoftwareUpdateOptions {}
670
+ if desired .ko .Spec .SoftwareUpdateOptions .AutoSoftwareUpdateEnabled != nil {
671
+ f15 .AutoSoftwareUpdateEnabled = desired .ko .Spec .SoftwareUpdateOptions .AutoSoftwareUpdateEnabled
672
+ }
673
+ res .SoftwareUpdateOptions = f15
674
+ }
675
+
676
+ if desired .ko .Spec .AIMLOptions != nil && delta .DifferentAt ("Spec.AIMLOptions" ) {
677
+ f16 := & svcsdktypes.AIMLOptionsInput {}
678
+ if desired .ko .Spec .AIMLOptions .NATuralLanguageQueryGenerationOptions != nil {
679
+ f16f0 := & svcsdktypes.NaturalLanguageQueryGenerationOptionsInput {}
680
+ if desired .ko .Spec .AIMLOptions .NATuralLanguageQueryGenerationOptions .DesiredState != nil {
681
+ f16f0 .DesiredState = svcsdktypes .NaturalLanguageQueryGenerationDesiredState (* desired .ko .Spec .AIMLOptions .NATuralLanguageQueryGenerationOptions .DesiredState )
682
+ }
683
+ f16 .NaturalLanguageQueryGenerationOptions = f16f0
684
+ }
685
+ res .AIMLOptions = f16
686
+ }
687
+
688
+ if desired .ko .Spec .OffPeakWindowOptions != nil && delta .DifferentAt ("Spec.OffPeakWindowOptions" ) {
689
+ f17 := & svcsdktypes.OffPeakWindowOptions {}
690
+ if desired .ko .Spec .OffPeakWindowOptions .Enabled != nil {
691
+ f17 .Enabled = desired .ko .Spec .OffPeakWindowOptions .Enabled
692
+ }
693
+ if desired .ko .Spec .OffPeakWindowOptions .OffPeakWindow != nil {
694
+ f17f1 := & svcsdktypes.OffPeakWindow {}
695
+ if desired .ko .Spec .OffPeakWindowOptions .OffPeakWindow .WindowStartTime != nil {
696
+ f17f1f1 := & svcsdktypes.WindowStartTime {}
697
+ if desired .ko .Spec .OffPeakWindowOptions .OffPeakWindow .WindowStartTime .Hours != nil {
698
+ f17f1f1 .Hours = * desired .ko .Spec .OffPeakWindowOptions .OffPeakWindow .WindowStartTime .Hours
699
+ }
700
+ if desired .ko .Spec .OffPeakWindowOptions .OffPeakWindow .WindowStartTime .Minutes != nil {
701
+ f17f1f1 .Minutes = * desired .ko .Spec .OffPeakWindowOptions .OffPeakWindow .WindowStartTime .Minutes
702
+ }
703
+ f17f1 .WindowStartTime = f17f1f1
704
+ }
705
+ f17 .OffPeakWindow = f17f1
706
+ }
707
+ res .OffPeakWindowOptions = f17
708
+ }
709
+
589
710
return res , nil
590
711
}
712
+
713
+ func int64OrNil (num * int32 ) * int64 {
714
+ if num == nil {
715
+ return nil
716
+ }
717
+
718
+ return aws .Int64 (int64 (* num ))
719
+ }
0 commit comments