@@ -16,8 +16,10 @@ 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"
22
+ svcapitypes "github.com/aws-controllers-k8s/opensearchservice-controller/apis/v1alpha1"
21
23
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
22
24
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare"
23
25
ackcondition "github.com/aws-controllers-k8s/runtime/pkg/condition"
37
39
)
38
40
)
39
41
42
+ func checkDomainStatus (resp * svcsdk.DescribeDomainOutput , ko * svcapitypes.Domain ) {
43
+ if resp .DomainStatus .AutoTuneOptions != nil {
44
+ if ready , err := isAutoTuneOptionReady (string (resp .DomainStatus .AutoTuneOptions .State ), resp .DomainStatus .AutoTuneOptions .ErrorMessage ); err != nil {
45
+ reason := err .Error ()
46
+ ackcondition .SetSynced (& resource {ko }, corev1 .ConditionFalse , nil , & reason )
47
+ } else if ! ready {
48
+ reason := fmt .Sprintf ("waiting for AutotuneOptions to sync. Current state: %s" , resp .DomainStatus .AutoTuneOptions .State )
49
+ ackcondition .SetSynced (& resource {ko }, corev1 .ConditionFalse , nil , & reason )
50
+ }
51
+ ko .Spec .AutoTuneOptions .DesiredState = aws .String (string (resp .DomainStatus .AutoTuneOptions .State ))
52
+ }
53
+
54
+ if domainProcessing (& resource {ko }) {
55
+ // Setting resource synced condition to false will trigger a requeue of
56
+ // the resource. No need to return a requeue error here.
57
+ ackcondition .SetSynced (& resource {ko }, corev1 .ConditionFalse , nil , nil )
58
+ } else {
59
+ ackcondition .SetSynced (& resource {ko }, corev1 .ConditionTrue , nil , nil )
60
+ }
61
+ }
62
+
40
63
// domainProcessing returns true if the supplied domain is in a state of
41
64
// processing
42
65
func domainProcessing (r * resource ) bool {
@@ -46,21 +69,44 @@ func domainProcessing(r *resource) bool {
46
69
return * r .ko .Status .Processing
47
70
}
48
71
72
+ func isAutoTuneOptionReady (state string , errorMessage * string ) (bool , error ) {
73
+ switch svcsdktypes .AutoTuneState (state ) {
74
+ case svcsdktypes .AutoTuneStateEnabled , svcsdktypes .AutoTuneStateDisabled :
75
+ return true , nil
76
+
77
+ case svcsdktypes .AutoTuneStateError :
78
+ if errorMessage != nil {
79
+ return false , fmt .Errorf ("error: %s" , * errorMessage )
80
+ }
81
+ return false , fmt .Errorf ("there is an error when updating AutoTuneOptions" )
82
+
83
+ default :
84
+ return false , nil
85
+ }
86
+ }
87
+
49
88
func (rm * resourceManager ) customUpdateDomain (ctx context.Context , desired , latest * resource ,
50
89
delta * ackcompare.Delta ) (updated * resource , err error ) {
51
90
rlog := ackrtlog .FromContext (ctx )
52
91
exit := rlog .Trace ("rm.customUpdateDomain" )
53
92
defer exit (err )
54
93
94
+ if latest .ko .Spec .AutoTuneOptions != nil &&
95
+ latest .ko .Spec .AutoTuneOptions .DesiredState != nil {
96
+ if ready , _ := isAutoTuneOptionReady (* latest .ko .Spec .AutoTuneOptions .DesiredState , nil ); ! ready {
97
+ return latest , ackrequeue .Needed (fmt .Errorf ("autoTuneOption is updating" ))
98
+ }
99
+ }
100
+
55
101
if domainProcessing (latest ) {
56
102
msg := "Domain is currently processing configuration changes"
57
103
ackcondition .SetSynced (desired , corev1 .ConditionFalse , & msg , nil )
58
- return desired , requeueWaitWhileProcessing
104
+ return latest , requeueWaitWhileProcessing
59
105
}
60
106
if latest .ko .Status .UpgradeProcessing != nil && * latest .ko .Status .UpgradeProcessing {
61
107
msg := "Domain is currently upgrading software"
62
108
ackcondition .SetSynced (desired , corev1 .ConditionFalse , & msg , nil )
63
- return desired , requeueWaitWhileProcessing
109
+ return latest , requeueWaitWhileProcessing
64
110
}
65
111
66
112
if desired .ko .Spec .EngineVersion != nil && delta .DifferentAt ("Spec.EngineVersion" ) {
@@ -185,6 +231,7 @@ func (rm *resourceManager) customUpdateDomain(ctx context.Context, desired, late
185
231
}
186
232
ko .Spec .AutoTuneOptions = & v1alpha1.AutoTuneOptionsInput {
187
233
DesiredState : aws .String (string (resp .DomainConfig .AutoTuneOptions .Options .DesiredState )),
234
+ UseOffPeakWindow : resp .DomainConfig .AutoTuneOptions .Options .UseOffPeakWindow ,
188
235
MaintenanceSchedules : maintSchedules ,
189
236
}
190
237
} else {
@@ -205,11 +252,15 @@ func (rm *resourceManager) customUpdateDomain(ctx context.Context, desired, late
205
252
}
206
253
}
207
254
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 ,
255
+ ColdStorageOptions : csOptions ,
256
+ DedicatedMasterCount : int64OrNil (resp .DomainConfig .ClusterConfig .Options .DedicatedMasterCount ),
257
+ DedicatedMasterEnabled : resp .DomainConfig .ClusterConfig .Options .DedicatedMasterEnabled ,
258
+ InstanceCount : int64OrNil (resp .DomainConfig .ClusterConfig .Options .InstanceCount ),
259
+ WarmCount : int64OrNil (resp .DomainConfig .ClusterConfig .Options .WarmCount ),
260
+ WarmEnabled : resp .DomainConfig .ClusterConfig .Options .WarmEnabled ,
261
+ ZoneAwarenessConfig : zaConfig ,
262
+ ZoneAwarenessEnabled : resp .DomainConfig .ClusterConfig .Options .ZoneAwarenessEnabled ,
263
+ MultiAZWithStandbyEnabled : resp .DomainConfig .ClusterConfig .Options .MultiAZWithStandbyEnabled ,
213
264
}
214
265
if resp .DomainConfig .ClusterConfig .Options .DedicatedMasterCount != nil {
215
266
ko .Spec .ClusterConfig .DedicatedMasterCount = aws .Int64 (int64 (* resp .DomainConfig .ClusterConfig .Options .DedicatedMasterCount ))
@@ -285,13 +336,53 @@ func (rm *resourceManager) customUpdateDomain(ctx context.Context, desired, late
285
336
} else {
286
337
ko .Spec .EngineVersion = nil
287
338
}
339
+ if resp .DomainConfig .IPAddressType != nil {
340
+ ko .Spec .IPAddressType = aws .String (string (resp .DomainConfig .IPAddressType .Options ))
341
+ } else {
342
+ ko .Spec .IPAddressType = nil
343
+ }
288
344
if resp .DomainConfig .NodeToNodeEncryptionOptions != nil {
289
345
ko .Spec .NodeToNodeEncryptionOptions = & v1alpha1.NodeToNodeEncryptionOptions {
290
346
Enabled : resp .DomainConfig .NodeToNodeEncryptionOptions .Options .Enabled ,
291
347
}
292
348
} else {
293
349
ko .Spec .NodeToNodeEncryptionOptions = nil
294
350
}
351
+ if resp .DomainConfig .SoftwareUpdateOptions != nil {
352
+ ko .Spec .SoftwareUpdateOptions = & v1alpha1.SoftwareUpdateOptions {
353
+ AutoSoftwareUpdateEnabled : resp .DomainConfig .SoftwareUpdateOptions .Options .AutoSoftwareUpdateEnabled ,
354
+ }
355
+ } else {
356
+ ko .Spec .SoftwareUpdateOptions = nil
357
+ }
358
+ if resp .DomainConfig .AIMLOptions != nil && resp .DomainConfig .AIMLOptions .Options != nil {
359
+ if resp .DomainConfig .AIMLOptions .Options .NaturalLanguageQueryGenerationOptions != nil {
360
+ ko .Spec .AIMLOptions = & v1alpha1.AIMLOptionsInput {
361
+ NATuralLanguageQueryGenerationOptions : & v1alpha1.NATuralLanguageQueryGenerationOptionsInput {
362
+ DesiredState : aws .String (string (resp .DomainConfig .AIMLOptions .Options .NaturalLanguageQueryGenerationOptions .DesiredState )),
363
+ },
364
+ }
365
+ }
366
+ } else {
367
+ ko .Spec .AIMLOptions = nil
368
+ }
369
+ if resp .DomainConfig .OffPeakWindowOptions != nil && resp .DomainConfig .OffPeakWindowOptions .Options != nil {
370
+ var offPeakWindow * v1alpha1.OffPeakWindow
371
+ if resp .DomainConfig .OffPeakWindowOptions .Options .OffPeakWindow != nil {
372
+ offPeakWindow = & v1alpha1.OffPeakWindow {
373
+ WindowStartTime : & v1alpha1.WindowStartTime {
374
+ Hours : aws .Int64 (resp .DomainConfig .OffPeakWindowOptions .Options .OffPeakWindow .WindowStartTime .Hours ),
375
+ Minutes : aws .Int64 (resp .DomainConfig .OffPeakWindowOptions .Options .OffPeakWindow .WindowStartTime .Minutes ),
376
+ },
377
+ }
378
+ }
379
+ ko .Spec .OffPeakWindowOptions = & v1alpha1.OffPeakWindowOptions {
380
+ Enabled : resp .DomainConfig .OffPeakWindowOptions .Options .Enabled ,
381
+ OffPeakWindow : offPeakWindow ,
382
+ }
383
+ } else {
384
+ ko .Spec .OffPeakWindowOptions = nil
385
+ }
295
386
296
387
rm .setStatusDefaults (ko )
297
388
@@ -401,6 +492,9 @@ func (rm *resourceManager) newCustomUpdateRequestPayload(
401
492
if desired .ko .Spec .AutoTuneOptions .DesiredState != nil {
402
493
f3 .DesiredState = svcsdktypes .AutoTuneDesiredState (* desired .ko .Spec .AutoTuneOptions .DesiredState )
403
494
}
495
+ if desired .ko .Spec .AutoTuneOptions .UseOffPeakWindow != nil {
496
+ f3 .UseOffPeakWindow = desired .ko .Spec .AutoTuneOptions .UseOffPeakWindow
497
+ }
404
498
if desired .ko .Spec .AutoTuneOptions .MaintenanceSchedules != nil {
405
499
f3f1 := []svcsdktypes.AutoTuneMaintenanceSchedule {}
406
500
for _ , f3f1iter := range desired .ko .Spec .AutoTuneOptions .MaintenanceSchedules {
@@ -471,6 +565,9 @@ func (rm *resourceManager) newCustomUpdateRequestPayload(
471
565
if desired .ko .Spec .ClusterConfig .ZoneAwarenessEnabled != nil {
472
566
f4 .ZoneAwarenessEnabled = desired .ko .Spec .ClusterConfig .ZoneAwarenessEnabled
473
567
}
568
+ if desired .ko .Spec .ClusterConfig .MultiAZWithStandbyEnabled != nil {
569
+ f4 .MultiAZWithStandbyEnabled = desired .ko .Spec .ClusterConfig .MultiAZWithStandbyEnabled
570
+ }
474
571
res .ClusterConfig = f4
475
572
}
476
573
@@ -586,5 +683,59 @@ func (rm *resourceManager) newCustomUpdateRequestPayload(
586
683
res .VPCOptions = f14
587
684
}
588
685
686
+ if desired .ko .Spec .IPAddressType != nil && delta .DifferentAt ("Spec.IPAddressType" ) {
687
+ res .IPAddressType = svcsdktypes .IPAddressType (* desired .ko .Spec .IPAddressType )
688
+ }
689
+
690
+ if desired .ko .Spec .SoftwareUpdateOptions != nil && delta .DifferentAt ("Spec.SoftwareUpdateOptions" ) {
691
+ f15 := & svcsdktypes.SoftwareUpdateOptions {}
692
+ if desired .ko .Spec .SoftwareUpdateOptions .AutoSoftwareUpdateEnabled != nil {
693
+ f15 .AutoSoftwareUpdateEnabled = desired .ko .Spec .SoftwareUpdateOptions .AutoSoftwareUpdateEnabled
694
+ }
695
+ res .SoftwareUpdateOptions = f15
696
+ }
697
+
698
+ if desired .ko .Spec .AIMLOptions != nil && delta .DifferentAt ("Spec.AIMLOptions" ) {
699
+ f16 := & svcsdktypes.AIMLOptionsInput {}
700
+ if desired .ko .Spec .AIMLOptions .NATuralLanguageQueryGenerationOptions != nil {
701
+ f16f0 := & svcsdktypes.NaturalLanguageQueryGenerationOptionsInput {}
702
+ if desired .ko .Spec .AIMLOptions .NATuralLanguageQueryGenerationOptions .DesiredState != nil {
703
+ f16f0 .DesiredState = svcsdktypes .NaturalLanguageQueryGenerationDesiredState (* desired .ko .Spec .AIMLOptions .NATuralLanguageQueryGenerationOptions .DesiredState )
704
+ }
705
+ f16 .NaturalLanguageQueryGenerationOptions = f16f0
706
+ }
707
+ res .AIMLOptions = f16
708
+ }
709
+
710
+ if desired .ko .Spec .OffPeakWindowOptions != nil && delta .DifferentAt ("Spec.OffPeakWindowOptions" ) {
711
+ f17 := & svcsdktypes.OffPeakWindowOptions {}
712
+ if desired .ko .Spec .OffPeakWindowOptions .Enabled != nil {
713
+ f17 .Enabled = desired .ko .Spec .OffPeakWindowOptions .Enabled
714
+ }
715
+ if desired .ko .Spec .OffPeakWindowOptions .OffPeakWindow != nil {
716
+ f17f1 := & svcsdktypes.OffPeakWindow {}
717
+ if desired .ko .Spec .OffPeakWindowOptions .OffPeakWindow .WindowStartTime != nil {
718
+ f17f1f1 := & svcsdktypes.WindowStartTime {}
719
+ if desired .ko .Spec .OffPeakWindowOptions .OffPeakWindow .WindowStartTime .Hours != nil {
720
+ f17f1f1 .Hours = * desired .ko .Spec .OffPeakWindowOptions .OffPeakWindow .WindowStartTime .Hours
721
+ }
722
+ if desired .ko .Spec .OffPeakWindowOptions .OffPeakWindow .WindowStartTime .Minutes != nil {
723
+ f17f1f1 .Minutes = * desired .ko .Spec .OffPeakWindowOptions .OffPeakWindow .WindowStartTime .Minutes
724
+ }
725
+ f17f1 .WindowStartTime = f17f1f1
726
+ }
727
+ f17 .OffPeakWindow = f17f1
728
+ }
729
+ res .OffPeakWindowOptions = f17
730
+ }
731
+
589
732
return res , nil
590
733
}
734
+
735
+ func int64OrNil (num * int32 ) * int64 {
736
+ if num == nil {
737
+ return nil
738
+ }
739
+
740
+ return aws .Int64 (int64 (* num ))
741
+ }
0 commit comments