Feat/field manager#694
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 |
|
@gustavodiaz7722: The following tests failed, say
Full PR test history. Your PR dashboard. 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. I understand the commands that are listed here. |
feat: Add field manager for managing fields with separate API operations
Summary
Introduces the field manager pattern to the ACK code generator. This allows a parent resource to declare fields whose lifecycle (create, update, delete, read) is managed by separate AWS API operations, without exposing those fields as standalone Kubernetes CRDs.
For example, a
BackupVaultresource can declareAccessPolicy,Notifications, andLockConfigurationas managed fields. Each gets its own generated manager package that handles CRUD via dedicated API operations (PutBackupVaultAccessPolicy,DeleteBackupVaultAccessPolicy, etc.), while the user interacts with a singleBackupVaultCR.generator.yaml interface
Managed fields are defined inline on individual fields using the
managerkey:The
managerblock accepts the same configuration as a top-level resource (hooks,renames,exceptions,fields,find_operation, etc.), scoped to the managed field's own operations.What the code generator produces
For each managed field, the code generator creates a package under
pkg/resource/<parent>/<field>/:manager.goNewManager(),Sync(),Get(), delta computation, singleton logicsdk.gosdkFind(),sdkCreate(),sdkDelete(), request payload buildersdelta.gocompare.is_ignoredOn the parent side, generated code is injected into:
sdkCreate— marks resource unsynced if managed field spec is non-nil (forces reconcile loop)sdkFind— callsGet()on each field manager to populate parent specsdkUpdate— callsSync()whendelta.DifferentAt("Spec.<Field>"), short-circuits if only managed fields changedsdkDelete— syncs each managed field with nil desired state before deleting parentAuto-inference
Operations
The code generator automatically infers API operation bindings from the SDK model using naming conventions. For parent
Fooand managed fieldBar, it tries suffixes in preference order:{Verb}{Parent}{Field}— e.g.PutBackupVaultLockConfiguration{Verb}{Field}— e.g.PutNotifications{Verb}{Parent}{Singular}— e.g.TagBackupVault{Verb}{Singular}— e.g.TagResource{Verb}Resource— generic fallbackWith verb prefixes per operation type:
Put,Create,Set,TagDelete,Remove,UntagGet,Describe,ListExplicit
operations:entries in generator.yaml always take precedence.Primary keys
The parent's primary key is automatically propagated to each managed field. The original SDK field name is resolved by reverse-looking up the parent's renames (e.g. parent renames
BackupVaultName→Name, so the managed field getsBackupVaultNameas its primary key). The injected field config carriesis_primary_key: true,go_tag: json:"-", andcompare.is_ignored: true.Config layer changes
FieldManagerConfigtype (embedsResourceConfig)Manager *FieldManagerConfigfield onFieldConfig(YAML key:manager)NormalizeManagedFields()promotes field-levelmanagerconfigs into the internalManagedFieldsmapInferManagedFieldOperations()auto-discovers SDK operationsInferManagedFieldPrimaryKeys()auto-derives primary keys from parentGetManagedFields(),IsManagedField(),GetFieldManagerConfig(),GetParentResourceName()Template files added
field_manager.go.tpl— main manager scaffoldfield_manager_singleton.go.tpl— singleton pattern (key, sync, Get, convertFromParent)sdk_create_field_manager_requeue.go.tpl— requeue on createsdk_update_field_manager_sync.go.tpl— sync on updatesdk_delete_field_manager_sync.go.tpl— cleanup on deletesdk_find_field_manager_get.go.tpl— populate on findTesting
inferManagedFieldOpscovering 12 scenarios: standard patterns, prefix preference, singular forms, generic Resource suffix, explicit binding preservation, partial matches, and no-match cases