Skip to content

Commit e69ba89

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

File tree

5 files changed

+216
-17
lines changed

5 files changed

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

+136-7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package domain
1616
import (
1717
"context"
1818
"errors"
19+
"fmt"
1920

2021
"github.com/aws-controllers-k8s/opensearchservice-controller/apis/v1alpha1"
2122
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
@@ -46,21 +47,44 @@ func domainProcessing(r *resource) bool {
4647
return *r.ko.Status.Processing
4748
}
4849

50+
func isAutoTuneOptionReady(state string, errorMessage *string) (bool, error) {
51+
switch svcsdktypes.AutoTuneState(state) {
52+
case svcsdktypes.AutoTuneStateEnabled, svcsdktypes.AutoTuneStateDisabled:
53+
return true, nil
54+
55+
case svcsdktypes.AutoTuneStateError:
56+
if errorMessage != nil {
57+
return false, fmt.Errorf("error: %s", *errorMessage)
58+
}
59+
return false, fmt.Errorf("there is an error when updating AutoTuneOptions")
60+
61+
default:
62+
return false, nil
63+
}
64+
}
65+
4966
func (rm *resourceManager) customUpdateDomain(ctx context.Context, desired, latest *resource,
5067
delta *ackcompare.Delta) (updated *resource, err error) {
5168
rlog := ackrtlog.FromContext(ctx)
5269
exit := rlog.Trace("rm.customUpdateDomain")
5370
defer exit(err)
5471

72+
if latest.ko.Spec.AutoTuneOptions != nil &&
73+
latest.ko.Spec.AutoTuneOptions.DesiredState != nil {
74+
if ready, _ := isAutoTuneOptionReady(*latest.ko.Spec.AutoTuneOptions.DesiredState, nil); !ready {
75+
return latest, ackrequeue.Needed(fmt.Errorf("autoTuneOption is updating"))
76+
}
77+
}
78+
5579
if domainProcessing(latest) {
5680
msg := "Domain is currently processing configuration changes"
5781
ackcondition.SetSynced(desired, corev1.ConditionFalse, &msg, nil)
58-
return desired, requeueWaitWhileProcessing
82+
return latest, requeueWaitWhileProcessing
5983
}
6084
if latest.ko.Status.UpgradeProcessing != nil && *latest.ko.Status.UpgradeProcessing {
6185
msg := "Domain is currently upgrading software"
6286
ackcondition.SetSynced(desired, corev1.ConditionFalse, &msg, nil)
63-
return desired, requeueWaitWhileProcessing
87+
return latest, requeueWaitWhileProcessing
6488
}
6589

6690
if desired.ko.Spec.EngineVersion != nil && delta.DifferentAt("Spec.EngineVersion") {
@@ -185,6 +209,7 @@ func (rm *resourceManager) customUpdateDomain(ctx context.Context, desired, late
185209
}
186210
ko.Spec.AutoTuneOptions = &v1alpha1.AutoTuneOptionsInput{
187211
DesiredState: aws.String(string(resp.DomainConfig.AutoTuneOptions.Options.DesiredState)),
212+
UseOffPeakWindow: resp.DomainConfig.AutoTuneOptions.Options.UseOffPeakWindow,
188213
MaintenanceSchedules: maintSchedules,
189214
}
190215
} else {
@@ -205,11 +230,15 @@ func (rm *resourceManager) customUpdateDomain(ctx context.Context, desired, late
205230
}
206231
}
207232
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,
233+
ColdStorageOptions: csOptions,
234+
DedicatedMasterCount: int64OrNil(resp.DomainConfig.ClusterConfig.Options.DedicatedMasterCount),
235+
DedicatedMasterEnabled: resp.DomainConfig.ClusterConfig.Options.DedicatedMasterEnabled,
236+
InstanceCount: int64OrNil(resp.DomainConfig.ClusterConfig.Options.InstanceCount),
237+
WarmCount: int64OrNil(resp.DomainConfig.ClusterConfig.Options.WarmCount),
238+
WarmEnabled: resp.DomainConfig.ClusterConfig.Options.WarmEnabled,
239+
ZoneAwarenessConfig: zaConfig,
240+
ZoneAwarenessEnabled: resp.DomainConfig.ClusterConfig.Options.ZoneAwarenessEnabled,
241+
MultiAZWithStandbyEnabled: resp.DomainConfig.ClusterConfig.Options.MultiAZWithStandbyEnabled,
213242
}
214243
if resp.DomainConfig.ClusterConfig.Options.DedicatedMasterCount != nil {
215244
ko.Spec.ClusterConfig.DedicatedMasterCount = aws.Int64(int64(*resp.DomainConfig.ClusterConfig.Options.DedicatedMasterCount))
@@ -285,13 +314,53 @@ func (rm *resourceManager) customUpdateDomain(ctx context.Context, desired, late
285314
} else {
286315
ko.Spec.EngineVersion = nil
287316
}
317+
if resp.DomainConfig.IPAddressType != nil {
318+
ko.Spec.IPAddressType = aws.String(string(resp.DomainConfig.IPAddressType.Options))
319+
} else {
320+
ko.Spec.IPAddressType = nil
321+
}
288322
if resp.DomainConfig.NodeToNodeEncryptionOptions != nil {
289323
ko.Spec.NodeToNodeEncryptionOptions = &v1alpha1.NodeToNodeEncryptionOptions{
290324
Enabled: resp.DomainConfig.NodeToNodeEncryptionOptions.Options.Enabled,
291325
}
292326
} else {
293327
ko.Spec.NodeToNodeEncryptionOptions = nil
294328
}
329+
if resp.DomainConfig.SoftwareUpdateOptions != nil {
330+
ko.Spec.SoftwareUpdateOptions = &v1alpha1.SoftwareUpdateOptions{
331+
AutoSoftwareUpdateEnabled: resp.DomainConfig.SoftwareUpdateOptions.Options.AutoSoftwareUpdateEnabled,
332+
}
333+
} else {
334+
ko.Spec.SoftwareUpdateOptions = nil
335+
}
336+
if resp.DomainConfig.AIMLOptions != nil && resp.DomainConfig.AIMLOptions.Options != nil {
337+
if resp.DomainConfig.AIMLOptions.Options.NaturalLanguageQueryGenerationOptions != nil {
338+
ko.Spec.AIMLOptions = &v1alpha1.AIMLOptionsInput{
339+
NATuralLanguageQueryGenerationOptions: &v1alpha1.NATuralLanguageQueryGenerationOptionsInput{
340+
DesiredState: aws.String(string(resp.DomainConfig.AIMLOptions.Options.NaturalLanguageQueryGenerationOptions.DesiredState)),
341+
},
342+
}
343+
}
344+
} else {
345+
ko.Spec.AIMLOptions = nil
346+
}
347+
if resp.DomainConfig.OffPeakWindowOptions != nil && resp.DomainConfig.OffPeakWindowOptions.Options != nil {
348+
var offPeakWindow *v1alpha1.OffPeakWindow
349+
if resp.DomainConfig.OffPeakWindowOptions.Options.OffPeakWindow != nil {
350+
offPeakWindow = &v1alpha1.OffPeakWindow{
351+
WindowStartTime: &v1alpha1.WindowStartTime{
352+
Hours: aws.Int64(resp.DomainConfig.OffPeakWindowOptions.Options.OffPeakWindow.WindowStartTime.Hours),
353+
Minutes: aws.Int64(resp.DomainConfig.OffPeakWindowOptions.Options.OffPeakWindow.WindowStartTime.Minutes),
354+
},
355+
}
356+
}
357+
ko.Spec.OffPeakWindowOptions = &v1alpha1.OffPeakWindowOptions{
358+
Enabled: resp.DomainConfig.OffPeakWindowOptions.Options.Enabled,
359+
OffPeakWindow: offPeakWindow,
360+
}
361+
} else {
362+
ko.Spec.OffPeakWindowOptions = nil
363+
}
295364

296365
rm.setStatusDefaults(ko)
297366

@@ -401,6 +470,9 @@ func (rm *resourceManager) newCustomUpdateRequestPayload(
401470
if desired.ko.Spec.AutoTuneOptions.DesiredState != nil {
402471
f3.DesiredState = svcsdktypes.AutoTuneDesiredState(*desired.ko.Spec.AutoTuneOptions.DesiredState)
403472
}
473+
if desired.ko.Spec.AutoTuneOptions.UseOffPeakWindow != nil {
474+
f3.UseOffPeakWindow = desired.ko.Spec.AutoTuneOptions.UseOffPeakWindow
475+
}
404476
if desired.ko.Spec.AutoTuneOptions.MaintenanceSchedules != nil {
405477
f3f1 := []svcsdktypes.AutoTuneMaintenanceSchedule{}
406478
for _, f3f1iter := range desired.ko.Spec.AutoTuneOptions.MaintenanceSchedules {
@@ -471,6 +543,9 @@ func (rm *resourceManager) newCustomUpdateRequestPayload(
471543
if desired.ko.Spec.ClusterConfig.ZoneAwarenessEnabled != nil {
472544
f4.ZoneAwarenessEnabled = desired.ko.Spec.ClusterConfig.ZoneAwarenessEnabled
473545
}
546+
if desired.ko.Spec.ClusterConfig.MultiAZWithStandbyEnabled != nil {
547+
f4.MultiAZWithStandbyEnabled = desired.ko.Spec.ClusterConfig.MultiAZWithStandbyEnabled
548+
}
474549
res.ClusterConfig = f4
475550
}
476551

@@ -586,5 +661,59 @@ func (rm *resourceManager) newCustomUpdateRequestPayload(
586661
res.VPCOptions = f14
587662
}
588663

664+
if desired.ko.Spec.IPAddressType != nil && delta.DifferentAt("Spec.IPAddressType") {
665+
res.IPAddressType = svcsdktypes.IPAddressType(*desired.ko.Spec.IPAddressType)
666+
}
667+
668+
if desired.ko.Spec.SoftwareUpdateOptions != nil && delta.DifferentAt("Spec.SoftwareUpdateOptions") {
669+
f15 := &svcsdktypes.SoftwareUpdateOptions{}
670+
if desired.ko.Spec.SoftwareUpdateOptions.AutoSoftwareUpdateEnabled != nil {
671+
f15.AutoSoftwareUpdateEnabled = desired.ko.Spec.SoftwareUpdateOptions.AutoSoftwareUpdateEnabled
672+
}
673+
res.SoftwareUpdateOptions = f15
674+
}
675+
676+
if desired.ko.Spec.AIMLOptions != nil && delta.DifferentAt("Spec.AIMLOptions") {
677+
f16 := &svcsdktypes.AIMLOptionsInput{}
678+
if desired.ko.Spec.AIMLOptions.NATuralLanguageQueryGenerationOptions != nil {
679+
f16f0 := &svcsdktypes.NaturalLanguageQueryGenerationOptionsInput{}
680+
if desired.ko.Spec.AIMLOptions.NATuralLanguageQueryGenerationOptions.DesiredState != nil {
681+
f16f0.DesiredState = svcsdktypes.NaturalLanguageQueryGenerationDesiredState(*desired.ko.Spec.AIMLOptions.NATuralLanguageQueryGenerationOptions.DesiredState)
682+
}
683+
f16.NaturalLanguageQueryGenerationOptions = f16f0
684+
}
685+
res.AIMLOptions = f16
686+
}
687+
688+
if desired.ko.Spec.OffPeakWindowOptions != nil && delta.DifferentAt("Spec.OffPeakWindowOptions") {
689+
f17 := &svcsdktypes.OffPeakWindowOptions{}
690+
if desired.ko.Spec.OffPeakWindowOptions.Enabled != nil {
691+
f17.Enabled = desired.ko.Spec.OffPeakWindowOptions.Enabled
692+
}
693+
if desired.ko.Spec.OffPeakWindowOptions.OffPeakWindow != nil {
694+
f17f1 := &svcsdktypes.OffPeakWindow{}
695+
if desired.ko.Spec.OffPeakWindowOptions.OffPeakWindow.WindowStartTime != nil {
696+
f17f1f1 := &svcsdktypes.WindowStartTime{}
697+
if desired.ko.Spec.OffPeakWindowOptions.OffPeakWindow.WindowStartTime.Hours != nil {
698+
f17f1f1.Hours = *desired.ko.Spec.OffPeakWindowOptions.OffPeakWindow.WindowStartTime.Hours
699+
}
700+
if desired.ko.Spec.OffPeakWindowOptions.OffPeakWindow.WindowStartTime.Minutes != nil {
701+
f17f1f1.Minutes = *desired.ko.Spec.OffPeakWindowOptions.OffPeakWindow.WindowStartTime.Minutes
702+
}
703+
f17f1.WindowStartTime = f17f1f1
704+
}
705+
f17.OffPeakWindow = f17f1
706+
}
707+
res.OffPeakWindowOptions = f17
708+
}
709+
589710
return res, nil
590711
}
712+
713+
func int64OrNil(num *int32) *int64 {
714+
if num == nil {
715+
return nil
716+
}
717+
718+
return aws.Int64(int64(*num))
719+
}

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(string(resp.DomainStatus.AutoTuneOptions.State), resp.DomainStatus.AutoTuneOptions.ErrorMessage); 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.

test/e2e/tests/test_domain.py

+56-8
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def es_7_9_domain(os_client, resources: BootstrapResources):
8787
)
8888
k8s.create_custom_resource(ref, resource_data)
8989
k8s.wait_resource_consumed_by_controller(ref)
90-
condition.assert_not_synced(ref)
90+
assert k8s.wait_on_condition(ref, "ACK.ResourceSynced", "False", wait_periods=10)
9191

9292
# An OpenSearch Domain gets its `DomainStatus.Created` field set to
9393
# `True` almost immediately, however the `DomainStatus.Processing` field
@@ -105,7 +105,7 @@ def es_7_9_domain(os_client, resources: BootstrapResources):
105105
logging.info(f"ES Domain {resource.name} creation succeeded and DomainStatus.Processing is now False")
106106

107107
time.sleep(CHECK_STATUS_WAIT_SECONDS)
108-
condition.assert_synced(ref)
108+
assert k8s.wait_on_condition(ref, "ACK.ResourceSynced", "True", wait_periods=10)
109109

110110
yield ref, resource
111111

@@ -144,14 +144,14 @@ def es_2d3m_multi_az_no_vpc_7_9_domain(os_client, resources: BootstrapResources)
144144
)
145145
k8s.create_custom_resource(ref, resource_data)
146146
k8s.wait_resource_consumed_by_controller(ref)
147-
condition.assert_not_synced(ref)
147+
assert k8s.wait_on_condition(ref, "ACK.ResourceSynced", "False", wait_periods=10)
148148

149149
domain.wait_until(ref.name, domain.processing_matches(False))
150150

151151
logging.info(f"ES Domain {resource.name} creation succeeded and DomainStatus.Processing is now False")
152152

153153
time.sleep(CHECK_STATUS_WAIT_SECONDS)
154-
condition.assert_synced(ref)
154+
assert k8s.wait_on_condition(ref, "ACK.ResourceSynced", "True", wait_periods=10)
155155

156156
yield ref, resource
157157

@@ -200,14 +200,14 @@ def es_2d3m_multi_az_vpc_2_subnet7_9_domain(os_client, resources: BootstrapResou
200200
)
201201
k8s.create_custom_resource(ref, resource_data)
202202
k8s.wait_resource_consumed_by_controller(ref)
203-
condition.assert_not_synced(ref)
203+
assert k8s.wait_on_condition(ref, "ACK.ResourceSynced", "False", wait_periods=10)
204204

205205
domain.wait_until(ref.name, domain.processing_matches(False))
206206

207207
logging.info(f"OpenSearch Domain {resource.name} creation succeeded and DomainStatus.Processing is now False")
208208

209209
time.sleep(CHECK_STATUS_WAIT_SECONDS)
210-
condition.assert_synced(ref)
210+
assert k8s.wait_on_condition(ref, "ACK.ResourceSynced", "True", wait_periods=10)
211211

212212
yield ref, resource
213213

@@ -244,7 +244,26 @@ def test_create_delete_es_7_9(self, es_7_9_domain):
244244
# now we will modify the engine version to test upgrades
245245
# similar to creating a new domain, this takes a long time, often 20+ minutes
246246
updates = {
247-
"spec": {"engineVersion": "Elasticsearch_7.10"},
247+
"spec": {
248+
"engineVersion": "Elasticsearch_7.10",
249+
"autoTuneOptions": {
250+
"useOffPeakWindow": False
251+
},
252+
"clusterConfig": {
253+
"multiAZWithStandbyEnabled": False
254+
},
255+
"offPeakWindowOptions": {
256+
"offPeakWindow": {
257+
"windowStartTime": {
258+
"hours": 23,
259+
"minutes": 30
260+
}
261+
}
262+
},
263+
"softwareUpdateOptions": {
264+
"autoSoftwareUpdateEnabled": True
265+
}
266+
}
248267
}
249268
k8s.patch_custom_resource(ref, updates)
250269

@@ -260,8 +279,37 @@ def test_create_delete_es_7_9(self, es_7_9_domain):
260279
time.sleep(CHECK_STATUS_WAIT_SECONDS)
261280
continue
262281
else:
263-
assert latest['DomainStatus']['EngineVersion'] == "Elasticsearch_7.10"
264282
break
283+
assert k8s.wait_on_condition(ref, "ACK.ResourceSynced", "True", wait_periods=10)
284+
cr = k8s.get_resource(ref)
285+
286+
assert latest['DomainStatus']['EngineVersion'] == "Elasticsearch_7.10"
287+
assert latest['DomainStatus']['OffPeakWindowOptions']["Enabled"] is True
288+
assert latest['DomainStatus']['OffPeakWindowOptions']["OffPeakWindow"]["WindowStartTime"]["Hours"] == 23
289+
assert latest['DomainStatus']['OffPeakWindowOptions']["OffPeakWindow"]["WindowStartTime"]["Minutes"] == 30
290+
assert latest['DomainStatus']['SoftwareUpdateOptions']["AutoSoftwareUpdateEnabled"] is True
291+
292+
assert "engineVersion" in cr["spec"]
293+
assert cr["spec"]["engineVersion"] == "Elasticsearch_7.10"
294+
295+
assert "autoTuneOptions" in cr["spec"]
296+
assert "useOffPeakWindow" in cr["spec"]["autoTuneOptions"]
297+
assert cr["spec"]["autoTuneOptions"]["useOffPeakWindow"] == False
298+
299+
assert "clusterConfig" in cr["spec"]
300+
assert "multiAZWithStandbyEnabled" in cr["spec"]["clusterConfig"]
301+
assert cr["spec"]["clusterConfig"]["multiAZWithStandbyEnabled"] == False
302+
303+
assert "offPeakWindowOptions" in cr["spec"]
304+
assert "enabled" in cr["spec"]["offPeakWindowOptions"]
305+
assert cr["spec"]["offPeakWindowOptions"]["enabled"] == True
306+
307+
assert "offPeakWindow" in cr["spec"]["offPeakWindowOptions"]
308+
assert "windowStartTime" in cr["spec"]["offPeakWindowOptions"]["offPeakWindow"]
309+
assert "hours" in cr["spec"]["offPeakWindowOptions"]["offPeakWindow"]["windowStartTime"]
310+
assert "minutes" in cr["spec"]["offPeakWindowOptions"]["offPeakWindow"]["windowStartTime"]
311+
assert cr["spec"]["offPeakWindowOptions"]["offPeakWindow"]["windowStartTime"]["hours"] == 23
312+
assert cr["spec"]["offPeakWindowOptions"]["offPeakWindow"]["windowStartTime"]["minutes"] == 30
265313

266314
def test_create_delete_es_2d3m_multi_az_no_vpc_7_9(self, es_2d3m_multi_az_no_vpc_7_9_domain):
267315
ref, resource = es_2d3m_multi_az_no_vpc_7_9_domain

0 commit comments

Comments
 (0)