Skip to content

Commit 69f014a

Browse files
fix: Set extra fields
Co-Authored-By: Andrei Charviakou <[email protected]>
1 parent 984c983 commit 69f014a

File tree

5 files changed

+244
-17
lines changed

5 files changed

+244
-17
lines changed

apis/v1alpha1/ack-generate-metadata.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ack_generate_info:
2-
build_date: "2025-05-02T16:41:02Z"
2+
build_date: "2025-05-06T05:27:03Z"
33
build_hash: f8dc5330705b3752ce07dce0ac831161fd4cb14f
4-
go_version: go1.24.2
4+
go_version: go1.24.1
55
version: v0.45.0
66
api_directory_checksum: 13af9d3a7962f45a46b4bedaca965631b194a9a8
77
api_version: v1alpha1

pkg/resource/domain/hooks.go

Lines changed: 164 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ package domain
1616
import (
1717
"context"
1818
"errors"
19+
"fmt"
20+
"strings"
1921

2022
"github.com/aws-controllers-k8s/opensearchservice-controller/apis/v1alpha1"
2123
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
@@ -28,13 +30,16 @@ import (
2830
svcsdktypes "github.com/aws/aws-sdk-go-v2/service/opensearch/types"
2931
corev1 "k8s.io/api/core/v1"
3032
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
33+
34+
svcapitypes "github.com/aws-controllers-k8s/opensearchservice-controller/apis/v1alpha1"
3135
)
3236

3337
var (
3438
requeueWaitWhileProcessing = ackrequeue.NeededAfter(
3539
errors.New("domain is currently processing changes, cannot be modified or deleted"),
3640
ackrequeue.DefaultRequeueAfterDuration,
3741
)
42+
noAutoTuneInstances = []string{"t2", "t3"}
3843
)
3944

4045
// domainProcessing returns true if the supplied domain is in a state of
@@ -46,21 +51,68 @@ func domainProcessing(r *resource) bool {
4651
return *r.ko.Status.Processing
4752
}
4853

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+
4995
func (rm *resourceManager) customUpdateDomain(ctx context.Context, desired, latest *resource,
5096
delta *ackcompare.Delta) (updated *resource, err error) {
5197
rlog := ackrtlog.FromContext(ctx)
5298
exit := rlog.Trace("rm.customUpdateDomain")
5399
defer exit(err)
54100

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+
55107
if domainProcessing(latest) {
56108
msg := "Domain is currently processing configuration changes"
57109
ackcondition.SetSynced(desired, corev1.ConditionFalse, &msg, nil)
58-
return desired, requeueWaitWhileProcessing
110+
return latest, requeueWaitWhileProcessing
59111
}
60112
if latest.ko.Status.UpgradeProcessing != nil && *latest.ko.Status.UpgradeProcessing {
61113
msg := "Domain is currently upgrading software"
62114
ackcondition.SetSynced(desired, corev1.ConditionFalse, &msg, nil)
63-
return desired, requeueWaitWhileProcessing
115+
return latest, requeueWaitWhileProcessing
64116
}
65117

66118
if desired.ko.Spec.EngineVersion != nil && delta.DifferentAt("Spec.EngineVersion") {
@@ -185,6 +237,7 @@ func (rm *resourceManager) customUpdateDomain(ctx context.Context, desired, late
185237
}
186238
ko.Spec.AutoTuneOptions = &v1alpha1.AutoTuneOptionsInput{
187239
DesiredState: aws.String(string(resp.DomainConfig.AutoTuneOptions.Options.DesiredState)),
240+
UseOffPeakWindow: resp.DomainConfig.AutoTuneOptions.Options.UseOffPeakWindow,
188241
MaintenanceSchedules: maintSchedules,
189242
}
190243
} else {
@@ -205,11 +258,15 @@ func (rm *resourceManager) customUpdateDomain(ctx context.Context, desired, late
205258
}
206259
}
207260
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,
213270
}
214271
if resp.DomainConfig.ClusterConfig.Options.DedicatedMasterCount != nil {
215272
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
285342
} else {
286343
ko.Spec.EngineVersion = nil
287344
}
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+
}
288350
if resp.DomainConfig.NodeToNodeEncryptionOptions != nil {
289351
ko.Spec.NodeToNodeEncryptionOptions = &v1alpha1.NodeToNodeEncryptionOptions{
290352
Enabled: resp.DomainConfig.NodeToNodeEncryptionOptions.Options.Enabled,
291353
}
292354
} else {
293355
ko.Spec.NodeToNodeEncryptionOptions = nil
294356
}
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+
}
295392

296393
rm.setStatusDefaults(ko)
297394

@@ -401,6 +498,9 @@ func (rm *resourceManager) newCustomUpdateRequestPayload(
401498
if desired.ko.Spec.AutoTuneOptions.DesiredState != nil {
402499
f3.DesiredState = svcsdktypes.AutoTuneDesiredState(*desired.ko.Spec.AutoTuneOptions.DesiredState)
403500
}
501+
if desired.ko.Spec.AutoTuneOptions.UseOffPeakWindow != nil {
502+
f3.UseOffPeakWindow = desired.ko.Spec.AutoTuneOptions.UseOffPeakWindow
503+
}
404504
if desired.ko.Spec.AutoTuneOptions.MaintenanceSchedules != nil {
405505
f3f1 := []svcsdktypes.AutoTuneMaintenanceSchedule{}
406506
for _, f3f1iter := range desired.ko.Spec.AutoTuneOptions.MaintenanceSchedules {
@@ -471,6 +571,9 @@ func (rm *resourceManager) newCustomUpdateRequestPayload(
471571
if desired.ko.Spec.ClusterConfig.ZoneAwarenessEnabled != nil {
472572
f4.ZoneAwarenessEnabled = desired.ko.Spec.ClusterConfig.ZoneAwarenessEnabled
473573
}
574+
if desired.ko.Spec.ClusterConfig.MultiAZWithStandbyEnabled != nil {
575+
f4.MultiAZWithStandbyEnabled = desired.ko.Spec.ClusterConfig.MultiAZWithStandbyEnabled
576+
}
474577
res.ClusterConfig = f4
475578
}
476579

@@ -586,5 +689,59 @@ func (rm *resourceManager) newCustomUpdateRequestPayload(
586689
res.VPCOptions = f14
587690
}
588691

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+
589738
return res, nil
590739
}
740+
741+
func int64OrNil(num *int32) *int64 {
742+
if num == nil {
743+
return nil
744+
}
745+
746+
return aws.Int64(int64(*num))
747+
}

pkg/resource/domain/sdk.go

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/hooks/domain/sdk_read_one_post_set_output.go.tpl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
if resp.DomainStatus.AutoTuneOptions != nil {
2+
if ready, err := isAutoTuneOptionReady(resp.DomainStatus.AutoTuneOptions); err != nil {
3+
reason := err.Error()
4+
ackcondition.SetSynced(&resource{ko}, corev1.ConditionFalse, nil, &reason)
5+
} else if !ready {
6+
reason := fmt.Sprintf("waiting for AutotuneOptions to sync. Current state: %s", resp.DomainStatus.AutoTuneOptions.State)
7+
ackcondition.SetSynced(&resource{ko}, corev1.ConditionFalse, nil, &reason)
8+
}
9+
ko.Spec.AutoTuneOptions.DesiredState = aws.String(string(resp.DomainStatus.AutoTuneOptions.State))
10+
}
11+
112
if domainProcessing(&resource{ko}) {
213
// Setting resource synced condition to false will trigger a requeue of
314
// the resource. No need to return a requeue error here.

0 commit comments

Comments
 (0)