Skip to content

Commit 24dc713

Browse files
authored
fix: Set missing fields during update cluster configuration (#89)
Issue [#2219](aws-controllers-k8s/community#2219) Description of changes: Set missing fields during domain update operation By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 984c983 commit 24dc713

File tree

5 files changed

+216
-32
lines changed

5 files changed

+216
-32
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: 158 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ package domain
1616
import (
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"
@@ -37,6 +39,27 @@ var (
3739
)
3840
)
3941

42+
func checkDomainStatus(resp *svcsdk.DescribeDomainOutput, ko *svcapitypes.Domain) {
43+
if resp.DomainStatus.AutoTuneOptions != nil {
44+
if ready, err := isAutoTuneOptionReady(string(resp.DomainStatus.AutoTuneOptions.State), resp.DomainStatus.AutoTuneOptions.ErrorMessage); err != nil {
45+
reason := err.Error()
46+
ackcondition.SetSynced(&resource{ko}, corev1.ConditionFalse, nil, &reason)
47+
} else if !ready {
48+
reason := fmt.Sprintf("waiting for AutotuneOptions to sync. Current state: %s", resp.DomainStatus.AutoTuneOptions.State)
49+
ackcondition.SetSynced(&resource{ko}, corev1.ConditionFalse, nil, &reason)
50+
}
51+
ko.Spec.AutoTuneOptions.DesiredState = aws.String(string(resp.DomainStatus.AutoTuneOptions.State))
52+
}
53+
54+
if domainProcessing(&resource{ko}) {
55+
// Setting resource synced condition to false will trigger a requeue of
56+
// the resource. No need to return a requeue error here.
57+
ackcondition.SetSynced(&resource{ko}, corev1.ConditionFalse, nil, nil)
58+
} else {
59+
ackcondition.SetSynced(&resource{ko}, corev1.ConditionTrue, nil, nil)
60+
}
61+
}
62+
4063
// domainProcessing returns true if the supplied domain is in a state of
4164
// processing
4265
func 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+
4988
func (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+
}

pkg/resource/domain/sdk.go

Lines changed: 1 addition & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
if domainProcessing(&resource{ko}) {
2-
// Setting resource synced condition to false will trigger a requeue of
3-
// the resource. No need to return a requeue error here.
4-
ackcondition.SetSynced(&resource{ko}, corev1.ConditionFalse, nil, nil)
5-
} else {
6-
ackcondition.SetSynced(&resource{ko}, corev1.ConditionTrue, nil, nil)
7-
}
8-
1+
checkDomainStatus(resp, ko)

0 commit comments

Comments
 (0)