Skip to content

Commit 92df571

Browse files
authored
fix: ensure Synced is generated (#49)
Issue [#2496](aws-controllers-k8s/community#2496) Description of changes: These changes address the following issues: * after creating a MountTarget, the Status gets stuck in `creating`. * the IPAddress never gets patched after a Create. Using the gnerator.yaml `synced` feature as a fix : By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 7f5acc0 commit 92df571

File tree

13 files changed

+50
-44
lines changed

13 files changed

+50
-44
lines changed

apis/v1alpha1/ack-generate-metadata.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ api_directory_checksum: 01de06bb7dff101d9ebdbc6e252f3e526b493fb2
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.32.6
99
generator_config_info:
10-
file_checksum: 8f51ccb0fdf00c0900f3cd0641fe851d5909686e
10+
file_checksum: 68ba2404c86e1c8b1f0bd0730312a146a6c4188f
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

apis/v1alpha1/generator.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ model_name: elasticfilesystem
2525
controller_name: efs
2626
resources:
2727
FileSystem:
28+
synced:
29+
when:
30+
- path: Status.LifeCycleState
31+
in: [ "available" ]
2832
fields:
2933
Backup:
3034
compare:
@@ -107,6 +111,10 @@ resources:
107111
type: string
108112
index: 30
109113
MountTarget:
114+
synced:
115+
when:
116+
- path: Status.LifeCycleState
117+
in: [ "available" ]
110118
tags:
111119
ignore: true
112120
fields:
@@ -127,8 +135,6 @@ resources:
127135
update_operation:
128136
custom_method_name: customUpdateMountTarget
129137
hooks:
130-
sdk_create_post_set_output:
131-
template_path: hooks/mount_target/sdk_create_post_set_output.go.tpl
132138
sdk_read_many_post_build_request:
133139
template_path: hooks/mount_target/sdk_read_many_post_build_request.go.tpl
134140
sdk_read_many_post_set_output:

generator.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ model_name: elasticfilesystem
2525
controller_name: efs
2626
resources:
2727
FileSystem:
28+
synced:
29+
when:
30+
- path: Status.LifeCycleState
31+
in: [ "available" ]
2832
fields:
2933
Backup:
3034
compare:
@@ -107,6 +111,10 @@ resources:
107111
type: string
108112
index: 30
109113
MountTarget:
114+
synced:
115+
when:
116+
- path: Status.LifeCycleState
117+
in: [ "available" ]
110118
tags:
111119
ignore: true
112120
fields:
@@ -127,8 +135,6 @@ resources:
127135
update_operation:
128136
custom_method_name: customUpdateMountTarget
129137
hooks:
130-
sdk_create_post_set_output:
131-
template_path: hooks/mount_target/sdk_create_post_set_output.go.tpl
132138
sdk_read_many_post_build_request:
133139
template_path: hooks/mount_target/sdk_read_many_post_build_request.go.tpl
134140
sdk_read_many_post_set_output:

pkg/resource/file_system/manager.go

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

pkg/resource/file_system/sdk.go

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/resource/mount_target/hooks.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,18 @@ func (rm *resourceManager) customUpdateMountTarget(
146146
rlog := ackrtlog.FromContext(ctx)
147147
exit := rlog.Trace("rm.sdkUpdate")
148148
defer func() { exit(err) }()
149+
updated = rm.concreteResource(desired.DeepCopy())
150+
updated.SetStatus(latest)
151+
if !mountTargetActive(updated) {
152+
return updated, requeueWaitState(updated)
153+
}
149154

150155
if delta.DifferentAt("Spec.SecurityGroups") {
151-
err := rm.putSecurityGroups(ctx, desired)
156+
err := rm.putSecurityGroups(ctx, updated)
152157
if err != nil {
153158
return nil, err
154159
}
155160
}
156161

157-
return desired, nil
162+
return updated, nil
158163
}

pkg/resource/mount_target/manager.go

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

pkg/resource/mount_target/sdk.go

Lines changed: 1 addition & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
if err := rm.setResourceAdditionalFields(ctx, ko); err != nil {
2-
return nil, err
3-
}
4-
if !filesystemActive(&resource{ko}) {
5-
return &resource{ko}, requeueWaitState(&resource{ko})
2+
return &resource{ko}, err
63
}

templates/hooks/mount_target/sdk_create_post_set_output.go.tpl

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
if err := rm.setResourceAdditionalFields(ctx, ko); err != nil {
2-
return nil, err
3-
}
4-
if !mountTargetActive(&resource{ko}) {
5-
return &resource{ko}, requeueWaitState(r)
2+
return &resource{ko}, err
63
}

test/e2e/resources/mount_target.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ metadata:
55
spec:
66
fileSystemID: $FILE_SYSTEM_ID
77
subnetID: $PRIVATE_SUBNET
8-
ipAddress: $IP_ADDRESS

test/e2e/tests/test_mount_target.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ def simple_mount_target(efs_client, simple_file_system):
4343
replacements = REPLACEMENT_VALUES.copy()
4444
replacements["MOUNT_TARGET_NAME"] = resource_name
4545
replacements["FILE_SYSTEM_ID"] = file_system_id
46-
replacements["IP_ADDRESS"] = "10.0.0.100"
4746

4847
# Load efs CR
4948
resource_data = load_efs_resource(
@@ -87,8 +86,12 @@ def simple_mount_target(efs_client, simple_file_system):
8786
@pytest.mark.canary
8887
class TestMountTarget:
8988
def test_create_delete(self, efs_client, simple_mount_target):
90-
(_, _, mount_target_id) = simple_mount_target
89+
(ref, _, mount_target_id) = simple_mount_target
9190
assert mount_target_id is not None
9291

9392
validator = EFSValidator(efs_client)
94-
assert validator.mount_target_exists(mount_target_id)
93+
assert validator.mount_target_exists(mount_target_id)
94+
95+
cr = k8s.get_resource(ref)
96+
assert 'spec' in cr
97+
assert 'ipAddress' in cr['spec']

0 commit comments

Comments
 (0)