-
Notifications
You must be signed in to change notification settings - Fork 226
replace nested field SecretKeyReference GoType #49
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
replace nested field SecretKeyReference GoType #49
Conversation
|
/approve |
|
/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.
/lgtm
In this patch, we post-process the `pkg/model.TypeDef` objects that are constructed by the code generator for nested fields of type "structure". This post-processing is used to replace the GoType of an Attr representing a Secret field in a nested parent field. For example, the AmazonMQ `Broker` resource has a `Spec.Users` top-level field. This top-level field is of type `[]*User`. The `User` Go struct type is constructed from a `pkg/model.TypeDef` object that describes the struct's attributes. One of those struct attributes is called `Password`, and we want to replace the Go type for this `Attr` from `string` to `*ackv1alpha1.SecretKeyReference`. In order to do this Go type replacement, we need to search through the TypeDef objects, looking for the parent field TypeDef, then look through that TypeDef's Attr collection for the Attr with the same name as our Field that has a FieldConfig.IsSecret setting of `true`. Issue aws-controllers-k8s/community#743
f2591ca to
6b6f1c2
Compare
|
New changes are detected. LGTM label has been removed. |
|
I was trying to regenerate ecr with a fake secret field - I have two comments regarding the sdk and crd templates:
|
Yes, good callout. I will update in the morning.
Yep. ++ |
|
@a-hilaly great callouts on your review. I've addressed both of them in the latest commits on this PR. Thanks for your review again! |
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.
Neat! I like the 5a5300d commit 👍
I left two non blocking comments
| // pointer to a struct... | ||
| goPkgType = goPkgType[1:] | ||
| } | ||
| pkg := strings.Split(goPkgType, ".")[0] |
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.
goPkgType is not used anymore - we can remove the block above
pkg/generate/code/set_sdk.go
Outdated
| if r.IsSecretField(memberName) { | ||
| out += setSDKForSecret( | ||
| cfg, r, | ||
| memberName, | ||
| targetVarName, | ||
| sourceAdaptedVarName, | ||
| indentLevel, | ||
| ) | ||
| continue | ||
| } | ||
|
|
||
| if r.IsSecretField(memberName) { | ||
| out += setSDKForSecret( | ||
| cfg, r, | ||
| memberName, | ||
| targetVarName, | ||
| sourceAdaptedVarName, | ||
| indentLevel, | ||
| ) | ||
| continue | ||
| } |
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.
Duplicate code :)
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.
oh, wow... copy pasta. Will fix ASAP. thank you!
This commit replaces the tracking of unique imported packages from the
processing of TypeDef structs by the code generator. Instead, we now
use the same technique to avoid import errors that we do in the `sdk.go`
code:
```go
import (
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
"github.com/aws/aws-sdk-go/aws"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// Hack to avoid import errors during build...
var (
_ = &metav1.Time{}
_ = &aws.JSONValue{}
_ = ackv1alpha1.AWSAccountID("")
)
```
The above is all the packages that are referenced by any type
definition's attribute fields that is collected by the code generator
during API inference.
Encapsulates the code that generates Go code for setting an SDK Input shape from the value of a SecretKeyReference in a separate `setSDKForSecret` function in `pkg/generate/code` and creates a `CRD.IsSecretField` that accepts a field path and returns whether the field at that field path is a SecretKeyReference.
Implements the `pkg/generate/code.SetSDK()` function for all nested fields that are SecretKeyReference types. This involved passing a field path down into the recursive `setSDKForXXX()` functions to keep track of where we were in the processing of nested fields. We look up whether a field is a SecretKeyReference by calling the `pkg/model.CRD:IsSecretField()` method, which accepts a field path, which is why we needed to pass this field path down into the recursive code generators. Issue aws-controllers-k8s/community#743
7fa1166 to
eef7ca5
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.
LGTM - let's 🚢 it!
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: A-Hilaly, jaypipes, RedbackThomson, vijtrip2 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
In this patch, we post-process the
pkg/model.TypeDefobjects that areconstructed by the code generator for nested fields of type "structure".
This post-processing is used to replace the GoType of an Attr
representing a Secret field in a nested parent field.
For example, the AmazonMQ
Brokerresource has aSpec.Userstop-levelfield. This top-level field is of type
[]*User. TheUserGo structtype is constructed from a
pkg/model.TypeDefobject that describes thestruct's attributes. One of those struct attributes is called
Password, and we want to replace the Go type for thisAttrfromstringto*ackv1alpha1.SecretKeyReference. In order to do this Gotype replacement, we need to search through the TypeDef objects, looking
for the parent field TypeDef, then look through that TypeDef's Attr
collection for the Attr with the same name as our Field that has a
FieldConfig.IsSecret setting of
true.Issue aws-controllers-k8s/community#743
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.