-
Notifications
You must be signed in to change notification settings - Fork 241
feat(sdk): Add per-service SDK tag fallback for model fetching #690
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ var ( | |
| defaultCacheDir string | ||
| optCacheDir string | ||
| optAWSSDKGoVersion string | ||
| optAWSServiceSDKVersion string | ||
| defaultTemplateDirs []string | ||
| optTemplateDirs []string | ||
| defaultServicesDir string | ||
|
|
@@ -124,6 +125,9 @@ func init() { | |
| rootCmd.PersistentFlags().StringVar( | ||
| &optAWSSDKGoVersion, "aws-sdk-go-version", "", "Version of github.com/aws/aws-sdk-go-v2 used to generate apis and controllers files", | ||
| ) | ||
| rootCmd.PersistentFlags().StringVar( | ||
|
Contributor
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. Q: Should this flag be mutually exclusive with
Contributor
Author
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. Makes sense. If core sdk version is set at the same time, we can return an error |
||
| &optAWSServiceSDKVersion, "aws-service-sdk-version", "", "Per-service SDK version (e.g. v1.0.0) for fetching model from per-service tag", | ||
| ) | ||
| rootCmd.PersistentFlags().StringVar( | ||
| &optServiceAccountName, "service-account-name", "", "The name of the ServiceAccount used for ACK service controller", | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,124 @@ | ||||||
| // 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 metadata | ||||||
|
|
||||||
| import ( | ||||||
| "strings" | ||||||
| "testing" | ||||||
|
|
||||||
| "github.com/ghodss/yaml" | ||||||
| "github.com/stretchr/testify/assert" | ||||||
| "github.com/stretchr/testify/require" | ||||||
| ) | ||||||
|
|
||||||
| // TestGenerationMetadata_RoundTrip validates that serializing GenerationMetadata | ||||||
| // to YAML and deserializing back produces identical field values, including the | ||||||
| // aws_service_sdk_version field when present and its absence when empty. | ||||||
| func TestGenerationMetadata_RoundTrip(t *testing.T) { | ||||||
| tests := []struct { | ||||||
| name string | ||||||
| awsServiceSDKVersion string | ||||||
| expectFieldInYAML bool | ||||||
| }{ | ||||||
| { | ||||||
| name: "with per-service SDK version", | ||||||
| awsServiceSDKVersion: "v1.0.0", | ||||||
| expectFieldInYAML: true, | ||||||
| }, | ||||||
| { | ||||||
| name: "without per-service SDK version", | ||||||
| awsServiceSDKVersion: "", | ||||||
| expectFieldInYAML: false, | ||||||
| }, | ||||||
| } | ||||||
|
|
||||||
| for _, tc := range tests { | ||||||
| t.Run(tc.name, func(t *testing.T) { | ||||||
| original := GenerationMetadata{ | ||||||
| APIVersion: "v1alpha1", | ||||||
| APIDirectoryChecksum: "abc123", | ||||||
| LastModification: lastModificationInfo{ | ||||||
| Reason: UpdateReasonAPIGeneration, | ||||||
| }, | ||||||
| AWSSDKGoVersion: "v1.41.5", | ||||||
|
Contributor
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 would be good to also test that |
||||||
| AWSServiceSDKVersion: tc.awsServiceSDKVersion, | ||||||
| ACKGenerateInfo: ackGenerateInfo{ | ||||||
| Version: "v0.58.0", | ||||||
| GoVersion: "go1.25.3", | ||||||
| BuildDate: "2026-04-14T18:02:39Z", | ||||||
| BuildHash: "a9e2cea", | ||||||
| }, | ||||||
| GeneratorConfigInfo: generatorConfigInfo{ | ||||||
| OriginalFileName: "generator.yaml", | ||||||
| FileChecksum: "5b522171", | ||||||
| }, | ||||||
| } | ||||||
|
|
||||||
| data, err := yaml.Marshal(original) | ||||||
| require.NoError(t, err) | ||||||
|
|
||||||
| // Verify the aws_service_sdk_version field presence/absence in raw YAML | ||||||
| yamlStr := string(data) | ||||||
| if tc.expectFieldInYAML { | ||||||
| assert.True(t, strings.Contains(yamlStr, "aws_service_sdk_version"), | ||||||
| "expected aws_service_sdk_version in YAML output") | ||||||
| } else { | ||||||
| assert.False(t, strings.Contains(yamlStr, "aws_service_sdk_version"), | ||||||
| "expected aws_service_sdk_version to be omitted from YAML output") | ||||||
| } | ||||||
|
|
||||||
| // Unmarshal back and verify round-trip equality | ||||||
| var restored GenerationMetadata | ||||||
| err = yaml.Unmarshal(data, &restored) | ||||||
| require.NoError(t, err) | ||||||
|
|
||||||
| assert.Equal(t, original.APIVersion, restored.APIVersion) | ||||||
| assert.Equal(t, original.APIDirectoryChecksum, restored.APIDirectoryChecksum) | ||||||
| assert.Equal(t, original.LastModification, restored.LastModification) | ||||||
| assert.Equal(t, original.AWSSDKGoVersion, restored.AWSSDKGoVersion) | ||||||
| assert.Equal(t, original.AWSServiceSDKVersion, restored.AWSServiceSDKVersion) | ||||||
| assert.Equal(t, original.ACKGenerateInfo, restored.ACKGenerateInfo) | ||||||
| assert.Equal(t, original.GeneratorConfigInfo, restored.GeneratorConfigInfo) | ||||||
| }) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // TestGenerationMetadata_BackwardCompatibility verifies that YAML without the | ||||||
| // aws_service_sdk_version field deserializes without error and the field | ||||||
| // defaults to empty string (Requirement 4.3). | ||||||
|
Contributor
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. nit:
Suggested change
|
||||||
| func TestGenerationMetadata_BackwardCompatibility(t *testing.T) { | ||||||
| // YAML that predates the aws_service_sdk_version field | ||||||
| oldYAML := ` | ||||||
| api_version: v1alpha1 | ||||||
| api_directory_checksum: abc123 | ||||||
| aws_sdk_go_version: v1.41.5 | ||||||
| last_modification: | ||||||
| reason: API generation | ||||||
| ack_generate_info: | ||||||
| version: v0.58.0 | ||||||
| go_version: go1.25.3 | ||||||
| build_date: "2026-04-14T18:02:39Z" | ||||||
| build_hash: a9e2cea | ||||||
| generator_config_info: | ||||||
| original_file_name: generator.yaml | ||||||
| file_checksum: "5b522171" | ||||||
| ` | ||||||
| var gm GenerationMetadata | ||||||
| err := yaml.Unmarshal([]byte(oldYAML), &gm) | ||||||
| require.NoError(t, err) | ||||||
|
|
||||||
| assert.Equal(t, "v1alpha1", gm.APIVersion) | ||||||
| assert.Equal(t, "v1.41.5", gm.AWSSDKGoVersion) | ||||||
| assert.Equal(t, "", gm.AWSServiceSDKVersion, "missing field should default to empty string") | ||||||
| } | ||||||
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.
Testing this PR against the
s3-controllerI see that after callingmake build-controller SERVICE=s3 AWS_SERVICE_SDK_VERSION=v1.99.1the ack-generate-metadata.yaml file looks like the below and includes bothaws_sdk_go_versionandaws_service_sdk_version. Should only one of these fields be emitted?