Skip to content

Conversation

kunhwiko
Copy link
Contributor

@kunhwiko kunhwiko commented Apr 5, 2024

Description of changes
The FirewallPolicyARN on the Firewall resource can be updatable through the AssociateFirewallPolicy API. This is something we're doing with our own local copy of this repo.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ack-prow ack-prow bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 5, 2024
@ack-prow ack-prow bot requested a review from a-hilaly April 5, 2024 22:46
@ack-prow ack-prow bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 5, 2024
Copy link

ack-prow bot commented Apr 5, 2024

Hi @kunhwiko. Thanks for your PR.

I'm waiting for a aws-controllers-k8s member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

build_hash: e8df4d5a4b86dea0e227786c2c3d213e5aeda97a
go_version: go1.22.0
version: v0.33.0
go_version: go1.21.0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

umm...? something I missed :D?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing critical (for code-gen), we just started using go 1.22.x :)

b *resource,
) {
// Sort subnet mappings such that they can be compared in a deterministic way.
customPreCompareSubnetMappings(a, b)
Copy link
Contributor Author

@kunhwiko kunhwiko Apr 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change doesn't actually have to do anything with making the FirewallPolicyARN updatable. I've noticed the same set of subnet mappings might be detected as "different" during updates because they're arranged in a different order.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! It appears that the AWS Firewall API sorts the resources behind the scenes. Ideally, we should avoid mutating the desired state here to maintain consistency. The common runtime patches back the Spec returned by an sdkUpdate, potentially sorting the SubnetMapping in the desired Spec.

Maybe we could create a new function called equalSubnetMapping and use that to detect if something change, regardless of the order?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@kunhwiko kunhwiko Apr 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@a-hilaly Ahh makes sense! If the spec gets patched by sdkUpdate, that might end up in an OutOfSync issue for folks using GitOps.

Hmm problem though is if we don't sort here, the controller ends up picking up a diff later on in the delta function:

The above is code-gened, so I think there's little control over what we can do there...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What we need to do is to figure out whether the SubnetMapping changed or not without sorting and usinf reflect.DeepEqual. In general we can do:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh sweet, was not aware of compare.is_ignored. that'll work, thanks!

pass
assert cr["status"]["firewall"]["firewallPolicyARN"] == policy_arn

@pytest.fixture
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed to use this function twice in simple_firewall...so had to stop using this as a fixture

@kunhwiko kunhwiko marked this pull request as ready for review April 6, 2024 00:34
@ack-prow ack-prow bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 6, 2024
@a-hilaly
Copy link
Member

a-hilaly commented Apr 8, 2024

/ok-to-test

@ack-prow ack-prow bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 8, 2024
Copy link
Member

@a-hilaly a-hilaly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @kunhwiko ! Left a comment in-line

build_hash: e8df4d5a4b86dea0e227786c2c3d213e5aeda97a
go_version: go1.22.0
version: v0.33.0
go_version: go1.21.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing critical (for code-gen), we just started using go 1.22.x :)

b *resource,
) {
// Sort subnet mappings such that they can be compared in a deterministic way.
customPreCompareSubnetMappings(a, b)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! It appears that the AWS Firewall API sorts the resources behind the scenes. Ideally, we should avoid mutating the desired state here to maintain consistency. The common runtime patches back the Spec returned by an sdkUpdate, potentially sorting the SubnetMapping in the desired Spec.

Maybe we could create a new function called equalSubnetMapping and use that to detect if something change, regardless of the order?

Copy link
Member

@a-hilaly a-hilaly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks a lot @kunhwiko !
/lgtm

@ack-prow ack-prow bot added the lgtm Indicates that a PR is ready to be merged. label Apr 22, 2024
Copy link

ack-prow bot commented Apr 22, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: a-hilaly, kunhwiko

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ack-prow ack-prow bot added the approved label Apr 22, 2024
@a-hilaly
Copy link
Member

/test all

@ack-prow ack-prow bot merged commit 527f748 into aws-controllers-k8s:main Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants