Skip to content

Commit 0304444

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

File tree

5 files changed

+247
-17
lines changed

5 files changed

+247
-17
lines changed

apis/v1alpha1/ack-generate-metadata.yaml

+2-2
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

+167-7
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,18 @@ 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+
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,
213273
}
214274
if resp.DomainConfig.ClusterConfig.Options.DedicatedMasterCount != nil {
215275
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
285345
} else {
286346
ko.Spec.EngineVersion = nil
287347
}
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+
}
288353
if resp.DomainConfig.NodeToNodeEncryptionOptions != nil {
289354
ko.Spec.NodeToNodeEncryptionOptions = &v1alpha1.NodeToNodeEncryptionOptions{
290355
Enabled: resp.DomainConfig.NodeToNodeEncryptionOptions.Options.Enabled,
291356
}
292357
} else {
293358
ko.Spec.NodeToNodeEncryptionOptions = nil
294359
}
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+
}
295395

296396
rm.setStatusDefaults(ko)
297397

@@ -401,6 +501,9 @@ func (rm *resourceManager) newCustomUpdateRequestPayload(
401501
if desired.ko.Spec.AutoTuneOptions.DesiredState != nil {
402502
f3.DesiredState = svcsdktypes.AutoTuneDesiredState(*desired.ko.Spec.AutoTuneOptions.DesiredState)
403503
}
504+
if desired.ko.Spec.AutoTuneOptions.UseOffPeakWindow != nil {
505+
f3.UseOffPeakWindow = desired.ko.Spec.AutoTuneOptions.UseOffPeakWindow
506+
}
404507
if desired.ko.Spec.AutoTuneOptions.MaintenanceSchedules != nil {
405508
f3f1 := []svcsdktypes.AutoTuneMaintenanceSchedule{}
406509
for _, f3f1iter := range desired.ko.Spec.AutoTuneOptions.MaintenanceSchedules {
@@ -471,6 +574,9 @@ func (rm *resourceManager) newCustomUpdateRequestPayload(
471574
if desired.ko.Spec.ClusterConfig.ZoneAwarenessEnabled != nil {
472575
f4.ZoneAwarenessEnabled = desired.ko.Spec.ClusterConfig.ZoneAwarenessEnabled
473576
}
577+
if desired.ko.Spec.ClusterConfig.MultiAZWithStandbyEnabled != nil {
578+
f4.MultiAZWithStandbyEnabled = desired.ko.Spec.ClusterConfig.MultiAZWithStandbyEnabled
579+
}
474580
res.ClusterConfig = f4
475581
}
476582

@@ -586,5 +692,59 @@ func (rm *resourceManager) newCustomUpdateRequestPayload(
586692
res.VPCOptions = f14
587693
}
588694

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+
589741
return res, nil
590742
}
743+
744+
func int64OrNil(num *int32) *int64 {
745+
if num == nil {
746+
return nil
747+
}
748+
749+
return aws.Int64(int64(*num))
750+
}

pkg/resource/domain/sdk.go

+11
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

+11
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)