Add is_primary_key_optional config option for resources with no single primary key - #736
Conversation
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: knottnt The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/retest |
1 similar comment
|
/retest |
| // mutually-exclusive fields (for example, a policy keyed by name OR by | ||
| // resource ARN) so adoption succeeds with whichever field(s) the user | ||
| // supplies. | ||
| IsPrimaryKeyOptional bool `json:"is_primary_key_optional"` |
There was a problem hiding this comment.
nit: is_primary_key_optional: true is a silent no-op unless a field is also marked is_primary_key: true
There was a problem hiding this comment.
Hmm that's a good call. This could also be applied to auto-discovered primary fields.
There was a problem hiding this comment.
Good catch — addressed. is_primary_key_optional now also applies to auto-discovered primary keys, not just fields explicitly marked is_primary_key: true. The optional if ok guard is emitted in the FindPrimaryIdentifierFieldNames path too, so the flag is no longer a silent no-op when is_primary_key is unset. (It still has no effect for ARN primary keys, which have no alternate identifier to fall back to — noted in a code comment.) Added a dedicated test + testdata config for the auto-discovered case.
|
Removing the required-field guard leaves nothing asserting that any identifier was supplied. Observedcloudwatchlogs-controller#76 built from source and deployed to an EKS cluster, with three Every CR below intends to adopt
Both failing CRs had the ACK finalizer attached and the AWS-managed policy's full 10-statement document copied into their spec — statements governing live log delivery for unrelated workloads in the account: Note also that two CRs were simultaneously bound to the same AWS policy, each believing it owned it. Why it does not fail safelyThe generated if elem.PolicyName != nil {
if ko.Spec.PolicyName != nil { // nil -> comparison skipped entirely
if *elem.PolicyName != *ko.Spec.PolicyName {
continue
}
}
ko.Spec.PolicyName = elem.PolicyName
}With This is specific to DeletionThe controller ran with the default Combined with the mis-adoption above, deleting a mis-adopted CR would delete the AWS-managed log delivery policy. That last step was deliberately not run — the two mis-adopted CRs were annotated |
@gustavodiaz7722 This is a good catch. Will need to test this, but I think what might be happening is when neither PolicyName or ResourceARN are set the DescribeResourcePolicies API returns with the default |
Issue #, if available:
Description of changes:
In some cases an AWS resource may have multiple potential identifiers with no single one serving as the primary. Currently out generate code for PopulateResourceFromAnnotation requires at least one field be identified as a primary key and will throw an error during adoption if it is not provided. For such resources this will either add an unnecessary requirement or actually prevent adoption if they identifiers are mutually exclusive.
The motivating resource for this feature is ResourcePolicy for cloudwatch logs. This resource can identified by two mutually exclusive primary keys (
policyNamefor account-wide andresourceARNfor resource scoped). See aws-controllers-k8s/cloudwatchlogs-controller#76By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.