feat: Add Accept Mode to ResourceShare CRD for cross-account sharing#44
feat: Add Accept Mode to ResourceShare CRD for cross-account sharing#44rhysxevans wants to merge 1 commit into
Conversation
This commit integrates resource share invitation acceptance functionality into the existing ResourceShare CRD, enabling dual-mode operation for cross-account AWS RAM sharing scenarios. ## Key Changes ### 1. Dual-Mode ResourceShare CRD - Added acceptInvitation field to enable Accept Mode - Made name field optional (required in Create Mode, not needed in Accept Mode) - Added invitation-specific status fields (invitationARN, invitationStatus, etc.) - Added resources field to status for tracking shared resources ### 2. Accept Mode Implementation - Implemented sdkAcceptInvitation() for accepting pending invitations - Implemented sdkFindAcceptedInvitation() for finding existing accepted invitations - Modified sdkCreate() to route to acceptance logic when acceptInvitation is set - Modified sdkFind() to route to invitation lookup in Accept Mode - Added validation to ensure name is provided in Create Mode ### 3. Deletion Handling - Implemented sdkRejectOrLeaveShare() for proper cleanup in Accept Mode - PENDING invitations: Rejected using RejectResourceShareInvitation - ACCEPTED invitations: Left using DisassociateResourceShare - Added graceful handling for OperationNotPermittedException (some resource types like Network Firewall don't support self-disassociation) ### 4. Deprecated API Replacement - Removed usage of deprecated ResourceShareAssociations field - Implemented populateInvitationResources() using ListPendingInvitationResources API - Added logging and metrics for resource population - Handles invitations with no resources gracefully ### 5. Documentation - Added comprehensive function-level documentation for Accept Mode - Documented AWS resource type limitations (Network Firewall, etc.) - Explained deletion behavior and OperationNotPermittedException handling - Added inline comments for error handling logic ### 6. E2E Tests - Created test_resource_share_accept_mode.py with Accept Mode tests - Added test for name validation in Create Mode - Added test templates for Accept Mode scenarios - Updated ram_resource_share.py with invitation helper functions ### 7. Examples - Added resource-share-integrated-modes.yaml with usage examples - Documented Create Mode and Accept Mode workflows - Included cross-account sharing examples ## Testing - ✅ Accept invitation with resources (Network Firewall) - ✅ Resources populated in status using new API - ✅ Deletion with OperationNotPermittedException handling - ✅ Name validation in Create Mode - ✅ All status fields populated correctly ## AWS Limitations Handled Some AWS resource types (e.g., Network Firewall) do not support self-disassociation. For these resources, the Kubernetes resource is deleted successfully, but the AWS invitation remains ACCEPTED until the share owner removes the principal. This is expected AWS behavior and is handled gracefully with appropriate logging. Addresses reviewer feedback on PR aws-controllers-k8s#43 regarding integrated vs separate CRD approach.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: rhysxevans The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @rhysxevans. 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 Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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. |
NOTE - Code has been generated using AI
Overview
This PR implements resource share invitation acceptance functionality by integrating it into the existing ResourceShare CRD rather than creating a separate ResourceShareAcceptor CRD. This approach was explored in response to reviewer feedback on PR #43 suggesting consideration of an integrated solution similar to EKS AccessPolicies.
Approach: Integrated vs Separate CRD
Integrated Approach (This PR)
Single CRD with dual-mode operation:
ResourceShareCRD operates in two modes based on spec fieldsspec.acceptInvitationfieldKey Differences from Separate CRD Approach
Implementation Details
1. CRD Changes
New Spec Fields
New Status Fields (Accept Mode only)
2. Controller Logic
Mode Detection
Accept Mode Operations
AcceptResourceShareInvitationGetResourceShareInvitations3. Deletion Handling
Two different deletion paths based on invitation status:
PENDING Invitations:
ACCEPTED Invitations:
4. AWS Limitation Handling
Problem: Some AWS resource types (e.g., Network Firewall) don't support self-disassociation.
Error from AWS:
Solution: Gracefully handle the error and allow Kubernetes resource deletion:
This prevents resources from getting stuck with finalizers while documenting the AWS limitation.
5. Deprecated API Replacement
Removed: Usage of deprecated
ResourceShareAssociationsfieldReplaced with:
ListPendingInvitationResourcesAPITesting Results
Test Scenario: Accept Invitation with Network Firewall Resource
Input:
arn:aws:ram:us-east-2:59211111111:resource-share/...Output After Acceptance:
Deletion Test:
Controller Logs
{"msg":"Fetching resources for invitation using ListPendingInvitationResources API"} {"msg":"Populated resources from invitation","resourceCount":1} {"msg":"Cannot leave resource share - resource type does not support self-disassociation"} {"msg":"deleted resource"}Validation
Name Field Validation
Added validation to ensure
nameis provided in Create Mode:Documentation
Code Documentation
Examples
Created
examples/resource-share-integrated-modes.yamlwith:E2E Tests
test_resource_share_accept_mode.pywith Accept Mode test casesTrade-offs Analysis
Advantages of Integrated Approach
Disadvantages of Integrated Approach
Advantages of Separate CRD Approach
Disadvantages of Separate CRD Approach
Recommendation
The integrated approach is recommended for the following reasons:
However, if the ACK project prefers explicit separation of concerns, the separate CRD approach is also valid and was the original implementation in PR #43.
Files Changed
apis/v1alpha1/resource_share.go- CRD definition with Accept Mode fieldspkg/resource/resource_share/sdk.go- Accept Mode implementationconfig/crd/bases/ram.services.k8s.aws_resourceshares.yaml- Generated CRDhelm/crds/ram.services.k8s.aws_resourceshares.yaml- Helm CRDtest/e2e/tests/test_resource_share_accept_mode.py- E2E testsexamples/resource-share-integrated-modes.yaml- Usage examplesTotal: 9 files changed, 992 insertions(+), 8 deletions(-)
Next Steps
Please review this integrated approach and provide feedback on:
I'm happy to adjust the implementation based on your feedback or revert to the separate CRD approach if preferred.
Issue #, if available: aws-controllers-k8s/community#2786
Description of changes:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.