-
Notifications
You must be signed in to change notification settings - Fork 226
update for default resource tags #335
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7032235
updated the default resource tags
vijtrip2 88aa3e1
Upgrade to runtime v0.19.0
9371653
update ACK runtime to v0.19.0
vijtrip2 4f2d4f0
update ResourceConfig to include TagsConfig
vijtrip2 8e01e12
add tagging methods inside model.CRD
vijtrip2 0f0f9ff
add new generator method to initialize nested structs
vijtrip2 9c2e73d
update templates to ensure ack tags
vijtrip2 21df70e
document the hooks for ensuring tags
vijtrip2 3ac2ae1
refactor model.GetIgnoreTagging -> config.TagsAreIgnored(resName)
vijtrip2 623f7e9
refactor crd.Tagging methods into pkg/model/tagging.go
vijtrip2 cc38201
determing Spec/Status prefix from inspecting the field
vijtrip2 4900b99
remove trailing newline from tags.go.tpl
vijtrip2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| // Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
| // not use this file except in compliance with the License. A copy of the | ||
| // License is located at | ||
| // | ||
| // http://aws.amazon.com/apache2.0/ | ||
| // | ||
| // or in the "license" file accompanying this file. This file is distributed | ||
| // on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| // express or implied. See the License for the specific language governing | ||
| // permissions and limitations under the License. | ||
|
|
||
| package code | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| "github.com/aws-controllers-k8s/code-generator/pkg/fieldpath" | ||
|
|
||
| "github.com/aws-controllers-k8s/code-generator/pkg/model" | ||
| ) | ||
|
|
||
| // InitializeNestedStructField returns the go code for initializing a nested | ||
| // struct field. Currently this method only supports the struct shape for | ||
| // nested elements. | ||
| // | ||
| // TODO(vijtrip2): Refactor the code out of set_resource.go for generating | ||
| // constructors and reuse here. This method is currently being used for handling | ||
| // nested Tagging fields. | ||
| // | ||
| // Example: generated code for "Logging.LoggingEnabled.TargetBucket" field | ||
| // inside "s3" "bucket" crd looks like: | ||
| // | ||
| // ``` | ||
| // r.ko.BucketLoggingStatus = &svcapitypes.BucketLoggingStatus{} | ||
vijtrip2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // r.ko.BucketLoggingStatus.LoggingEnabled = &svcapitypes.LoggingEnabled{} | ||
| // ``` | ||
|
|
||
vijtrip2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| func InitializeNestedStructField( | ||
| r *model.CRD, | ||
| sourceVarName string, | ||
| field *model.Field, | ||
| // apiPkgImportName contains the imported package name where the type definition | ||
| // for nested structs is present. | ||
| // ex: svcapitypes "github.com/aws-controllers-k8s/s3-controller/apis/v1alpha1" | ||
| apiPkgImportName string, | ||
vijtrip2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // Number of levels of indentation to use | ||
| indentLevel int, | ||
| ) string { | ||
| out := "" | ||
| indent := strings.Repeat("\t", indentLevel) | ||
| fieldPath := field.Path | ||
| if fieldPath != "" { | ||
| fp := fieldpath.FromString(fieldPath) | ||
| if fp.Size() > 1 { | ||
vijtrip2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // replace the front field name with front field shape name inside | ||
| // the field path to construct the fieldShapePath | ||
| front := fp.Front() | ||
| frontField := r.Fields[front] | ||
| if frontField == nil { | ||
| panic(fmt.Sprintf("unable to find the field with name %s"+ | ||
| " for fieldpath %s", front, fieldPath)) | ||
| } | ||
| if frontField.ShapeRef == nil { | ||
| panic(fmt.Sprintf("nil ShapeRef for field %s", front)) | ||
| } | ||
| fieldShapePath := strings.Replace(fieldPath, front, | ||
| frontField.ShapeRef.ShapeName, 1) | ||
| fsp := fieldpath.FromString(fieldShapePath) | ||
| var index int | ||
| elemAccessPrefix := sourceVarName | ||
| var importPath string | ||
| if apiPkgImportName != "" { | ||
| importPath = fmt.Sprintf("%s.", apiPkgImportName) | ||
| } | ||
| // traverse over the fieldShapePath and initialize every element | ||
| // except the last. | ||
| for index < fsp.Size()-1 { | ||
| elemName := fsp.At(index) | ||
| elemShapeRef := fsp.ShapeRefAt(frontField.ShapeRef, index) | ||
| if elemShapeRef.Shape.Type != "structure" { | ||
| panic(fmt.Sprintf("only nested structures are supported."+ | ||
| " Shape type for %s is %s inside fieldpath %s", elemName, | ||
| elemShapeRef.Shape.Type, fieldPath)) | ||
| } | ||
| out += fmt.Sprintf("%s%s.%s = &%s%s{}\n", | ||
| indent, elemAccessPrefix, elemName, importPath, | ||
| elemShapeRef.GoTypeElem()) | ||
| elemAccessPrefix = fmt.Sprintf("%s.%s", elemAccessPrefix, | ||
| elemName) | ||
| index++ | ||
| } | ||
vijtrip2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| return out | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package code_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/aws-controllers-k8s/code-generator/pkg/generate/code" | ||
|
|
||
| "github.com/aws-controllers-k8s/code-generator/pkg/testutil" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestInitializeNestedStructField(t *testing.T) { | ||
| assert := assert.New(t) | ||
|
|
||
| g := testutil.NewModelForServiceWithOptions(t, "s3", | ||
| &testutil.TestingModelOptions{GeneratorConfigFile: "generator-with-tags.yaml"}) | ||
|
|
||
| crd := testutil.GetCRDByName(t, g, "Bucket") | ||
| assert.NotNil(crd) | ||
|
|
||
| f := crd.Fields["Logging.LoggingEnabled.TargetBucket"] | ||
|
|
||
| s := code.InitializeNestedStructField(crd, "r.ko", f, | ||
| "svcapitypes", 1) | ||
| expected := | ||
| ` r.ko.BucketLoggingStatus = &svcapitypes.BucketLoggingStatus{} | ||
| r.ko.BucketLoggingStatus.LoggingEnabled = &svcapitypes.LoggingEnabled{} | ||
| ` | ||
| assert.Equal(expected, s) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.