@@ -16,6 +16,8 @@ package domain
16
16
import (
17
17
"context"
18
18
"errors"
19
+ "fmt"
20
+ "strings"
19
21
20
22
"github.com/aws-controllers-k8s/opensearchservice-controller/apis/v1alpha1"
21
23
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
@@ -28,13 +30,16 @@ import (
28
30
svcsdktypes "github.com/aws/aws-sdk-go-v2/service/opensearch/types"
29
31
corev1 "k8s.io/api/core/v1"
30
32
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
33
+
34
+ svcapitypes "github.com/aws-controllers-k8s/opensearchservice-controller/apis/v1alpha1"
31
35
)
32
36
33
37
var (
34
38
requeueWaitWhileProcessing = ackrequeue .NeededAfter (
35
39
errors .New ("domain is currently processing changes, cannot be modified or deleted" ),
36
40
ackrequeue .DefaultRequeueAfterDuration ,
37
41
)
42
+ noAutoTuneInstances = []string {"t2" , "t3" }
38
43
)
39
44
40
45
// domainProcessing returns true if the supplied domain is in a state of
@@ -46,21 +51,68 @@ func domainProcessing(r *resource) bool {
46
51
return * r .ko .Status .Processing
47
52
}
48
53
54
+ func isAutoTuneOptionReady (autoTuneOption * svcsdktypes.AutoTuneOptionsOutput ) (bool , error ) {
55
+ switch autoTuneOption .State {
56
+ case svcsdktypes .AutoTuneStateEnabled , svcsdktypes .AutoTuneStateDisabled :
57
+ return true , nil
58
+
59
+ case svcsdktypes .AutoTuneStateError :
60
+ if autoTuneOption .ErrorMessage != nil {
61
+ return false , fmt .Errorf ("error: %s" , * autoTuneOption .ErrorMessage )
62
+ }
63
+ return false , fmt .Errorf ("there is an error when updating AutoTuneOptions" )
64
+
65
+ default :
66
+ return false , nil
67
+ }
68
+ }
69
+
70
+ func isAutoTuneOptionAvailable (autoTuneOption * svcapitypes.AutoTuneOptionsInput ) bool {
71
+ if autoTuneOption == nil {
72
+ return true
73
+ }
74
+ switch * autoTuneOption .DesiredState {
75
+ case string (svcsdktypes .AutoTuneStateEnabled ), string (svcsdktypes .AutoTuneStateDisabled ):
76
+ return true
77
+ default :
78
+ return false
79
+ }
80
+ }
81
+
82
+ // isAutoTuneSupported returns true if instance type supports AutoTune
83
+ // https://docs.aws.amazon.com/opensearch-service/latest/developerguide/supported-instance-types.html
84
+ func isAutoTuneSupported (r * resource ) bool {
85
+ if r .ko .Spec .ClusterConfig != nil && r .ko .Spec .ClusterConfig .InstanceType != nil {
86
+ for _ , v := range noAutoTuneInstances {
87
+ if strings .HasPrefix (* r .ko .Spec .ClusterConfig .InstanceType , v ) {
88
+ return false
89
+ }
90
+ }
91
+ }
92
+ return true
93
+ }
94
+
49
95
func (rm * resourceManager ) customUpdateDomain (ctx context.Context , desired , latest * resource ,
50
96
delta * ackcompare.Delta ) (updated * resource , err error ) {
51
97
rlog := ackrtlog .FromContext (ctx )
52
98
exit := rlog .Trace ("rm.customUpdateDomain" )
53
99
defer exit (err )
54
100
101
+ if latest .ko .Spec .AutoTuneOptions != nil {
102
+ if ! isAutoTuneOptionAvailable (latest .ko .Spec .AutoTuneOptions ) {
103
+ return latest , ackrequeue .Needed (fmt .Errorf ("autoTuneOption is updating" ))
104
+ }
105
+ }
106
+
55
107
if domainProcessing (latest ) {
56
108
msg := "Domain is currently processing configuration changes"
57
109
ackcondition .SetSynced (desired , corev1 .ConditionFalse , & msg , nil )
58
- return desired , requeueWaitWhileProcessing
110
+ return latest , requeueWaitWhileProcessing
59
111
}
60
112
if latest .ko .Status .UpgradeProcessing != nil && * latest .ko .Status .UpgradeProcessing {
61
113
msg := "Domain is currently upgrading software"
62
114
ackcondition .SetSynced (desired , corev1 .ConditionFalse , & msg , nil )
63
- return desired , requeueWaitWhileProcessing
115
+ return latest , requeueWaitWhileProcessing
64
116
}
65
117
66
118
if desired .ko .Spec .EngineVersion != nil && delta .DifferentAt ("Spec.EngineVersion" ) {
@@ -185,6 +237,7 @@ func (rm *resourceManager) customUpdateDomain(ctx context.Context, desired, late
185
237
}
186
238
ko .Spec .AutoTuneOptions = & v1alpha1.AutoTuneOptionsInput {
187
239
DesiredState : aws .String (string (resp .DomainConfig .AutoTuneOptions .Options .DesiredState )),
240
+ UseOffPeakWindow : resp .DomainConfig .AutoTuneOptions .Options .UseOffPeakWindow ,
188
241
MaintenanceSchedules : maintSchedules ,
189
242
}
190
243
} else {
@@ -205,11 +258,15 @@ func (rm *resourceManager) customUpdateDomain(ctx context.Context, desired, late
205
258
}
206
259
}
207
260
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 ,
261
+ ColdStorageOptions : csOptions ,
262
+ DedicatedMasterCount : int64OrNil (resp .DomainConfig .ClusterConfig .Options .DedicatedMasterCount ),
263
+ DedicatedMasterEnabled : resp .DomainConfig .ClusterConfig .Options .DedicatedMasterEnabled ,
264
+ InstanceCount : int64OrNil (resp .DomainConfig .ClusterConfig .Options .InstanceCount ),
265
+ WarmCount : int64OrNil (resp .DomainConfig .ClusterConfig .Options .WarmCount ),
266
+ WarmEnabled : resp .DomainConfig .ClusterConfig .Options .WarmEnabled ,
267
+ ZoneAwarenessConfig : zaConfig ,
268
+ ZoneAwarenessEnabled : resp .DomainConfig .ClusterConfig .Options .ZoneAwarenessEnabled ,
269
+ MultiAZWithStandbyEnabled : resp .DomainConfig .ClusterConfig .Options .MultiAZWithStandbyEnabled ,
213
270
}
214
271
if resp .DomainConfig .ClusterConfig .Options .DedicatedMasterCount != nil {
215
272
ko .Spec .ClusterConfig .DedicatedMasterCount = aws .Int64 (int64 (* resp .DomainConfig .ClusterConfig .Options .DedicatedMasterCount ))
@@ -285,13 +342,53 @@ func (rm *resourceManager) customUpdateDomain(ctx context.Context, desired, late
285
342
} else {
286
343
ko .Spec .EngineVersion = nil
287
344
}
345
+ if resp .DomainConfig .IPAddressType != nil {
346
+ ko .Spec .IPAddressType = aws .String (string (resp .DomainConfig .IPAddressType .Options ))
347
+ } else {
348
+ ko .Spec .IPAddressType = nil
349
+ }
288
350
if resp .DomainConfig .NodeToNodeEncryptionOptions != nil {
289
351
ko .Spec .NodeToNodeEncryptionOptions = & v1alpha1.NodeToNodeEncryptionOptions {
290
352
Enabled : resp .DomainConfig .NodeToNodeEncryptionOptions .Options .Enabled ,
291
353
}
292
354
} else {
293
355
ko .Spec .NodeToNodeEncryptionOptions = nil
294
356
}
357
+ if resp .DomainConfig .SoftwareUpdateOptions != nil {
358
+ ko .Spec .SoftwareUpdateOptions = & v1alpha1.SoftwareUpdateOptions {
359
+ AutoSoftwareUpdateEnabled : resp .DomainConfig .SoftwareUpdateOptions .Options .AutoSoftwareUpdateEnabled ,
360
+ }
361
+ } else {
362
+ ko .Spec .SoftwareUpdateOptions = nil
363
+ }
364
+ if resp .DomainConfig .AIMLOptions != nil && resp .DomainConfig .AIMLOptions .Options != nil {
365
+ if resp .DomainConfig .AIMLOptions .Options .NaturalLanguageQueryGenerationOptions != nil {
366
+ ko .Spec .AIMLOptions = & v1alpha1.AIMLOptionsInput {
367
+ NATuralLanguageQueryGenerationOptions : & v1alpha1.NATuralLanguageQueryGenerationOptionsInput {
368
+ DesiredState : aws .String (string (resp .DomainConfig .AIMLOptions .Options .NaturalLanguageQueryGenerationOptions .DesiredState )),
369
+ },
370
+ }
371
+ }
372
+ } else {
373
+ ko .Spec .AIMLOptions = nil
374
+ }
375
+ if resp .DomainConfig .OffPeakWindowOptions != nil && resp .DomainConfig .OffPeakWindowOptions .Options != nil {
376
+ var offPeakWindow * v1alpha1.OffPeakWindow
377
+ if resp .DomainConfig .OffPeakWindowOptions .Options .OffPeakWindow != nil {
378
+ offPeakWindow = & v1alpha1.OffPeakWindow {
379
+ WindowStartTime : & v1alpha1.WindowStartTime {
380
+ Hours : aws .Int64 (resp .DomainConfig .OffPeakWindowOptions .Options .OffPeakWindow .WindowStartTime .Hours ),
381
+ Minutes : aws .Int64 (resp .DomainConfig .OffPeakWindowOptions .Options .OffPeakWindow .WindowStartTime .Minutes ),
382
+ },
383
+ }
384
+ }
385
+ ko .Spec .OffPeakWindowOptions = & v1alpha1.OffPeakWindowOptions {
386
+ Enabled : resp .DomainConfig .OffPeakWindowOptions .Options .Enabled ,
387
+ OffPeakWindow : offPeakWindow ,
388
+ }
389
+ } else {
390
+ ko .Spec .OffPeakWindowOptions = nil
391
+ }
295
392
296
393
rm .setStatusDefaults (ko )
297
394
@@ -401,6 +498,9 @@ func (rm *resourceManager) newCustomUpdateRequestPayload(
401
498
if desired .ko .Spec .AutoTuneOptions .DesiredState != nil {
402
499
f3 .DesiredState = svcsdktypes .AutoTuneDesiredState (* desired .ko .Spec .AutoTuneOptions .DesiredState )
403
500
}
501
+ if desired .ko .Spec .AutoTuneOptions .UseOffPeakWindow != nil {
502
+ f3 .UseOffPeakWindow = desired .ko .Spec .AutoTuneOptions .UseOffPeakWindow
503
+ }
404
504
if desired .ko .Spec .AutoTuneOptions .MaintenanceSchedules != nil {
405
505
f3f1 := []svcsdktypes.AutoTuneMaintenanceSchedule {}
406
506
for _ , f3f1iter := range desired .ko .Spec .AutoTuneOptions .MaintenanceSchedules {
@@ -471,6 +571,9 @@ func (rm *resourceManager) newCustomUpdateRequestPayload(
471
571
if desired .ko .Spec .ClusterConfig .ZoneAwarenessEnabled != nil {
472
572
f4 .ZoneAwarenessEnabled = desired .ko .Spec .ClusterConfig .ZoneAwarenessEnabled
473
573
}
574
+ if desired .ko .Spec .ClusterConfig .MultiAZWithStandbyEnabled != nil {
575
+ f4 .MultiAZWithStandbyEnabled = desired .ko .Spec .ClusterConfig .MultiAZWithStandbyEnabled
576
+ }
474
577
res .ClusterConfig = f4
475
578
}
476
579
@@ -586,5 +689,59 @@ func (rm *resourceManager) newCustomUpdateRequestPayload(
586
689
res .VPCOptions = f14
587
690
}
588
691
692
+ if desired .ko .Spec .IPAddressType != nil && delta .DifferentAt ("Spec.IPAddressType" ) {
693
+ res .IPAddressType = svcsdktypes .IPAddressType (* desired .ko .Spec .IPAddressType )
694
+ }
695
+
696
+ if desired .ko .Spec .SoftwareUpdateOptions != nil && delta .DifferentAt ("Spec.SoftwareUpdateOptions" ) {
697
+ f15 := & svcsdktypes.SoftwareUpdateOptions {}
698
+ if desired .ko .Spec .SoftwareUpdateOptions .AutoSoftwareUpdateEnabled != nil {
699
+ f15 .AutoSoftwareUpdateEnabled = desired .ko .Spec .SoftwareUpdateOptions .AutoSoftwareUpdateEnabled
700
+ }
701
+ res .SoftwareUpdateOptions = f15
702
+ }
703
+
704
+ if desired .ko .Spec .AIMLOptions != nil && delta .DifferentAt ("Spec.AIMLOptions" ) {
705
+ f16 := & svcsdktypes.AIMLOptionsInput {}
706
+ if desired .ko .Spec .AIMLOptions .NATuralLanguageQueryGenerationOptions != nil {
707
+ f16f0 := & svcsdktypes.NaturalLanguageQueryGenerationOptionsInput {}
708
+ if desired .ko .Spec .AIMLOptions .NATuralLanguageQueryGenerationOptions .DesiredState != nil {
709
+ f16f0 .DesiredState = svcsdktypes .NaturalLanguageQueryGenerationDesiredState (* desired .ko .Spec .AIMLOptions .NATuralLanguageQueryGenerationOptions .DesiredState )
710
+ }
711
+ f16 .NaturalLanguageQueryGenerationOptions = f16f0
712
+ }
713
+ res .AIMLOptions = f16
714
+ }
715
+
716
+ if desired .ko .Spec .OffPeakWindowOptions != nil && delta .DifferentAt ("Spec.OffPeakWindowOptions" ) {
717
+ f17 := & svcsdktypes.OffPeakWindowOptions {}
718
+ if desired .ko .Spec .OffPeakWindowOptions .Enabled != nil {
719
+ f17 .Enabled = desired .ko .Spec .OffPeakWindowOptions .Enabled
720
+ }
721
+ if desired .ko .Spec .OffPeakWindowOptions .OffPeakWindow != nil {
722
+ f17f1 := & svcsdktypes.OffPeakWindow {}
723
+ if desired .ko .Spec .OffPeakWindowOptions .OffPeakWindow .WindowStartTime != nil {
724
+ f17f1f1 := & svcsdktypes.WindowStartTime {}
725
+ if desired .ko .Spec .OffPeakWindowOptions .OffPeakWindow .WindowStartTime .Hours != nil {
726
+ f17f1f1 .Hours = * desired .ko .Spec .OffPeakWindowOptions .OffPeakWindow .WindowStartTime .Hours
727
+ }
728
+ if desired .ko .Spec .OffPeakWindowOptions .OffPeakWindow .WindowStartTime .Minutes != nil {
729
+ f17f1f1 .Minutes = * desired .ko .Spec .OffPeakWindowOptions .OffPeakWindow .WindowStartTime .Minutes
730
+ }
731
+ f17f1 .WindowStartTime = f17f1f1
732
+ }
733
+ f17 .OffPeakWindow = f17f1
734
+ }
735
+ res .OffPeakWindowOptions = f17
736
+ }
737
+
589
738
return res , nil
590
739
}
740
+
741
+ func int64OrNil (num * int32 ) * int64 {
742
+ if num == nil {
743
+ return nil
744
+ }
745
+
746
+ return aws .Int64 (int64 (* num ))
747
+ }
0 commit comments