Skip to content
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

Make Topic Name an immutable field #65

Merged
merged 1 commit into from
Oct 25, 2024
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: "2024-10-24T02:09:19Z"
build_hash: 36c2d234498c2bc4f60773ab8df632af4067f43b
build_date: "2024-10-25T16:48:58Z"
build_hash: ab15f9206796e9660c51695fab0ff07a09ea28e2
go_version: go1.23.2
version: v0.39.1
version: v0.39.1-2-gab15f92
api_directory_checksum: 07a2ec03f194442b69cf147a88a4cc33badaa895
api_version: v1alpha1
aws_sdk_go_version: v1.49.0
generator_config_info:
file_checksum: e95b5fd9a0571826102c9546eae4cc73228a8395
file_checksum: da7d9b038cf0421583a14109fe0e04628911ab69
original_file_name: generator.yaml
last_modification:
reason: API generation
2 changes: 2 additions & 0 deletions apis/v1alpha1/generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ resources:
sdk_get_attributes_post_set_output:
template_path: hooks/topic/sdk_get_attributes_post_set_output.go.tpl
fields:
Name:
is_immutable: true
TopicArn:
is_attribute: true
is_arn: true
Expand Down
2 changes: 2 additions & 0 deletions generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ resources:
sdk_get_attributes_post_set_output:
template_path: hooks/topic/sdk_get_attributes_post_set_output.go.tpl
fields:
Name:
is_immutable: true
TopicArn:
is_attribute: true
is_arn: true
Expand Down
4 changes: 3 additions & 1 deletion pkg/resource/platform_application/sdk.go

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

4 changes: 3 additions & 1 deletion pkg/resource/platform_endpoint/sdk.go

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

5 changes: 5 additions & 0 deletions pkg/resource/topic/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package topic
import (
"context"
"fmt"
"strings"

ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare"
Expand Down Expand Up @@ -60,6 +61,10 @@ func (rm *resourceManager) customUpdate(
defer func() {
exit(err)
}()
if immutableFieldChanges := rm.getImmutableFieldChanges(delta); len(immutableFieldChanges) > 0 {
msg := fmt.Sprintf("Immutable Spec fields have been modified: %s", strings.Join(immutableFieldChanges, ","))
return nil, ackerr.NewTerminalError(fmt.Errorf(msg))
}
if delta.DifferentAt("Spec.Tags") {
if err := rm.syncTags(ctx, desired, latest); err != nil {
return nil, err
Expand Down
24 changes: 17 additions & 7 deletions pkg/resource/topic/sdk.go

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

12 changes: 5 additions & 7 deletions templates/hooks/topic/sdk_get_attributes_pre_set_output.go.tpl
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@

// If the Name field is empty, populate it with the last part of the topic ARN
// Populate the name field with the last part of the topic ARN
// This is a workaround for the fact that the Name field is required by the
// CreateTopic API call, but not by the GetTopicAttributes API call
// Use case: adopting an existing topic by topic ARN
if ko.Spec.Name == nil {
topicName, err := rm.getTopicNameFromARN(tmpARN)
if err != nil {
return nil, err
}
ko.Spec.Name = &topicName
topicName, err := rm.getTopicNameFromARN(tmpARN)
if err != nil {
return nil, err
}
ko.Spec.Name = &topicName

13 changes: 13 additions & 0 deletions test/e2e/tests/test_topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,19 @@ def test_crud(self, simple_topic):
expect_after_update_tags, latest_tags,
)

updates = {
"spec": {"name": "my-simple-topic-edited"}
}
k8s.patch_custom_resource(ref, updates)
time.sleep(MODIFY_WAIT_AFTER_SECONDS)
k8s.wait_resource_consumed_by_controller(ref)
condition.assert_type_status(ref, condition.CONDITION_TYPE_TERMINAL)

expected_msg = "Immutable Spec fields have been modified: Name"
terminal_condition = k8s.get_resource_condition(ref, condition.CONDITION_TYPE_TERMINAL)
# The name is immutable, testing if we get a terminal error
assert expected_msg in terminal_condition['message']

def test_crud_fifo(self, fifo_topic):
ref, res = fifo_topic

Expand Down