Skip to content

Add sdkFind hook to retrieve ServerProperties, a required field #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions apis/v1alpha1/ack-generate-metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
ack_generate_info:
build_date: "2025-03-07T23:22:35Z"
build_hash: 5645e51ed3c413f616e1b929f1527a5139c44198
build_date: "2025-03-14T22:21:13Z"
build_hash: a326346bd3a6973254d247c9ab2dc76790c36241
go_version: go1.24.0
version: v0.43.2-3-g5645e51
version: v0.43.2
api_directory_checksum: 36fbfad1e0bff98a14b120ba292a7f6b4e546fb4
api_version: v1alpha1
aws_sdk_go_version: v1.32.6
generator_config_info:
file_checksum: c641b5dd9aa81f1f42655f2afe9fcfb9dc7de696
file_checksum: 76a24bb9624894530a21ecedf80641625d3040c9
original_file_name: generator.yaml
last_modification:
reason: API generation
3 changes: 3 additions & 0 deletions apis/v1alpha1/generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ resources:
is_ignored: true
tags:
ignore: true
hooks:
sdk_read_one_post_set_output:
template_path: hooks/configuration/sdk_read_one_post_set_output.go.tpl
Cluster:
renames:
operations:
Expand Down
3 changes: 3 additions & 0 deletions generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ resources:
is_ignored: true
tags:
ignore: true
hooks:
sdk_read_one_post_set_output:
template_path: hooks/configuration/sdk_read_one_post_set_output.go.tpl
Cluster:
renames:
operations:
Expand Down
11 changes: 11 additions & 0 deletions pkg/resource/configuration/sdk.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions templates/hooks/configuration/sdk_read_one_post_set_output.go.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
response, err := rm.sdkapi.DescribeConfigurationRevision(ctx, &svcsdk.DescribeConfigurationRevisionInput{
Arn: (*string)(ko.Status.ACKResourceMetadata.ARN),
Revision: ko.Status.LatestRevision.Revision,
})
rm.metrics.RecordAPICall("READ_ONE", "DescribeConfigurationRevision", err)
if err != nil {
return &resource{ko}, err
}
if response.ServerProperties != nil {
ko.Spec.ServerProperties = response.ServerProperties
}
9 changes: 9 additions & 0 deletions test/e2e/resources/configuration_adopt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: kafka.services.k8s.aws/v1alpha1
kind: Configuration
metadata:
name: $CONFIG_NAME
annotations:
services.k8s.aws/adoption-policy: adopt
services.k8s.aws/adoption-fields: "$ADOPTION_FIELDS"


2 changes: 2 additions & 0 deletions test/e2e/resources/configuration_simple.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ apiVersion: kafka.services.k8s.aws/v1alpha1
kind: Configuration
metadata:
name: $CONFIG_NAME
annotations:
services.k8s.aws/deletion-policy: $DELETION_POLICY
spec:
name: $CONFIG_NAME
kafkaVersions:
Expand Down
73 changes: 73 additions & 0 deletions test/e2e/tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def simple_config():
resource_name = random_suffix_name("my-config", 24)
replacements = REPLACEMENT_VALUES.copy()
replacements["CONFIG_NAME"] = resource_name
replacements["DELETION_POLICY"] = "delete"

resource_data = load_resource(
"configuration_simple", additional_replacements=replacements
Expand All @@ -61,6 +62,66 @@ def simple_config():
except:
pass

@pytest.fixture(scope="module")
def adoption_config():
resource_name = random_suffix_name("my-config", 24)
replacements = REPLACEMENT_VALUES.copy()
replacements["CONFIG_NAME"] = resource_name
replacements["DELETION_POLICY"] = "retain"

resource_data = load_resource(
"configuration_simple", additional_replacements=replacements
)

ref = k8s.CustomResourceReference(
CRD_GROUP,
CRD_VERSION,
CONFIG_RESOURCE_PLURAL,
resource_name,
namespace="default",
)
k8s.create_custom_resource(ref, resource_data)
cr = k8s.wait_resource_consumed_by_controller(ref)

assert cr is not None
assert k8s.get_resource_exists(ref)
time.sleep(CREATE_WAIT_SECONDS)

assert "status" in cr
assert "ackResourceMetadata" in cr["status"]
assert "arn" in cr["status"]["ackResourceMetadata"]
arn = cr["status"]["ackResourceMetadata"]["arn"]

#Delete with retain policy allows us to adopt same resource
_, deleted = k8s.delete_custom_resource(ref, 3, 10)
assert deleted

replacements["ADOPTION_FIELDS"] = f'{{\\\"arn\\\": \\\"{arn}\\\"}}'
resource_data = load_resource(
"configuration_adopt", additional_replacements=replacements
)

ref = k8s.CustomResourceReference(
CRD_GROUP,
CRD_VERSION,
CONFIG_RESOURCE_PLURAL,
resource_name,
namespace="default",
)
k8s.create_custom_resource(ref, resource_data)
cr = k8s.wait_resource_consumed_by_controller(ref)

assert cr is not None
assert k8s.get_resource_exists(ref)

yield (ref, cr)

try:
_, deleted = k8s.delete_custom_resource(ref, DELETE_WAIT_SECONDS)
assert deleted
except:
pass


@service_marker
@pytest.mark.canary
Expand Down Expand Up @@ -101,3 +162,15 @@ def test_crud(self, simple_config):

latest = get_by_arn(config_arn)
assert latest is None

def test_adopt(seld, adoption_config):
ref, cr = adoption_config
time.sleep(CREATE_WAIT_SECONDS)

assert "status" in cr
assert "ackResourceMetadata" in cr["status"]
assert "arn" in cr["status"]["ackResourceMetadata"]

assert "spec" in cr
assert "serverProperties" in cr["spec"]