@@ -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,18 @@ 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
+ DedicatedMasterType : aws .String (string (resp .DomainConfig .ClusterConfig .Options .DedicatedMasterType )),
265
+ InstanceCount : int64OrNil (resp .DomainConfig .ClusterConfig .Options .InstanceCount ),
266
+ InstanceType : aws .String (string (resp .DomainConfig .ClusterConfig .Options .InstanceType )),
267
+ WarmCount : int64OrNil (resp .DomainConfig .ClusterConfig .Options .WarmCount ),
268
+ WarmEnabled : resp .DomainConfig .ClusterConfig .Options .WarmEnabled ,
269
+ WarmType : aws .String (string (resp .DomainConfig .ClusterConfig .Options .WarmType )),
270
+ ZoneAwarenessConfig : zaConfig ,
271
+ ZoneAwarenessEnabled : resp .DomainConfig .ClusterConfig .Options .ZoneAwarenessEnabled ,
272
+ MultiAZWithStandbyEnabled : resp .DomainConfig .ClusterConfig .Options .MultiAZWithStandbyEnabled ,
213
273
}
214
274
if resp .DomainConfig .ClusterConfig .Options .DedicatedMasterCount != nil {
215
275
ko .Spec .ClusterConfig .DedicatedMasterCount = aws .Int64 (int64 (* resp .DomainConfig .ClusterConfig .Options .DedicatedMasterCount ))
@@ -285,13 +345,53 @@ func (rm *resourceManager) customUpdateDomain(ctx context.Context, desired, late
285
345
} else {
286
346
ko .Spec .EngineVersion = nil
287
347
}
348
+ if resp .DomainConfig .IPAddressType != nil {
349
+ ko .Spec .IPAddressType = aws .String (string (resp .DomainConfig .IPAddressType .Options ))
350
+ } else {
351
+ ko .Spec .IPAddressType = nil
352
+ }
288
353
if resp .DomainConfig .NodeToNodeEncryptionOptions != nil {
289
354
ko .Spec .NodeToNodeEncryptionOptions = & v1alpha1.NodeToNodeEncryptionOptions {
290
355
Enabled : resp .DomainConfig .NodeToNodeEncryptionOptions .Options .Enabled ,
291
356
}
292
357
} else {
293
358
ko .Spec .NodeToNodeEncryptionOptions = nil
294
359
}
360
+ if resp .DomainConfig .SoftwareUpdateOptions != nil {
361
+ ko .Spec .SoftwareUpdateOptions = & v1alpha1.SoftwareUpdateOptions {
362
+ AutoSoftwareUpdateEnabled : resp .DomainConfig .SoftwareUpdateOptions .Options .AutoSoftwareUpdateEnabled ,
363
+ }
364
+ } else {
365
+ ko .Spec .SoftwareUpdateOptions = nil
366
+ }
367
+ if resp .DomainConfig .AIMLOptions != nil && resp .DomainConfig .AIMLOptions .Options != nil {
368
+ if resp .DomainConfig .AIMLOptions .Options .NaturalLanguageQueryGenerationOptions != nil {
369
+ ko .Spec .AIMLOptions = & v1alpha1.AIMLOptionsInput {
370
+ NATuralLanguageQueryGenerationOptions : & v1alpha1.NATuralLanguageQueryGenerationOptionsInput {
371
+ DesiredState : aws .String (string (resp .DomainConfig .AIMLOptions .Options .NaturalLanguageQueryGenerationOptions .DesiredState )),
372
+ },
373
+ }
374
+ }
375
+ } else {
376
+ ko .Spec .AIMLOptions = nil
377
+ }
378
+ if resp .DomainConfig .OffPeakWindowOptions != nil && resp .DomainConfig .OffPeakWindowOptions .Options != nil {
379
+ var offPeakWindow * v1alpha1.OffPeakWindow
380
+ if resp .DomainConfig .OffPeakWindowOptions .Options .OffPeakWindow != nil {
381
+ offPeakWindow = & v1alpha1.OffPeakWindow {
382
+ WindowStartTime : & v1alpha1.WindowStartTime {
383
+ Hours : aws .Int64 (resp .DomainConfig .OffPeakWindowOptions .Options .OffPeakWindow .WindowStartTime .Hours ),
384
+ Minutes : aws .Int64 (resp .DomainConfig .OffPeakWindowOptions .Options .OffPeakWindow .WindowStartTime .Minutes ),
385
+ },
386
+ }
387
+ }
388
+ ko .Spec .OffPeakWindowOptions = & v1alpha1.OffPeakWindowOptions {
389
+ Enabled : resp .DomainConfig .OffPeakWindowOptions .Options .Enabled ,
390
+ OffPeakWindow : offPeakWindow ,
391
+ }
392
+ } else {
393
+ ko .Spec .OffPeakWindowOptions = nil
394
+ }
295
395
296
396
rm .setStatusDefaults (ko )
297
397
@@ -401,6 +501,9 @@ func (rm *resourceManager) newCustomUpdateRequestPayload(
401
501
if desired .ko .Spec .AutoTuneOptions .DesiredState != nil {
402
502
f3 .DesiredState = svcsdktypes .AutoTuneDesiredState (* desired .ko .Spec .AutoTuneOptions .DesiredState )
403
503
}
504
+ if desired .ko .Spec .AutoTuneOptions .UseOffPeakWindow != nil {
505
+ f3 .UseOffPeakWindow = desired .ko .Spec .AutoTuneOptions .UseOffPeakWindow
506
+ }
404
507
if desired .ko .Spec .AutoTuneOptions .MaintenanceSchedules != nil {
405
508
f3f1 := []svcsdktypes.AutoTuneMaintenanceSchedule {}
406
509
for _ , f3f1iter := range desired .ko .Spec .AutoTuneOptions .MaintenanceSchedules {
@@ -471,6 +574,9 @@ func (rm *resourceManager) newCustomUpdateRequestPayload(
471
574
if desired .ko .Spec .ClusterConfig .ZoneAwarenessEnabled != nil {
472
575
f4 .ZoneAwarenessEnabled = desired .ko .Spec .ClusterConfig .ZoneAwarenessEnabled
473
576
}
577
+ if desired .ko .Spec .ClusterConfig .MultiAZWithStandbyEnabled != nil {
578
+ f4 .MultiAZWithStandbyEnabled = desired .ko .Spec .ClusterConfig .MultiAZWithStandbyEnabled
579
+ }
474
580
res .ClusterConfig = f4
475
581
}
476
582
@@ -586,5 +692,59 @@ func (rm *resourceManager) newCustomUpdateRequestPayload(
586
692
res .VPCOptions = f14
587
693
}
588
694
695
+ if desired .ko .Spec .IPAddressType != nil && delta .DifferentAt ("Spec.IPAddressType" ) {
696
+ res .IPAddressType = svcsdktypes .IPAddressType (* desired .ko .Spec .IPAddressType )
697
+ }
698
+
699
+ if desired .ko .Spec .SoftwareUpdateOptions != nil && delta .DifferentAt ("Spec.SoftwareUpdateOptions" ) {
700
+ f15 := & svcsdktypes.SoftwareUpdateOptions {}
701
+ if desired .ko .Spec .SoftwareUpdateOptions .AutoSoftwareUpdateEnabled != nil {
702
+ f15 .AutoSoftwareUpdateEnabled = desired .ko .Spec .SoftwareUpdateOptions .AutoSoftwareUpdateEnabled
703
+ }
704
+ res .SoftwareUpdateOptions = f15
705
+ }
706
+
707
+ if desired .ko .Spec .AIMLOptions != nil && delta .DifferentAt ("Spec.AIMLOptions" ) {
708
+ f16 := & svcsdktypes.AIMLOptionsInput {}
709
+ if desired .ko .Spec .AIMLOptions .NATuralLanguageQueryGenerationOptions != nil {
710
+ f16f0 := & svcsdktypes.NaturalLanguageQueryGenerationOptionsInput {}
711
+ if desired .ko .Spec .AIMLOptions .NATuralLanguageQueryGenerationOptions .DesiredState != nil {
712
+ f16f0 .DesiredState = svcsdktypes .NaturalLanguageQueryGenerationDesiredState (* desired .ko .Spec .AIMLOptions .NATuralLanguageQueryGenerationOptions .DesiredState )
713
+ }
714
+ f16 .NaturalLanguageQueryGenerationOptions = f16f0
715
+ }
716
+ res .AIMLOptions = f16
717
+ }
718
+
719
+ if desired .ko .Spec .OffPeakWindowOptions != nil && delta .DifferentAt ("Spec.OffPeakWindowOptions" ) {
720
+ f17 := & svcsdktypes.OffPeakWindowOptions {}
721
+ if desired .ko .Spec .OffPeakWindowOptions .Enabled != nil {
722
+ f17 .Enabled = desired .ko .Spec .OffPeakWindowOptions .Enabled
723
+ }
724
+ if desired .ko .Spec .OffPeakWindowOptions .OffPeakWindow != nil {
725
+ f17f1 := & svcsdktypes.OffPeakWindow {}
726
+ if desired .ko .Spec .OffPeakWindowOptions .OffPeakWindow .WindowStartTime != nil {
727
+ f17f1f1 := & svcsdktypes.WindowStartTime {}
728
+ if desired .ko .Spec .OffPeakWindowOptions .OffPeakWindow .WindowStartTime .Hours != nil {
729
+ f17f1f1 .Hours = * desired .ko .Spec .OffPeakWindowOptions .OffPeakWindow .WindowStartTime .Hours
730
+ }
731
+ if desired .ko .Spec .OffPeakWindowOptions .OffPeakWindow .WindowStartTime .Minutes != nil {
732
+ f17f1f1 .Minutes = * desired .ko .Spec .OffPeakWindowOptions .OffPeakWindow .WindowStartTime .Minutes
733
+ }
734
+ f17f1 .WindowStartTime = f17f1f1
735
+ }
736
+ f17 .OffPeakWindow = f17f1
737
+ }
738
+ res .OffPeakWindowOptions = f17
739
+ }
740
+
589
741
return res , nil
590
742
}
743
+
744
+ func int64OrNil (num * int32 ) * int64 {
745
+ if num == nil {
746
+ return nil
747
+ }
748
+
749
+ return aws .Int64 (int64 (* num ))
750
+ }
0 commit comments