-
Notifications
You must be signed in to change notification settings - Fork 226
Replace primary_identifier_field_name
with is_primary_key
#190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c458dcf
3100a75
bb98d9c
d6aada9
338f466
76f943c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -788,12 +788,14 @@ func SetResourceGetAttributes( | |
// that an ARN, ID or Name) and any other "additional keys" required for the AWS | ||
// service to uniquely identify the object. | ||
// | ||
// The method will attempt to use the `ReadOne` operation, if present, otherwise | ||
// will fall back to using `ReadMany`. If it detects the operation uses an ARN | ||
// to identify the resource it will read it from the metadata status field. | ||
// Otherwise it will use any fields with a matching name in the operation, | ||
// pulling from spec or status - requiring that exactly one of those fields is | ||
// marked as the "primary" identifier. | ||
// The method will attempt to look for the field denoted with a value of true | ||
// for `is_primary_key`, or will use the ARN if the resource has a value of true | ||
// for `is_arn_primary_key`. Otherwise, the method will attempt to use the | ||
// `ReadOne` operation, if present, falling back to using `ReadMany`. | ||
// If it detects the operation uses an ARN to identify the resource it will read | ||
// it from the metadata status field. Otherwise it will use any field with a | ||
// name that matches the primary identifier from the operation, pulling from | ||
// top-level spec or status fields. | ||
// | ||
// An example of code with no additional keys: | ||
// | ||
|
@@ -873,21 +875,42 @@ func SetResourceIdentifiers( | |
primaryKeyConditionalOut := "\n" | ||
primaryKeyConditionalOut += identifierNameOrIDGuardConstructor(sourceVarName, indentLevel) | ||
|
||
primaryCRField, primaryShapeField := FindPrimaryIdentifierFieldNames(cfg, r, op) | ||
if primaryShapeField == PrimaryIdentifierARNOverride { | ||
// if r.ko.Status.ACKResourceMetadata == nil { | ||
// r.ko.Status.ACKResourceMetadata = &ackv1alpha1.ResourceMetadata{} | ||
// } | ||
// r.ko.Status.ACKResourceMetadata.ARN = identifier.ARN | ||
arnOut := "\n" | ||
arnOut += ackResourceMetadataGuardConstructor(fmt.Sprintf("%s.Status", targetVarName), indentLevel) | ||
arnOut += fmt.Sprintf( | ||
"%s%s.Status.ACKResourceMetadata.ARN = %s.ARN\n", | ||
indent, targetVarName, sourceVarName, | ||
) | ||
// if r.ko.Status.ACKResourceMetadata == nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's up with this commented out code ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a code sample for the generated code for the following block :) |
||
// r.ko.Status.ACKResourceMetadata = &ackv1alpha1.ResourceMetadata{} | ||
// } | ||
// r.ko.Status.ACKResourceMetadata.ARN = identifier.ARN | ||
arnOut := "\n" | ||
arnOut += ackResourceMetadataGuardConstructor(fmt.Sprintf("%s.Status", targetVarName), indentLevel) | ||
arnOut += fmt.Sprintf( | ||
"%s%s.Status.ACKResourceMetadata.ARN = %s.ARN\n", | ||
indent, targetVarName, sourceVarName, | ||
) | ||
|
||
// Check if the CRD defines the primary keys | ||
if r.IsARNPrimaryKey() { | ||
return arnOut | ||
} | ||
primaryField, err := r.GetPrimaryKeyField() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
var primaryCRField, primaryShapeField string | ||
isPrimarySet := primaryField != nil | ||
if isPrimarySet { | ||
memberPath, _ := findFieldInCR(cfg, r, primaryField.Names.Original) | ||
targetVarPath := fmt.Sprintf("%s%s", targetVarName, memberPath) | ||
primaryKeyOut += setResourceIdentifierPrimaryIdentifier(cfg, r, | ||
primaryField, | ||
targetVarPath, | ||
sourceVarName, | ||
indentLevel) | ||
} else { | ||
primaryCRField, primaryShapeField = FindPrimaryIdentifierFieldNames(cfg, r, op) | ||
if primaryShapeField == PrimaryIdentifierARNOverride { | ||
return arnOut | ||
} | ||
} | ||
|
||
paginatorFieldLookup := []string{ | ||
"NextToken", | ||
|
@@ -924,6 +947,11 @@ func SetResourceIdentifiers( | |
op.Name, memberName, | ||
) | ||
|
||
// Check to see if we've already set the field as the primary identifier | ||
if isPrimarySet && renamedName == primaryField.Names.Camel { | ||
continue | ||
} | ||
|
||
isPrimaryIdentifier := memberName == primaryShapeField | ||
|
||
searchField := "" | ||
|
@@ -934,7 +962,7 @@ func SetResourceIdentifiers( | |
} | ||
|
||
memberPath, targetField := findFieldInCR(cfg, r, searchField) | ||
if targetField == nil { | ||
if targetField == nil || (isPrimarySet && targetField == primaryField) { | ||
continue | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,11 +170,11 @@ type FieldConfig struct { | |
// Required indicates whether this field is a required member or not. | ||
// This field is used to configure '+kubebuilder:validation:Required' on API object's members. | ||
IsRequired *bool `json:"is_required,omitempty"` | ||
// IsName indicates the field represents the name/string identifier field | ||
// for the resource. This allows the generator config to override the | ||
// default behaviour of considering a field called "Name" or | ||
// IsPrimaryKey indicates the field represents the primary name/string | ||
// identifier field for the resource. This allows the generator config to | ||
// override the default behaviour of considering a field called "Name" or | ||
// "{Resource}Name" or "{Resource}Id" as the "name field" for the resource. | ||
IsName bool `json:"is_name"` | ||
IsPrimaryKey bool `json:"is_primary_key"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My local config has both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I did a global search for all service controllers using |
||
// IsOwnerAccountID indicates the field contains the AWS Account ID | ||
// that owns the resource. This is a special field that we direct to | ||
// storage in the common `Status.ACKResourceMetadata.OwnerAccountID` field. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ resources: | |
Repository: | ||
fields: | ||
Name: | ||
is_name: true | ||
is_primary_key: true | ||
exceptions: | ||
errors: | ||
404: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ApplicationAutoscaling does not utilize this, so I have not verified this snippet, looks ok though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SageMaker controller uses it (for ModelPackage). We have unit tests that cover it.