-
Notifications
You must be signed in to change notification settings - Fork 226
Extend ack-generate to generate slice with elements of type K8s Secret #87
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
Extend ack-generate to generate slice with elements of type K8s Secret #87
Conversation
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.
LGTM
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.
This is awesomesauce, @kumargauravsharma :) I have one question and a small suggestion inline, but overall this looks great.
pkg/generate/code/set_sdk.go
Outdated
memberShapeRef, _ := inputShape.MemberRefs[memberName] | ||
memberShape := memberShapeRef.Shape | ||
|
||
if r.IsSecretField(memberName) && |
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.
Instead of adding the additional conditionals here, how about we move this block of code:
if r.IsSecretFieildmemberName) {
...
}
down to original line 341, right below this:
default:
which is the code block that executes for scalar field types.
We could clean up the setSDKForSecret
function to remove the if XXX != nil
{` guard from here:
code-generator/pkg/generate/code/set_sdk.go
Lines 816 to 820 in cac5654
// if ko.Spec.MasterUserPassword != nil { | |
out += fmt.Sprintf( | |
"%sif %s != nil {\n", | |
indent, sourceVarName, | |
) |
and here:
code-generator/pkg/generate/code/set_sdk.go
Line 842 in cac5654
out += fmt.Sprintf("%s}\n", indent) |
which would simplify both the setSDKForSecret
function a bit that way and clean this conditional up a bit.
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.
Thanks for the suggestion.
I have refactored the code in next revision.
out += fmt.Sprintf("%s\t}\n", indent) | ||
// if tmpSecret != "" { | ||
// res.SetMasterUserPassword(tmpSecret) | ||
// } |
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.
please update the above code comment to say something like this:
// if tmpSecret != "" {
// res.SetMasterUserPassword(tmpSecret)
// }
//
// or:
//
// if tmpSecret != "" {
// f3elem = tmpSecret
// }
//
// The second case is used when the SecretKeyReference field
// is a slice of `[]*string` in the original AWS API Input shape.
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.
Updated code comments.
sourceAttributePath := sourceFieldPath | ||
if targetShape.MemberRef.Shape.Type == "structure" { | ||
containerFieldName = targetFieldName | ||
sourceAttributePath = sourceFieldPath+"." |
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.
do we have a unit test that can stress this code path? I don't believe the unit test about User.Passwords will hit this.
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.
This path is unit tested in TestSetSDK_MQ_Broker_Create
test for Users field.
gt = "*metav1.Time" | ||
} else if fieldCfg != nil && fieldCfg.IsSecret { | ||
gt = "*ackv1alpha1.SecretKeyReference" | ||
gte = "SecretKeyReference" |
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.
good fix here. ++
…s Secret Related issue: aws-controllers-k8s/community#828 With this code change, when a field of type slice is configured as secret type inside Generator config, then the generated CRD yaml allows specifying multiple k8s secret values for that field in input yaml and generated sdk code supplies these values to the resource API input field as slice type.
ad7a8d2
to
a8e7770
Compare
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.
Rock on :)
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: jaypipes, kumargauravsharma, nmvk The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Issue: aws-controllers-k8s/community#828
Description of changes:
With this code change, when a field of type slice
is configured as secret type inside Generator config,
then the generated CRD yaml allows specifying multiple k8s secret values
for that field in input yaml and generated sdk code supplies these values
to the resource API input field as slice type.
Added unit tests to test the scenario.
Details on resultant generated code:
Taking ElastiCache User API has
passwords
filed as example:ElastiCache User API has
passwords
filed of type[]*string
in the API input. Reference API docsWhen this field is configured as secret type inside Generator config:
and service controller code is generated with changes from this PR then,
the generated CRD yaml for password field is:
Observe that the password field is
array
type with K8s Secreret as element typeand User resource sdk.go file contain following code for password field while setting the inputs:
Observe that it supplies the secrets values as slice type to the input API.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Testing:
make test
passed forcode-generator
which contained already existing tests for secret fields code generation scenarios for MQ, ElastiCache ReplicationGroup.make test
passed for ElastiCache ACK controller generated code.