@@ -16,8 +16,10 @@ package domain
1616import (
1717 "context"
1818 "errors"
19+ "fmt"
1920
2021 "github.com/aws-controllers-k8s/opensearchservice-controller/apis/v1alpha1"
22+ svcapitypes "github.com/aws-controllers-k8s/opensearchservice-controller/apis/v1alpha1"
2123 ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
2224 ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare"
2325 ackcondition "github.com/aws-controllers-k8s/runtime/pkg/condition"
3739 )
3840)
3941
42+ func checkDomainStatus (resp * svcsdk.DescribeDomainOutput , ko * svcapitypes.Domain ) {
43+ if domainProcessing (& resource {ko }) {
44+ // Setting resource synced condition to false will trigger a requeue of
45+ // the resource. No need to return a requeue error here.
46+ ackcondition .SetSynced (& resource {ko }, corev1 .ConditionFalse , nil , nil )
47+ } else {
48+ ackcondition .SetSynced (& resource {ko }, corev1 .ConditionTrue , nil , nil )
49+ }
50+
51+ if resp .DomainStatus .AutoTuneOptions != nil {
52+ if ready , err := isAutoTuneOptionReady (string (resp .DomainStatus .AutoTuneOptions .State ), resp .DomainStatus .AutoTuneOptions .ErrorMessage ); err != nil {
53+ reason := err .Error ()
54+ ackcondition .SetSynced (& resource {ko }, corev1 .ConditionFalse , nil , & reason )
55+ } else if ! ready {
56+ reason := fmt .Sprintf ("waiting for AutotuneOptions to sync. Current state: %s" , resp .DomainStatus .AutoTuneOptions .State )
57+ ackcondition .SetSynced (& resource {ko }, corev1 .ConditionFalse , nil , & reason )
58+ }
59+ ko .Spec .AutoTuneOptions .DesiredState = aws .String (string (resp .DomainStatus .AutoTuneOptions .State ))
60+ }
61+ }
62+
4063// domainProcessing returns true if the supplied domain is in a state of
4164// processing
4265func domainProcessing (r * resource ) bool {
@@ -46,21 +69,44 @@ func domainProcessing(r *resource) bool {
4669 return * r .ko .Status .Processing
4770}
4871
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+
4988func (rm * resourceManager ) customUpdateDomain (ctx context.Context , desired , latest * resource ,
5089 delta * ackcompare.Delta ) (updated * resource , err error ) {
5190 rlog := ackrtlog .FromContext (ctx )
5291 exit := rlog .Trace ("rm.customUpdateDomain" )
5392 defer exit (err )
5493
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+
55101 if domainProcessing (latest ) {
56102 msg := "Domain is currently processing configuration changes"
57103 ackcondition .SetSynced (desired , corev1 .ConditionFalse , & msg , nil )
58- return desired , requeueWaitWhileProcessing
104+ return latest , requeueWaitWhileProcessing
59105 }
60106 if latest .ko .Status .UpgradeProcessing != nil && * latest .ko .Status .UpgradeProcessing {
61107 msg := "Domain is currently upgrading software"
62108 ackcondition .SetSynced (desired , corev1 .ConditionFalse , & msg , nil )
63- return desired , requeueWaitWhileProcessing
109+ return latest , requeueWaitWhileProcessing
64110 }
65111
66112 if desired .ko .Spec .EngineVersion != nil && delta .DifferentAt ("Spec.EngineVersion" ) {
@@ -185,6 +231,7 @@ func (rm *resourceManager) customUpdateDomain(ctx context.Context, desired, late
185231 }
186232 ko .Spec .AutoTuneOptions = & v1alpha1.AutoTuneOptionsInput {
187233 DesiredState : aws .String (string (resp .DomainConfig .AutoTuneOptions .Options .DesiredState )),
234+ UseOffPeakWindow : resp .DomainConfig .AutoTuneOptions .Options .UseOffPeakWindow ,
188235 MaintenanceSchedules : maintSchedules ,
189236 }
190237 } else {
@@ -205,11 +252,15 @@ func (rm *resourceManager) customUpdateDomain(ctx context.Context, desired, late
205252 }
206253 }
207254 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 ,
213264 }
214265 if resp .DomainConfig .ClusterConfig .Options .DedicatedMasterCount != nil {
215266 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
285336 } else {
286337 ko .Spec .EngineVersion = nil
287338 }
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+ }
288344 if resp .DomainConfig .NodeToNodeEncryptionOptions != nil {
289345 ko .Spec .NodeToNodeEncryptionOptions = & v1alpha1.NodeToNodeEncryptionOptions {
290346 Enabled : resp .DomainConfig .NodeToNodeEncryptionOptions .Options .Enabled ,
291347 }
292348 } else {
293349 ko .Spec .NodeToNodeEncryptionOptions = nil
294350 }
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+ }
295386
296387 rm .setStatusDefaults (ko )
297388
@@ -401,6 +492,9 @@ func (rm *resourceManager) newCustomUpdateRequestPayload(
401492 if desired .ko .Spec .AutoTuneOptions .DesiredState != nil {
402493 f3 .DesiredState = svcsdktypes .AutoTuneDesiredState (* desired .ko .Spec .AutoTuneOptions .DesiredState )
403494 }
495+ if desired .ko .Spec .AutoTuneOptions .UseOffPeakWindow != nil {
496+ f3 .UseOffPeakWindow = desired .ko .Spec .AutoTuneOptions .UseOffPeakWindow
497+ }
404498 if desired .ko .Spec .AutoTuneOptions .MaintenanceSchedules != nil {
405499 f3f1 := []svcsdktypes.AutoTuneMaintenanceSchedule {}
406500 for _ , f3f1iter := range desired .ko .Spec .AutoTuneOptions .MaintenanceSchedules {
@@ -471,6 +565,9 @@ func (rm *resourceManager) newCustomUpdateRequestPayload(
471565 if desired .ko .Spec .ClusterConfig .ZoneAwarenessEnabled != nil {
472566 f4 .ZoneAwarenessEnabled = desired .ko .Spec .ClusterConfig .ZoneAwarenessEnabled
473567 }
568+ if desired .ko .Spec .ClusterConfig .MultiAZWithStandbyEnabled != nil {
569+ f4 .MultiAZWithStandbyEnabled = desired .ko .Spec .ClusterConfig .MultiAZWithStandbyEnabled
570+ }
474571 res .ClusterConfig = f4
475572 }
476573
@@ -586,5 +683,59 @@ func (rm *resourceManager) newCustomUpdateRequestPayload(
586683 res .VPCOptions = f14
587684 }
588685
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+
589732 return res , nil
590733}
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