Skip to content

Commit 0271c52

Browse files
authored
Fix AdoptedResource functionality for FlowLogs (#161)
Issue # : aws-controllers-k8s/community#1946 RCA: Following CR currently fails to adopt the existing FlowLog resource. ``` apiVersion: services.k8s.aws/v1alpha1 kind: AdoptedResource metadata: name: flowlog1 spec: aws: nameOrID: fl-xxxxxx kubernetes: group: ec2.services.k8s.aws kind: FlowLog metadata: name: flowlog-adopted namespace: default ``` The error ``` "error": "FlowLog.ec2.services.k8s.aws "my-resource" is invalid: [spec.resourceID: Required value, spec.resourceType: Required value]"} ``` comes from https://github.com/aws-controllers-k8s/runtime/blob/main/pkg/runtime/adoption_reconciler.go#L157 `SetIdentifiers` function needs to have code to fill up `required` values of the CR so as to solve this issue. Solution: 2 new fields are defined as `ResourceID` and `ResourceType` and they are initialized in `SetIdentifiers` function. These fields need to part of `additionalKeys` field of `AdoptedResource` CR for `FlowLog`. The new CR looks like, ``` apiVersion: services.k8s.aws/v1alpha1 kind: AdoptedResource metadata: name: flowlog1 spec: aws: nameOrID: fl-xxxxx additionalKeys: ResourceID: vpc-xxxxxx ResourceType: VPC kubernetes: group: ec2.services.k8s.aws kind: FlowLog metadata: name: flowlog-adopted namespace: default ``` By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 374304e commit 0271c52

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
ack_generate_info:
2-
build_date: "2023-12-06T21:00:34Z"
3-
build_hash: 1cc9b5172d3d1676af578a3411e8672698ec29ce
4-
go_version: go1.21.0
5-
version: 1cc9b51
6-
api_directory_checksum: d452bf19bfd1496aacdc215bf7cc9ea86c55c122
2+
build_date: "2023-12-06T21:43:43Z"
3+
build_hash: 892f29d00a4c4ad21a2fa32919921de18190979d
4+
go_version: go1.21.1
5+
version: v0.27.1
6+
api_directory_checksum: 6e2d850d97f2f72db31c9bef522eca4ab95b3fcd
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.44.93
99
generator_config_info:
10-
file_checksum: 86b3e3aa1ff4769894d475244d0cc5902bcb258f
10+
file_checksum: d10a62517f87bacf988184f8c454b90b42dee732
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

apis/v1alpha1/generator.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ resources:
340340
template_path: hooks/flow_log/sdk_read_many_post_build_request.go.tpl
341341
sdk_file_end:
342342
template_path: hooks/flow_log/sdk_file_end.go.tpl
343+
post_set_resource_identifiers:
344+
template_path: hooks/flow_log/post_set_resource_identifiers.go.tpl
343345
update_operation:
344346
custom_method_name: customUpdateFlowLog
345347
InternetGateway:

generator.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ resources:
340340
template_path: hooks/flow_log/sdk_read_many_post_build_request.go.tpl
341341
sdk_file_end:
342342
template_path: hooks/flow_log/sdk_file_end.go.tpl
343+
post_set_resource_identifiers:
344+
template_path: hooks/flow_log/post_set_resource_identifiers.go.tpl
343345
update_operation:
344346
custom_method_name: customUpdateFlowLog
345347
InternetGateway:

pkg/resource/flow_log/resource.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
if resourceID, ok := identifier.AdditionalKeys["resourceID"]; ok {
2+
r.ko.Spec.ResourceID = &resourceID
3+
}
4+
5+
if resourceType, ok := identifier.AdditionalKeys["resourceType"]; ok {
6+
r.ko.Spec.ResourceType = &resourceType
7+
}

0 commit comments

Comments
 (0)