Skip to content

Commit

Permalink
Fix: EC2 controller for vpcendpoint does not update status (#191)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nnbu authored May 22, 2024
1 parent 23161f5 commit 34439b0
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 6 deletions.
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-05-02T20:55:46Z"
build_date: "2024-05-22T16:42:26Z"
build_hash: 14cef51778d471698018b6c38b604181a6948248
go_version: go1.22.0
go_version: go1.21.1
version: v0.34.0
api_directory_checksum: 7fd395ceb7d5d8e35906991c7348d3498f384741
api_directory_checksum: 1b53401670898ce50e6d6cc8bfba6b63ea7d5683
api_version: v1alpha1
aws_sdk_go_version: v1.44.93
generator_config_info:
file_checksum: 21aa2c0035772a834102dcdac81a186fe148212c
file_checksum: 75820b9d685b38976cd9723a9435f119ab913245
original_file_name: generator.yaml
last_modification:
reason: API generation
4 changes: 4 additions & 0 deletions apis/v1alpha1/generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,12 @@ resources:
code: compareTags(delta, a, b)
sdk_create_post_build_request:
template_path: hooks/vpc_endpoint/sdk_create_post_build_request.go.tpl
sdk_create_post_set_output:
template_path: hooks/vpc_endpoint/sdk_create_post_set_output.go.tpl
sdk_delete_post_build_request:
template_path: hooks/vpc_endpoint/sdk_delete_post_build_request.go.tpl
sdk_read_many_post_set_output:
template_path: hooks/vpc_endpoint/sdk_read_many_post_set_output.go.tpl
sdk_file_end:
template_path: hooks/vpc_endpoint/sdk_file_end.go.tpl
update_operation:
Expand Down
4 changes: 4 additions & 0 deletions generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,12 @@ resources:
code: compareTags(delta, a, b)
sdk_create_post_build_request:
template_path: hooks/vpc_endpoint/sdk_create_post_build_request.go.tpl
sdk_create_post_set_output:
template_path: hooks/vpc_endpoint/sdk_create_post_set_output.go.tpl
sdk_delete_post_build_request:
template_path: hooks/vpc_endpoint/sdk_delete_post_build_request.go.tpl
sdk_read_many_post_set_output:
template_path: hooks/vpc_endpoint/sdk_read_many_post_set_output.go.tpl
sdk_file_end:
template_path: hooks/vpc_endpoint/sdk_file_end.go.tpl
update_operation:
Expand Down
19 changes: 19 additions & 0 deletions pkg/resource/vpc_endpoint/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@ import (
svcsdk "github.com/aws/aws-sdk-go/service/ec2"
)

// https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2/client/describe_vpc_endpoints.html
const (
StatusPendingAcceptance = "pendingAcceptance"
StatusPending = "pending"
StatusAvailable = "available"
StatusDeleting = "deleting"
StatusDeleted = "deleted"
StatusRejected = "rejected"
StatusFailed = "failed"
)

func vpcEndpointAvailable(r *resource) bool {
if r.ko.Status.State == nil {
return false
}
cs := *r.ko.Status.State
return cs == StatusAvailable
}

// addIDToDeleteRequest adds resource's Vpc Endpoint ID to DeleteRequest.
// Return error to indicate to callers that the resource is not yet created.
func addIDToDeleteRequest(r *resource,
Expand Down
14 changes: 14 additions & 0 deletions pkg/resource/vpc_endpoint/sdk.go

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

// Setting resource synced condition to false will trigger a requeue of
// the resource. No need to return a requeue error here.
ackcondition.SetSynced(&resource{ko}, corev1.ConditionFalse, nil, nil)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

if !vpcEndpointAvailable(&resource{ko}) {
// Setting resource synced condition to false will trigger a requeue of
// the resource. No need to return a requeue error here.
ackcondition.SetSynced(&resource{ko}, corev1.ConditionFalse, nil, nil)
} else {
ackcondition.SetSynced(&resource{ko}, corev1.ConditionTrue, nil, nil)
}
4 changes: 2 additions & 2 deletions test/e2e/tests/test_references.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ def test_references(self, ec2_client):
assert k8s.wait_on_condition(vpc_ref, "ACK.ResourceSynced", "True", wait_periods=5)
assert k8s.wait_on_condition(sg_ref, "ACK.ResourceSynced", "True", wait_periods=5)
assert k8s.wait_on_condition(subnet_ref, "ACK.ResourceSynced", "True", wait_periods=5)
assert k8s.wait_on_condition(vpc_endpoint_ref, "ACK.ResourceSynced", "True", wait_periods=5)
assert k8s.wait_on_condition(vpc_endpoint_ref, "ACK.ResourceSynced", "True", wait_periods=10)

assert k8s.wait_on_condition(sg_ref, "ACK.ReferencesResolved", "True", wait_periods=5)
assert k8s.wait_on_condition(subnet_ref, "ACK.ReferencesResolved", "True", wait_periods=5)
assert k8s.wait_on_condition(vpc_endpoint_ref, "ACK.ReferencesResolved", "True", wait_periods=5)
assert k8s.wait_on_condition(vpc_endpoint_ref, "ACK.ReferencesResolved", "True", wait_periods=10)

# Acquire resource IDs
vpc_endpoint_cr = k8s.get_resource(vpc_endpoint_ref)
Expand Down

0 comments on commit 34439b0

Please sign in to comment.