Sub Resource manager Intial Implementation#687
Open
gustavodiaz7722 wants to merge 5 commits intoaws-controllers-k8s:mainfrom
Open
Sub Resource manager Intial Implementation#687gustavodiaz7722 wants to merge 5 commits intoaws-controllers-k8s:mainfrom
gustavodiaz7722 wants to merge 5 commits intoaws-controllers-k8s:mainfrom
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: gustavodiaz7722 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sub-Resource Manager Framework
Introduces a code generation framework for managing sub-resource fields on parent CRDs through dedicated manager types. Sub-resources are fields on a parent resource (e.g.
Spec.Policies,Spec.Tagson a Role) that are managed by separate AWS API operations rather than the parent's CRUD operations.Problem
Many AWS resources have fields managed by separate API calls. For example, IAM Role has
Policies(AttachRolePolicy/DetachRolePolicy),Tags(TagRole/UntagRole),InlinePolicies(PutRolePolicy/DeleteRolePolicy),PermissionsBoundary(PutRolePermissionsBoundary/DeleteRolePermissionsBoundary), andAssumeRolePolicyDocument(UpdateAssumeRolePolicy). Previously, each controller implemented custom Go code to sync these fields, leading to duplicated patterns across controllers.Solution
The code generator now produces sub-resource manager files automatically from
generator.yamlconfiguration. Each sub-resource gets its own package withsdk.go(generated CRUD operations),delta.go(field comparison), andmanager.go(conversion and sync logic).Configuration
Sub-resources are declared under
sub_resourcesingenerator.yamlwith amapperthat defines field mappings between parent and sub-resource CRDs:Special mapper tokens:
$item(list element),$item.Field(struct field access),$key/$value(map entries).Source Type System
The parent field's shape type is automatically detected and dispatched to type-specific templates:
SourceTypeScalar— single value (e.g. PermissionsBoundary)SourceTypeListScalar— list of scalars (e.g. Policies[]*string)SourceTypeListStruct— list of structs (e.g. Tags[]*Tag)SourceTypeMapScalar— map with scalar values (e.g. InlinePoliciesmap[string]*string)Batch Inference
The framework automatically detects when an SDK operation accepts multiple items per call (e.g.
TagRoletakesTags []*Tag) by checking if the mapper's$itemtarget is a list field on the sub-resource CRD. When batching is detected, the sync merges all create/update/delete items into a single SDK call instead of N individual calls.Key Changes
code-generator:
ManagerConfigwithmapperandread_field_pathconfigurationSourceTypeenum andSourceTypeInfowith automatic type detectionconvertFromParenttemplates (scalar, list_scalar, list_struct, map_scalar)sub_resource_manager.go.tpl(sync, Get, computeDelta, key)ResourceHookCodeBatchFieldPathinferencesdk_find_sub_resource_get.go.tpl,sdk_update_sub_resource_sync.go.tpl,sdk_delete_sub_resource_sync.go.tplupdated for unique manager variable namesiam-controller (reference implementation):
Testing
All 13 sub-resource e2e tests pass alongside the existing IAM controller test suite.