Skip to content

Commit 65970fb

Browse files
nnbuNishant Burte
authored and
Nishant Burte
committed
Fix: EC2 controller for vpcendpoint does not update status (aws-controllers-k8s#191)
Issue : aws-controllers-k8s/community#2075 Description of changes: The issue is that vpce CR status is not updated. This happens because when vpce is created, it takes around a minute for it to be created in aws. Due to this, it's status is kept `pending`. But there is no sync enforced on the reconciler. Due to this, reconciliation happens after 10h default time. At this time, status would be set correctly. This fix enforces reconciliation to make sure CR is updated correctly when vpce creation in aws is successful. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 9ab50d1 commit 65970fb

File tree

8 files changed

+59
-6
lines changed

8 files changed

+59
-6
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
ack_generate_info:
2-
build_date: "2024-05-02T20:55:46Z"
2+
build_date: "2024-05-22T16:42:26Z"
33
build_hash: 14cef51778d471698018b6c38b604181a6948248
4-
go_version: go1.22.0
4+
go_version: go1.21.1
55
version: v0.34.0
6-
api_directory_checksum: 7fd395ceb7d5d8e35906991c7348d3498f384741
6+
api_directory_checksum: 1b53401670898ce50e6d6cc8bfba6b63ea7d5683
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.44.93
99
generator_config_info:
10-
file_checksum: 21aa2c0035772a834102dcdac81a186fe148212c
10+
file_checksum: 75820b9d685b38976cd9723a9435f119ab913245
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

apis/v1alpha1/generator.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,12 @@ resources:
823823
code: compareTags(delta, a, b)
824824
sdk_create_post_build_request:
825825
template_path: hooks/vpc_endpoint/sdk_create_post_build_request.go.tpl
826+
sdk_create_post_set_output:
827+
template_path: hooks/vpc_endpoint/sdk_create_post_set_output.go.tpl
826828
sdk_delete_post_build_request:
827829
template_path: hooks/vpc_endpoint/sdk_delete_post_build_request.go.tpl
830+
sdk_read_many_post_set_output:
831+
template_path: hooks/vpc_endpoint/sdk_read_many_post_set_output.go.tpl
828832
sdk_file_end:
829833
template_path: hooks/vpc_endpoint/sdk_file_end.go.tpl
830834
update_operation:

generator.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,12 @@ resources:
823823
code: compareTags(delta, a, b)
824824
sdk_create_post_build_request:
825825
template_path: hooks/vpc_endpoint/sdk_create_post_build_request.go.tpl
826+
sdk_create_post_set_output:
827+
template_path: hooks/vpc_endpoint/sdk_create_post_set_output.go.tpl
826828
sdk_delete_post_build_request:
827829
template_path: hooks/vpc_endpoint/sdk_delete_post_build_request.go.tpl
830+
sdk_read_many_post_set_output:
831+
template_path: hooks/vpc_endpoint/sdk_read_many_post_set_output.go.tpl
828832
sdk_file_end:
829833
template_path: hooks/vpc_endpoint/sdk_file_end.go.tpl
830834
update_operation:

pkg/resource/vpc_endpoint/hooks.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,25 @@ import (
2424
svcsdk "github.com/aws/aws-sdk-go/service/ec2"
2525
)
2626

27+
// https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2/client/describe_vpc_endpoints.html
28+
const (
29+
StatusPendingAcceptance = "pendingAcceptance"
30+
StatusPending = "pending"
31+
StatusAvailable = "available"
32+
StatusDeleting = "deleting"
33+
StatusDeleted = "deleted"
34+
StatusRejected = "rejected"
35+
StatusFailed = "failed"
36+
)
37+
38+
func vpcEndpointAvailable(r *resource) bool {
39+
if r.ko.Status.State == nil {
40+
return false
41+
}
42+
cs := *r.ko.Status.State
43+
return cs == StatusAvailable
44+
}
45+
2746
// addIDToDeleteRequest adds resource's Vpc Endpoint ID to DeleteRequest.
2847
// Return error to indicate to callers that the resource is not yet created.
2948
func addIDToDeleteRequest(r *resource,

pkg/resource/vpc_endpoint/sdk.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
// Setting resource synced condition to false will trigger a requeue of
3+
// the resource. No need to return a requeue error here.
4+
ackcondition.SetSynced(&resource{ko}, corev1.ConditionFalse, nil, nil)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
if !vpcEndpointAvailable(&resource{ko}) {
3+
// Setting resource synced condition to false will trigger a requeue of
4+
// the resource. No need to return a requeue error here.
5+
ackcondition.SetSynced(&resource{ko}, corev1.ConditionFalse, nil, nil)
6+
} else {
7+
ackcondition.SetSynced(&resource{ko}, corev1.ConditionTrue, nil, nil)
8+
}

test/e2e/tests/test_references.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ def test_references(self, ec2_client):
118118
assert k8s.wait_on_condition(vpc_ref, "ACK.ResourceSynced", "True", wait_periods=5)
119119
assert k8s.wait_on_condition(sg_ref, "ACK.ResourceSynced", "True", wait_periods=5)
120120
assert k8s.wait_on_condition(subnet_ref, "ACK.ResourceSynced", "True", wait_periods=5)
121-
assert k8s.wait_on_condition(vpc_endpoint_ref, "ACK.ResourceSynced", "True", wait_periods=5)
121+
assert k8s.wait_on_condition(vpc_endpoint_ref, "ACK.ResourceSynced", "True", wait_periods=10)
122122

123123
assert k8s.wait_on_condition(sg_ref, "ACK.ReferencesResolved", "True", wait_periods=5)
124124
assert k8s.wait_on_condition(subnet_ref, "ACK.ReferencesResolved", "True", wait_periods=5)
125-
assert k8s.wait_on_condition(vpc_endpoint_ref, "ACK.ReferencesResolved", "True", wait_periods=5)
125+
assert k8s.wait_on_condition(vpc_endpoint_ref, "ACK.ReferencesResolved", "True", wait_periods=10)
126126

127127
# Acquire resource IDs
128128
vpc_endpoint_cr = k8s.get_resource(vpc_endpoint_ref)

0 commit comments

Comments
 (0)