Skip to content

feat(instance): add securityGroupRefs - #406

Merged
ack-prow[bot] merged 3 commits into
aws-controllers-k8s:mainfrom
blacksoxx:instance-security-group-refs
Nov 11, 2026
Merged

ack-prow[bot] merged 3 commits into
aws-controllers-k8s:mainfrom
blacksoxx:instance-security-group-refs

Conversation

@blacksoxx

@blacksoxx blacksoxx commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Issue #, if available: aws-controllers-k8s/community#3132

Description of changes:

Instance had securityGroupIDs and securityGroups but no way to point at a SecurityGroup CR, so a group managed by ACK had to be created first and its ID copied into the Instance manifest. SecurityGroupIds now carries a reference to SecurityGroup (Status.ID), the way VpcEndpoint already does, which generates spec.securityGroupRefs with an optional namespace per entry, the resolver and the "either IDs or refs" validation.

Generated with code-generator v0.68.0 and controller-gen v0.19.0: the spec field, references, deepcopy and the CRD (config and helm copies). go build ./... and go test ./pkg/... pass. The new e2e test_security_group_ref creates a SecurityGroup CR in the shared VPC, launches an Instance that references it by name, and checks that the instance's groups in EC2 hold the group's ID while the CR keeps the reference and no securityGroupIDs is persisted, since the runtime clears resolved IDs before the spec patch. Not run locally.

networkInterfaces[].groups is left as is, as the issue allows.

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

SecurityGroupIds on Instance now carries a reference to SecurityGroup (Status.ID) the way VpcEndpoint does, so an Instance can point at a SecurityGroup CR by name instead of waiting for its ID. Generated with code-generator v0.67.0: spec field, resolver, deepcopy and CRD. The e2e launches an Instance that references a SecurityGroup CR and checks the group ID on both sides.

Signed-off-by: Youssef Omar Bouden <[email protected]>
@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 Nov 10, 2026
@ack-prow

ack-prow Bot commented Nov 10, 2026

Copy link
Copy Markdown

Hi @blacksoxx. 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.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

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.

Details

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-sigs/prow repository.

@gustavodiaz7722 gustavodiaz7722 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, the reference works as intended. I ran a controller built from this branch (rebased onto main, code-generator and runtime v0.68.0) against real EC2. The Instance launched with the referenced group, adding and removing a ref updated the instance's groups through ModifyInstanceAttribute, and setting both securityGroupIDs and securityGroupRefs was rejected.

Three things before merge:

  1. The e2e assertion on spec.securityGroupIDs fails (inline comment). The runtime clears resolved reference IDs before it patches the spec, so with securityGroupRefs set, spec.securityGroupIDs is never persisted. That is what aws-controllers-k8s/community#3132 asks for. In my run the same check raised KeyError: 'securityGroupIDs'. test_references.py already asserts this convention for the route table's gatewayID.
  2. The branch conflicts with #408 in apis/v1alpha1/ack-generate-metadata.yaml. Please rebase onto main and rerun make build-controller with code-generator v0.68.0. Regenerating this change on top of main with v0.68.0 gave the same generated files as this PR, so only the metadata file should change.
  3. Tide uses the PR description as the squash commit message. After the fixes, please update what it says the e2e checks and the code-generator version.

Comment thread test/e2e/tests/test_instance.py Outdated
assert k8s.wait_on_condition(ref, "ACK.ReferencesResolved", "True", wait_periods=5)

cr = k8s.get_resource(ref)
assert cr["spec"]["securityGroupIDs"] == [sg_id]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With securityGroupRefs set, spec.securityGroupIDs is never written back (the runtime runs ClearResolvedReferences before the spec patch), so this line raises KeyError. Suggest asserting that the ref is kept and the IDs are not:

Suggested change
assert cr["spec"]["securityGroupIDs"] == [sg_id]
assert "securityGroupIDs" not in cr["spec"]
assert cr["spec"]["securityGroupRefs"][0]["from"]["name"] == sg_name

@gustavodiaz7722

Copy link
Copy Markdown
Member

/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 Nov 10, 2026
…roup-refs

# Conflicts:
#	apis/v1alpha1/ack-generate-metadata.yaml
…isted

The runtime clears resolved reference IDs before it patches the spec, so with securityGroupRefs set spec.securityGroupIDs never lands in the CR; the e2e now checks the ref stays and the IDs field is absent. Regenerated with code-generator v0.68.0 on top of main: only the metadata changed.

Signed-off-by: Youssef Omar Bouden <[email protected]>
@gustavodiaz7722

Copy link
Copy Markdown
Member

/LGTM

@ack-prow ack-prow Bot added the lgtm Indicates that a PR is ready to be merged. label Nov 11, 2026
@gustavodiaz7722

Copy link
Copy Markdown
Member

/label release/minor

@ack-prow ack-prow Bot added the release/minor Indicates this PR should trigger a minor version release on merge. label Nov 11, 2026
@ack-prow

ack-prow Bot commented Nov 11, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: blacksoxx, gustavodiaz7722

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

The pull request process is described here

Details 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 Nov 11, 2026
@ack-prow
ack-prow Bot merged commit d326d55 into aws-controllers-k8s:main Nov 11, 2026
10 checks passed
ack-prow Bot pushed a commit that referenced this pull request Nov 13, 2026
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. release/minor Indicates this PR should trigger a minor version release on merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants