From 295bca6d3467c15311208a0738c08ad888c66346 Mon Sep 17 00:00:00 2001 From: vijtrip2 Date: Mon, 13 Jun 2022 22:05:55 -0700 Subject: [PATCH 1/3] ACK runtime update to v0.19.0 --- apis/v1alpha1/ack-generate-metadata.yaml | 8 ++-- apis/v1alpha1/generator.yaml | 8 ++++ cmd/controller/main.go | 3 +- config/controller/deployment.yaml | 2 +- config/controller/kustomization.yaml | 2 +- generator.yaml | 8 ++++ go.mod | 2 +- go.sum | 4 +- helm/Chart.yaml | 4 +- helm/templates/NOTES.txt | 2 +- helm/values.yaml | 7 ++- pkg/resource/api/manager.go | 36 ++++++++++++++- pkg/resource/api/tags.go | 59 ++++++++++++++++++++++++ pkg/resource/authorizer/manager.go | 26 ++++++++++- pkg/resource/deployment/manager.go | 26 ++++++++++- pkg/resource/integration/manager.go | 26 ++++++++++- pkg/resource/route/manager.go | 26 ++++++++++- pkg/resource/stage/manager.go | 36 ++++++++++++++- pkg/resource/stage/tags.go | 59 ++++++++++++++++++++++++ pkg/resource/vpc_link/manager.go | 36 ++++++++++++++- pkg/resource/vpc_link/tags.go | 59 ++++++++++++++++++++++++ 21 files changed, 408 insertions(+), 31 deletions(-) create mode 100644 pkg/resource/api/tags.go create mode 100644 pkg/resource/stage/tags.go create mode 100644 pkg/resource/vpc_link/tags.go diff --git a/apis/v1alpha1/ack-generate-metadata.yaml b/apis/v1alpha1/ack-generate-metadata.yaml index e0ebc7d..4e807d0 100755 --- a/apis/v1alpha1/ack-generate-metadata.yaml +++ b/apis/v1alpha1/ack-generate-metadata.yaml @@ -1,13 +1,13 @@ ack_generate_info: - build_date: "2022-04-15T20:27:58Z" - build_hash: 50c64871bcaf88b9ee200eb8d6b8245fa8f675eb + build_date: "2022-06-14T05:05:04Z" + build_hash: a133935a9a93591a9e1ba9d5ca940cb83a1353b4 go_version: go1.17.5 - version: v0.18.4 + version: v0.19.0 api_directory_checksum: c69d75f37400a8d4d6eb4362eb743005531a7b2c api_version: v1alpha1 aws_sdk_go_version: v1.42.0 generator_config_info: - file_checksum: 6ea111ed6683ab7ee07ffd165ae76454bd0fddab + file_checksum: 52b0fd0e1882461d1c0694dd583d1ef7e655c5c1 original_file_name: generator.yaml last_modification: reason: API generation diff --git a/apis/v1alpha1/generator.yaml b/apis/v1alpha1/generator.yaml index 3f9b52c..43f994e 100644 --- a/apis/v1alpha1/generator.yaml +++ b/apis/v1alpha1/generator.yaml @@ -50,12 +50,16 @@ resources: references: resource: API path: Status.APIID + tags: + ignore: true Deployment: fields: ApiId: references: resource: API path: Status.APIID + tags: + ignore: true Integration: fields: ApiId: @@ -66,6 +70,8 @@ resources: references: resource: VPCLink path: Status.VPCLinkID + tags: + ignore: true Route: fields: ApiId: @@ -83,6 +89,8 @@ resources: hooks: references_post_resolve: template_path: hooks/route/references_post_resolve.go.tpl + tags: + ignore: true VpcLink: hooks: sdk_update_pre_build_request: diff --git a/cmd/controller/main.go b/cmd/controller/main.go index 5ccd64f..dc33d17 100644 --- a/cmd/controller/main.go +++ b/cmd/controller/main.go @@ -21,6 +21,7 @@ import ( ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1" ackcfg "github.com/aws-controllers-k8s/runtime/pkg/config" ackrt "github.com/aws-controllers-k8s/runtime/pkg/runtime" + acktypes "github.com/aws-controllers-k8s/runtime/pkg/types" ackrtutil "github.com/aws-controllers-k8s/runtime/pkg/util" ackrtwebhook "github.com/aws-controllers-k8s/runtime/pkg/webhook" svcsdk "github.com/aws/aws-sdk-go/service/apigatewayv2" @@ -107,7 +108,7 @@ func main() { ) sc := ackrt.NewServiceController( awsServiceAlias, awsServiceAPIGroup, awsServiceEndpointsID, - ackrt.VersionInfo{ + acktypes.VersionInfo{ version.GitCommit, version.GitVersion, version.BuildDate, diff --git a/config/controller/deployment.yaml b/config/controller/deployment.yaml index 2d6d621..cf7c4a6 100644 --- a/config/controller/deployment.yaml +++ b/config/controller/deployment.yaml @@ -66,7 +66,7 @@ spec: - name: ACK_LOG_LEVEL value: "info" - name: ACK_RESOURCE_TAGS - value: "services.k8s.aws/managed=true,services.k8s.aws/created=%UTCNOW%,services.k8s.aws/namespace=%KUBERNETES_NAMESPACE%" + value: "services.k8s.aws/controller-version=%CONTROLLER_SERVICE%-%CONTROLLER_VERSION%,services.k8s.aws/namespace=%K8S_NAMESPACE%" securityContext: allowPrivilegeEscalation: false privileged: false diff --git a/config/controller/kustomization.yaml b/config/controller/kustomization.yaml index 6d6407e..dd59fc6 100644 --- a/config/controller/kustomization.yaml +++ b/config/controller/kustomization.yaml @@ -6,4 +6,4 @@ kind: Kustomization images: - name: controller newName: public.ecr.aws/aws-controllers-k8s/apigatewayv2-controller - newTag: v0.1.0 + newTag: v0.1.1 diff --git a/generator.yaml b/generator.yaml index 3f9b52c..43f994e 100644 --- a/generator.yaml +++ b/generator.yaml @@ -50,12 +50,16 @@ resources: references: resource: API path: Status.APIID + tags: + ignore: true Deployment: fields: ApiId: references: resource: API path: Status.APIID + tags: + ignore: true Integration: fields: ApiId: @@ -66,6 +70,8 @@ resources: references: resource: VPCLink path: Status.VPCLinkID + tags: + ignore: true Route: fields: ApiId: @@ -83,6 +89,8 @@ resources: hooks: references_post_resolve: template_path: hooks/route/references_post_resolve.go.tpl + tags: + ignore: true VpcLink: hooks: sdk_update_pre_build_request: diff --git a/go.mod b/go.mod index a41ea83..e89fe98 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/aws-controllers-k8s/apigatewayv2-controller go 1.17 require ( - github.com/aws-controllers-k8s/runtime v0.18.4 + github.com/aws-controllers-k8s/runtime v0.19.0 github.com/aws/aws-sdk-go v1.42.0 github.com/go-logr/logr v1.2.0 github.com/google/go-cmp v0.5.5 diff --git a/go.sum b/go.sum index db2f6c3..07c7d30 100644 --- a/go.sum +++ b/go.sum @@ -64,8 +64,8 @@ github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hC github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= -github.com/aws-controllers-k8s/runtime v0.18.4 h1:iwLYNwhbuiWZrHPoulGj75oT+alE91wCNkF1FUELiAw= -github.com/aws-controllers-k8s/runtime v0.18.4/go.mod h1:oA8ML1/LL3chPn26P6SzBNu1CUI2nekB+PTqykNs0qU= +github.com/aws-controllers-k8s/runtime v0.19.0 h1:+O5a6jBSBAd8XTNMrVCIYu4G+ZUPZe/G5eopVFO18Dc= +github.com/aws-controllers-k8s/runtime v0.19.0/go.mod h1:oA8ML1/LL3chPn26P6SzBNu1CUI2nekB+PTqykNs0qU= github.com/aws/aws-sdk-go v1.42.0 h1:BMZws0t8NAhHFsfnT3B40IwD13jVDG5KerlRksctVIw= github.com/aws/aws-sdk-go v1.42.0/go.mod h1:585smgzpB/KqRA+K3y/NL/oYRqQvpNJYvLm+LY1U59Q= github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM= diff --git a/helm/Chart.yaml b/helm/Chart.yaml index 9d1ff55..90a8040 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -1,8 +1,8 @@ apiVersion: v1 name: apigatewayv2-chart description: A Helm chart for the ACK service controller for Amazon API Gateway (APIGWv2) -version: v0.1.0 -appVersion: v0.1.0 +version: v0.1.1 +appVersion: v0.1.1 home: https://github.com/aws-controllers-k8s/apigatewayv2-controller icon: https://raw.githubusercontent.com/aws/eks-charts/master/docs/logo/aws.png sources: diff --git a/helm/templates/NOTES.txt b/helm/templates/NOTES.txt index 9bf5b40..652ced9 100644 --- a/helm/templates/NOTES.txt +++ b/helm/templates/NOTES.txt @@ -1,5 +1,5 @@ {{ .Chart.Name }} has been installed. -This chart deploys "public.ecr.aws/aws-controllers-k8s/apigatewayv2-controller:v0.1.0". +This chart deploys "public.ecr.aws/aws-controllers-k8s/apigatewayv2-controller:v0.1.1". Check its status by running: kubectl --namespace {{ .Release.Namespace }} get pods -l "app.kubernetes.io/instance={{ .Release.Name }}" diff --git a/helm/values.yaml b/helm/values.yaml index bc66c5b..3f068d8 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -4,7 +4,7 @@ image: repository: public.ecr.aws/aws-controllers-k8s/apigatewayv2-controller - tag: v0.1.0 + tag: v0.1.1 pullPolicy: IfNotPresent pullSecrets: [] @@ -64,9 +64,8 @@ installScope: cluster resourceTags: # Configures the ACK service controller to always set key/value pairs tags on # resources that it manages. - - services.k8s.aws/managed=true - - services.k8s.aws/created=%UTCNOW% - - services.k8s.aws/namespace=%KUBERNETES_NAMESPACE% + - services.k8s.aws/controller-version=%CONTROLLER_SERVICE%-%CONTROLLER_VERSION% + - services.k8s.aws/namespace=%K8S_NAMESPACE% serviceAccount: # Specifies whether a service account should be created diff --git a/pkg/resource/api/manager.go b/pkg/resource/api/manager.go index f308a28..720848a 100644 --- a/pkg/resource/api/manager.go +++ b/pkg/resource/api/manager.go @@ -27,19 +27,25 @@ import ( ackerr "github.com/aws-controllers-k8s/runtime/pkg/errors" ackmetrics "github.com/aws-controllers-k8s/runtime/pkg/metrics" ackrequeue "github.com/aws-controllers-k8s/runtime/pkg/requeue" + ackrt "github.com/aws-controllers-k8s/runtime/pkg/runtime" ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log" + acktags "github.com/aws-controllers-k8s/runtime/pkg/tags" acktypes "github.com/aws-controllers-k8s/runtime/pkg/types" ackutil "github.com/aws-controllers-k8s/runtime/pkg/util" "github.com/aws/aws-sdk-go/aws/session" + svcsdk "github.com/aws/aws-sdk-go/service/apigatewayv2" + svcsdkapi "github.com/aws/aws-sdk-go/service/apigatewayv2/apigatewayv2iface" "github.com/go-logr/logr" corev1 "k8s.io/api/core/v1" - svcsdk "github.com/aws/aws-sdk-go/service/apigatewayv2" - svcsdkapi "github.com/aws/aws-sdk-go/service/apigatewayv2/apigatewayv2iface" + svcapitypes "github.com/aws-controllers-k8s/apigatewayv2-controller/apis/v1alpha1" ) var ( _ = ackutil.InStrings + _ = acktags.NewTags() + _ = ackrt.MissingImageTagValue + _ = svcapitypes.API{} ) // +kubebuilder:rbac:groups=apigatewayv2.services.k8s.aws,resources=apis,verbs=get;list;watch;create;update;patch;delete @@ -259,6 +265,32 @@ func (rm *resourceManager) IsSynced(ctx context.Context, res acktypes.AWSResourc return true, nil } +// EnsureTags ensures that tags are present inside the AWSResource. +// If the AWSResource does not have any existing resource tags, the 'tags' +// field is initialized and the controller tags are added. +// If the AWSResource has existing resource tags, then controller tags are +// added to the existing resource tags without overriding them. +// If the AWSResource does not support tags, only then the controller tags +// will not be added to the AWSResource. +func (rm *resourceManager) EnsureTags( + ctx context.Context, + res acktypes.AWSResource, + md acktypes.ServiceControllerMetadata, +) error { + r := rm.concreteResource(res) + if r.ko == nil { + // Should never happen... if it does, it's buggy code. + panic("resource manager's EnsureTags method received resource with nil CR object") + } + defaultTags := ackrt.GetDefaultTags(&rm.cfg, r.ko, md) + var existingTags map[string]*string + existingTags = r.ko.Spec.Tags + resourceTags := ToACKTags(existingTags) + tags := acktags.Merge(resourceTags, defaultTags) + r.ko.Spec.Tags = FromACKTags(tags) + return nil +} + // newResourceManager returns a new struct implementing // acktypes.AWSResourceManager func newResourceManager( diff --git a/pkg/resource/api/tags.go b/pkg/resource/api/tags.go new file mode 100644 index 0000000..94a8291 --- /dev/null +++ b/pkg/resource/api/tags.go @@ -0,0 +1,59 @@ +// 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. + +// Code generated by ack-generate. DO NOT EDIT. + +package api + +import ( + acktags "github.com/aws-controllers-k8s/runtime/pkg/tags" + + svcapitypes "github.com/aws-controllers-k8s/apigatewayv2-controller/apis/v1alpha1" +) + +var ( + _ = svcapitypes.API{} + _ = acktags.NewTags() +) + +// ToACKTags converts the tags parameter into 'acktags.Tags' shape. +// This method helps in creating the hub(acktags.Tags) for merging +// default controller tags with existing resource tags. +func ToACKTags(tags map[string]*string) acktags.Tags { + result := acktags.NewTags() + if tags == nil || len(tags) == 0 { + return result + } + + for k, v := range tags { + if v == nil { + result[k] = "" + } else { + result[k] = *v + } + } + + return result +} + +// FromACKTags converts the tags parameter into map[string]*string shape. +// This method helps in setting the tags back inside AWSResource after merging +// default controller tags with existing resource tags. +func FromACKTags(tags acktags.Tags) map[string]*string { + result := map[string]*string{} + for k, v := range tags { + vCopy := v + result[k] = &vCopy + } + return result +} diff --git a/pkg/resource/authorizer/manager.go b/pkg/resource/authorizer/manager.go index 0484fca..dc766d1 100644 --- a/pkg/resource/authorizer/manager.go +++ b/pkg/resource/authorizer/manager.go @@ -27,19 +27,25 @@ import ( ackerr "github.com/aws-controllers-k8s/runtime/pkg/errors" ackmetrics "github.com/aws-controllers-k8s/runtime/pkg/metrics" ackrequeue "github.com/aws-controllers-k8s/runtime/pkg/requeue" + ackrt "github.com/aws-controllers-k8s/runtime/pkg/runtime" ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log" + acktags "github.com/aws-controllers-k8s/runtime/pkg/tags" acktypes "github.com/aws-controllers-k8s/runtime/pkg/types" ackutil "github.com/aws-controllers-k8s/runtime/pkg/util" "github.com/aws/aws-sdk-go/aws/session" + svcsdk "github.com/aws/aws-sdk-go/service/apigatewayv2" + svcsdkapi "github.com/aws/aws-sdk-go/service/apigatewayv2/apigatewayv2iface" "github.com/go-logr/logr" corev1 "k8s.io/api/core/v1" - svcsdk "github.com/aws/aws-sdk-go/service/apigatewayv2" - svcsdkapi "github.com/aws/aws-sdk-go/service/apigatewayv2/apigatewayv2iface" + svcapitypes "github.com/aws-controllers-k8s/apigatewayv2-controller/apis/v1alpha1" ) var ( _ = ackutil.InStrings + _ = acktags.NewTags() + _ = ackrt.MissingImageTagValue + _ = svcapitypes.Authorizer{} ) // +kubebuilder:rbac:groups=apigatewayv2.services.k8s.aws,resources=authorizers,verbs=get;list;watch;create;update;patch;delete @@ -259,6 +265,22 @@ func (rm *resourceManager) IsSynced(ctx context.Context, res acktypes.AWSResourc return true, nil } +// EnsureTags ensures that tags are present inside the AWSResource. +// If the AWSResource does not have any existing resource tags, the 'tags' +// field is initialized and the controller tags are added. +// If the AWSResource has existing resource tags, then controller tags are +// added to the existing resource tags without overriding them. +// If the AWSResource does not support tags, only then the controller tags +// will not be added to the AWSResource. +func (rm *resourceManager) EnsureTags( + ctx context.Context, + res acktypes.AWSResource, + md acktypes.ServiceControllerMetadata, +) error { + + return nil +} + // newResourceManager returns a new struct implementing // acktypes.AWSResourceManager func newResourceManager( diff --git a/pkg/resource/deployment/manager.go b/pkg/resource/deployment/manager.go index fc00d45..aa3e88d 100644 --- a/pkg/resource/deployment/manager.go +++ b/pkg/resource/deployment/manager.go @@ -27,19 +27,25 @@ import ( ackerr "github.com/aws-controllers-k8s/runtime/pkg/errors" ackmetrics "github.com/aws-controllers-k8s/runtime/pkg/metrics" ackrequeue "github.com/aws-controllers-k8s/runtime/pkg/requeue" + ackrt "github.com/aws-controllers-k8s/runtime/pkg/runtime" ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log" + acktags "github.com/aws-controllers-k8s/runtime/pkg/tags" acktypes "github.com/aws-controllers-k8s/runtime/pkg/types" ackutil "github.com/aws-controllers-k8s/runtime/pkg/util" "github.com/aws/aws-sdk-go/aws/session" + svcsdk "github.com/aws/aws-sdk-go/service/apigatewayv2" + svcsdkapi "github.com/aws/aws-sdk-go/service/apigatewayv2/apigatewayv2iface" "github.com/go-logr/logr" corev1 "k8s.io/api/core/v1" - svcsdk "github.com/aws/aws-sdk-go/service/apigatewayv2" - svcsdkapi "github.com/aws/aws-sdk-go/service/apigatewayv2/apigatewayv2iface" + svcapitypes "github.com/aws-controllers-k8s/apigatewayv2-controller/apis/v1alpha1" ) var ( _ = ackutil.InStrings + _ = acktags.NewTags() + _ = ackrt.MissingImageTagValue + _ = svcapitypes.Deployment{} ) // +kubebuilder:rbac:groups=apigatewayv2.services.k8s.aws,resources=deployments,verbs=get;list;watch;create;update;patch;delete @@ -259,6 +265,22 @@ func (rm *resourceManager) IsSynced(ctx context.Context, res acktypes.AWSResourc return true, nil } +// EnsureTags ensures that tags are present inside the AWSResource. +// If the AWSResource does not have any existing resource tags, the 'tags' +// field is initialized and the controller tags are added. +// If the AWSResource has existing resource tags, then controller tags are +// added to the existing resource tags without overriding them. +// If the AWSResource does not support tags, only then the controller tags +// will not be added to the AWSResource. +func (rm *resourceManager) EnsureTags( + ctx context.Context, + res acktypes.AWSResource, + md acktypes.ServiceControllerMetadata, +) error { + + return nil +} + // newResourceManager returns a new struct implementing // acktypes.AWSResourceManager func newResourceManager( diff --git a/pkg/resource/integration/manager.go b/pkg/resource/integration/manager.go index 5525b3b..3e6f953 100644 --- a/pkg/resource/integration/manager.go +++ b/pkg/resource/integration/manager.go @@ -27,19 +27,25 @@ import ( ackerr "github.com/aws-controllers-k8s/runtime/pkg/errors" ackmetrics "github.com/aws-controllers-k8s/runtime/pkg/metrics" ackrequeue "github.com/aws-controllers-k8s/runtime/pkg/requeue" + ackrt "github.com/aws-controllers-k8s/runtime/pkg/runtime" ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log" + acktags "github.com/aws-controllers-k8s/runtime/pkg/tags" acktypes "github.com/aws-controllers-k8s/runtime/pkg/types" ackutil "github.com/aws-controllers-k8s/runtime/pkg/util" "github.com/aws/aws-sdk-go/aws/session" + svcsdk "github.com/aws/aws-sdk-go/service/apigatewayv2" + svcsdkapi "github.com/aws/aws-sdk-go/service/apigatewayv2/apigatewayv2iface" "github.com/go-logr/logr" corev1 "k8s.io/api/core/v1" - svcsdk "github.com/aws/aws-sdk-go/service/apigatewayv2" - svcsdkapi "github.com/aws/aws-sdk-go/service/apigatewayv2/apigatewayv2iface" + svcapitypes "github.com/aws-controllers-k8s/apigatewayv2-controller/apis/v1alpha1" ) var ( _ = ackutil.InStrings + _ = acktags.NewTags() + _ = ackrt.MissingImageTagValue + _ = svcapitypes.Integration{} ) // +kubebuilder:rbac:groups=apigatewayv2.services.k8s.aws,resources=integrations,verbs=get;list;watch;create;update;patch;delete @@ -259,6 +265,22 @@ func (rm *resourceManager) IsSynced(ctx context.Context, res acktypes.AWSResourc return true, nil } +// EnsureTags ensures that tags are present inside the AWSResource. +// If the AWSResource does not have any existing resource tags, the 'tags' +// field is initialized and the controller tags are added. +// If the AWSResource has existing resource tags, then controller tags are +// added to the existing resource tags without overriding them. +// If the AWSResource does not support tags, only then the controller tags +// will not be added to the AWSResource. +func (rm *resourceManager) EnsureTags( + ctx context.Context, + res acktypes.AWSResource, + md acktypes.ServiceControllerMetadata, +) error { + + return nil +} + // newResourceManager returns a new struct implementing // acktypes.AWSResourceManager func newResourceManager( diff --git a/pkg/resource/route/manager.go b/pkg/resource/route/manager.go index c56a48f..4bfa316 100644 --- a/pkg/resource/route/manager.go +++ b/pkg/resource/route/manager.go @@ -27,19 +27,25 @@ import ( ackerr "github.com/aws-controllers-k8s/runtime/pkg/errors" ackmetrics "github.com/aws-controllers-k8s/runtime/pkg/metrics" ackrequeue "github.com/aws-controllers-k8s/runtime/pkg/requeue" + ackrt "github.com/aws-controllers-k8s/runtime/pkg/runtime" ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log" + acktags "github.com/aws-controllers-k8s/runtime/pkg/tags" acktypes "github.com/aws-controllers-k8s/runtime/pkg/types" ackutil "github.com/aws-controllers-k8s/runtime/pkg/util" "github.com/aws/aws-sdk-go/aws/session" + svcsdk "github.com/aws/aws-sdk-go/service/apigatewayv2" + svcsdkapi "github.com/aws/aws-sdk-go/service/apigatewayv2/apigatewayv2iface" "github.com/go-logr/logr" corev1 "k8s.io/api/core/v1" - svcsdk "github.com/aws/aws-sdk-go/service/apigatewayv2" - svcsdkapi "github.com/aws/aws-sdk-go/service/apigatewayv2/apigatewayv2iface" + svcapitypes "github.com/aws-controllers-k8s/apigatewayv2-controller/apis/v1alpha1" ) var ( _ = ackutil.InStrings + _ = acktags.NewTags() + _ = ackrt.MissingImageTagValue + _ = svcapitypes.Route{} ) // +kubebuilder:rbac:groups=apigatewayv2.services.k8s.aws,resources=routes,verbs=get;list;watch;create;update;patch;delete @@ -259,6 +265,22 @@ func (rm *resourceManager) IsSynced(ctx context.Context, res acktypes.AWSResourc return true, nil } +// EnsureTags ensures that tags are present inside the AWSResource. +// If the AWSResource does not have any existing resource tags, the 'tags' +// field is initialized and the controller tags are added. +// If the AWSResource has existing resource tags, then controller tags are +// added to the existing resource tags without overriding them. +// If the AWSResource does not support tags, only then the controller tags +// will not be added to the AWSResource. +func (rm *resourceManager) EnsureTags( + ctx context.Context, + res acktypes.AWSResource, + md acktypes.ServiceControllerMetadata, +) error { + + return nil +} + // newResourceManager returns a new struct implementing // acktypes.AWSResourceManager func newResourceManager( diff --git a/pkg/resource/stage/manager.go b/pkg/resource/stage/manager.go index c586c19..6161707 100644 --- a/pkg/resource/stage/manager.go +++ b/pkg/resource/stage/manager.go @@ -27,19 +27,25 @@ import ( ackerr "github.com/aws-controllers-k8s/runtime/pkg/errors" ackmetrics "github.com/aws-controllers-k8s/runtime/pkg/metrics" ackrequeue "github.com/aws-controllers-k8s/runtime/pkg/requeue" + ackrt "github.com/aws-controllers-k8s/runtime/pkg/runtime" ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log" + acktags "github.com/aws-controllers-k8s/runtime/pkg/tags" acktypes "github.com/aws-controllers-k8s/runtime/pkg/types" ackutil "github.com/aws-controllers-k8s/runtime/pkg/util" "github.com/aws/aws-sdk-go/aws/session" + svcsdk "github.com/aws/aws-sdk-go/service/apigatewayv2" + svcsdkapi "github.com/aws/aws-sdk-go/service/apigatewayv2/apigatewayv2iface" "github.com/go-logr/logr" corev1 "k8s.io/api/core/v1" - svcsdk "github.com/aws/aws-sdk-go/service/apigatewayv2" - svcsdkapi "github.com/aws/aws-sdk-go/service/apigatewayv2/apigatewayv2iface" + svcapitypes "github.com/aws-controllers-k8s/apigatewayv2-controller/apis/v1alpha1" ) var ( _ = ackutil.InStrings + _ = acktags.NewTags() + _ = ackrt.MissingImageTagValue + _ = svcapitypes.Stage{} ) // +kubebuilder:rbac:groups=apigatewayv2.services.k8s.aws,resources=stages,verbs=get;list;watch;create;update;patch;delete @@ -259,6 +265,32 @@ func (rm *resourceManager) IsSynced(ctx context.Context, res acktypes.AWSResourc return true, nil } +// EnsureTags ensures that tags are present inside the AWSResource. +// If the AWSResource does not have any existing resource tags, the 'tags' +// field is initialized and the controller tags are added. +// If the AWSResource has existing resource tags, then controller tags are +// added to the existing resource tags without overriding them. +// If the AWSResource does not support tags, only then the controller tags +// will not be added to the AWSResource. +func (rm *resourceManager) EnsureTags( + ctx context.Context, + res acktypes.AWSResource, + md acktypes.ServiceControllerMetadata, +) error { + r := rm.concreteResource(res) + if r.ko == nil { + // Should never happen... if it does, it's buggy code. + panic("resource manager's EnsureTags method received resource with nil CR object") + } + defaultTags := ackrt.GetDefaultTags(&rm.cfg, r.ko, md) + var existingTags map[string]*string + existingTags = r.ko.Spec.Tags + resourceTags := ToACKTags(existingTags) + tags := acktags.Merge(resourceTags, defaultTags) + r.ko.Spec.Tags = FromACKTags(tags) + return nil +} + // newResourceManager returns a new struct implementing // acktypes.AWSResourceManager func newResourceManager( diff --git a/pkg/resource/stage/tags.go b/pkg/resource/stage/tags.go new file mode 100644 index 0000000..b00d908 --- /dev/null +++ b/pkg/resource/stage/tags.go @@ -0,0 +1,59 @@ +// 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. + +// Code generated by ack-generate. DO NOT EDIT. + +package stage + +import ( + acktags "github.com/aws-controllers-k8s/runtime/pkg/tags" + + svcapitypes "github.com/aws-controllers-k8s/apigatewayv2-controller/apis/v1alpha1" +) + +var ( + _ = svcapitypes.Stage{} + _ = acktags.NewTags() +) + +// ToACKTags converts the tags parameter into 'acktags.Tags' shape. +// This method helps in creating the hub(acktags.Tags) for merging +// default controller tags with existing resource tags. +func ToACKTags(tags map[string]*string) acktags.Tags { + result := acktags.NewTags() + if tags == nil || len(tags) == 0 { + return result + } + + for k, v := range tags { + if v == nil { + result[k] = "" + } else { + result[k] = *v + } + } + + return result +} + +// FromACKTags converts the tags parameter into map[string]*string shape. +// This method helps in setting the tags back inside AWSResource after merging +// default controller tags with existing resource tags. +func FromACKTags(tags acktags.Tags) map[string]*string { + result := map[string]*string{} + for k, v := range tags { + vCopy := v + result[k] = &vCopy + } + return result +} diff --git a/pkg/resource/vpc_link/manager.go b/pkg/resource/vpc_link/manager.go index 0629b45..96d2452 100644 --- a/pkg/resource/vpc_link/manager.go +++ b/pkg/resource/vpc_link/manager.go @@ -27,19 +27,25 @@ import ( ackerr "github.com/aws-controllers-k8s/runtime/pkg/errors" ackmetrics "github.com/aws-controllers-k8s/runtime/pkg/metrics" ackrequeue "github.com/aws-controllers-k8s/runtime/pkg/requeue" + ackrt "github.com/aws-controllers-k8s/runtime/pkg/runtime" ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log" + acktags "github.com/aws-controllers-k8s/runtime/pkg/tags" acktypes "github.com/aws-controllers-k8s/runtime/pkg/types" ackutil "github.com/aws-controllers-k8s/runtime/pkg/util" "github.com/aws/aws-sdk-go/aws/session" + svcsdk "github.com/aws/aws-sdk-go/service/apigatewayv2" + svcsdkapi "github.com/aws/aws-sdk-go/service/apigatewayv2/apigatewayv2iface" "github.com/go-logr/logr" corev1 "k8s.io/api/core/v1" - svcsdk "github.com/aws/aws-sdk-go/service/apigatewayv2" - svcsdkapi "github.com/aws/aws-sdk-go/service/apigatewayv2/apigatewayv2iface" + svcapitypes "github.com/aws-controllers-k8s/apigatewayv2-controller/apis/v1alpha1" ) var ( _ = ackutil.InStrings + _ = acktags.NewTags() + _ = ackrt.MissingImageTagValue + _ = svcapitypes.VPCLink{} ) // +kubebuilder:rbac:groups=apigatewayv2.services.k8s.aws,resources=vpclinks,verbs=get;list;watch;create;update;patch;delete @@ -267,6 +273,32 @@ func (rm *resourceManager) IsSynced(ctx context.Context, res acktypes.AWSResourc return true, nil } +// EnsureTags ensures that tags are present inside the AWSResource. +// If the AWSResource does not have any existing resource tags, the 'tags' +// field is initialized and the controller tags are added. +// If the AWSResource has existing resource tags, then controller tags are +// added to the existing resource tags without overriding them. +// If the AWSResource does not support tags, only then the controller tags +// will not be added to the AWSResource. +func (rm *resourceManager) EnsureTags( + ctx context.Context, + res acktypes.AWSResource, + md acktypes.ServiceControllerMetadata, +) error { + r := rm.concreteResource(res) + if r.ko == nil { + // Should never happen... if it does, it's buggy code. + panic("resource manager's EnsureTags method received resource with nil CR object") + } + defaultTags := ackrt.GetDefaultTags(&rm.cfg, r.ko, md) + var existingTags map[string]*string + existingTags = r.ko.Spec.Tags + resourceTags := ToACKTags(existingTags) + tags := acktags.Merge(resourceTags, defaultTags) + r.ko.Spec.Tags = FromACKTags(tags) + return nil +} + // newResourceManager returns a new struct implementing // acktypes.AWSResourceManager func newResourceManager( diff --git a/pkg/resource/vpc_link/tags.go b/pkg/resource/vpc_link/tags.go new file mode 100644 index 0000000..98ccf20 --- /dev/null +++ b/pkg/resource/vpc_link/tags.go @@ -0,0 +1,59 @@ +// 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. + +// Code generated by ack-generate. DO NOT EDIT. + +package vpc_link + +import ( + acktags "github.com/aws-controllers-k8s/runtime/pkg/tags" + + svcapitypes "github.com/aws-controllers-k8s/apigatewayv2-controller/apis/v1alpha1" +) + +var ( + _ = svcapitypes.VPCLink{} + _ = acktags.NewTags() +) + +// ToACKTags converts the tags parameter into 'acktags.Tags' shape. +// This method helps in creating the hub(acktags.Tags) for merging +// default controller tags with existing resource tags. +func ToACKTags(tags map[string]*string) acktags.Tags { + result := acktags.NewTags() + if tags == nil || len(tags) == 0 { + return result + } + + for k, v := range tags { + if v == nil { + result[k] = "" + } else { + result[k] = *v + } + } + + return result +} + +// FromACKTags converts the tags parameter into map[string]*string shape. +// This method helps in setting the tags back inside AWSResource after merging +// default controller tags with existing resource tags. +func FromACKTags(tags acktags.Tags) map[string]*string { + result := map[string]*string{} + for k, v := range tags { + vCopy := v + result[k] = &vCopy + } + return result +} From 2d16de7875ced0f9a58baae98560461233f792cb Mon Sep 17 00:00:00 2001 From: vijtrip2 Date: Tue, 14 Jun 2022 12:43:03 -0700 Subject: [PATCH 2/3] allow tags as ImportApi input --- pkg/resource/api/custom_http_api.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/resource/api/custom_http_api.go b/pkg/resource/api/custom_http_api.go index 513b54f..e19c78a 100644 --- a/pkg/resource/api/custom_http_api.go +++ b/pkg/resource/api/custom_http_api.go @@ -96,6 +96,9 @@ func (rm *resourceManager) validateImportApiInputFields(api *v1alpha1.API) error specCopy.Body = nil specCopy.FailOnWarnings = nil specCopy.Basepath = nil + // Tags field is added with ACK default tags by ACK reconciler. + //Allow tag field to be present with other ImportApi fields. + specCopy.Tags = nil opts := []cmp.Option{cmpopts.EquateEmpty()} if cmp.Equal(*specCopy, v1alpha1.APISpec{}, opts...) { return nil From 978dd9ed767f66c1a855c5f32c82e16a0fccd61a Mon Sep 17 00:00:00 2001 From: vijtrip2 Date: Wed, 15 Jun 2022 09:37:49 -0700 Subject: [PATCH 3/3] handle partial reference resolution --- apis/v1alpha1/ack-generate-metadata.yaml | 6 +++--- helm/templates/_helpers.tpl | 10 ++++++++++ helm/templates/deployment.yaml | 16 ++++++++++++++++ helm/values.schema.json | 15 +++++++++++++++ helm/values.yaml | 7 +++++++ pkg/resource/authorizer/references.go | 5 +++++ pkg/resource/deployment/references.go | 5 +++++ pkg/resource/integration/references.go | 5 +++++ pkg/resource/route/references.go | 5 +++++ pkg/resource/stage/references.go | 5 +++++ 10 files changed, 76 insertions(+), 3 deletions(-) diff --git a/apis/v1alpha1/ack-generate-metadata.yaml b/apis/v1alpha1/ack-generate-metadata.yaml index 4e807d0..681aea9 100755 --- a/apis/v1alpha1/ack-generate-metadata.yaml +++ b/apis/v1alpha1/ack-generate-metadata.yaml @@ -1,8 +1,8 @@ ack_generate_info: - build_date: "2022-06-14T05:05:04Z" - build_hash: a133935a9a93591a9e1ba9d5ca940cb83a1353b4 + build_date: "2022-06-15T16:33:46Z" + build_hash: 53ebfaca89abd8cedbeb8e48ac76954a8e1841dd go_version: go1.17.5 - version: v0.19.0 + version: v0.19.0-2-g53ebfac api_directory_checksum: c69d75f37400a8d4d6eb4362eb743005531a7b2c api_version: v1alpha1 aws_sdk_go_version: v1.42.0 diff --git a/helm/templates/_helpers.tpl b/helm/templates/_helpers.tpl index 29265d7..973704c 100644 --- a/helm/templates/_helpers.tpl +++ b/helm/templates/_helpers.tpl @@ -36,3 +36,13 @@ If release name contains chart name it will be used as a full name. {{- .Release.Namespace -}} {{- end -}} {{- end -}} + +{{/* The mount path for the shared credentials file */}} +{{- define "aws.credentials.secret_mount_path" -}} +{{- "/var/run/secrets/aws" -}} +{{- end -}} + +{{/* The path the shared credentials file is mounted */}} +{{- define "aws.credentials.path" -}} +{{- printf "%s/%s" (include "aws.credentials.secret_mount_path" .) .Values.aws.credentials.secretKey -}} +{{- end -}} diff --git a/helm/templates/deployment.yaml b/helm/templates/deployment.yaml index d3a307a..9fd82f7 100644 --- a/helm/templates/deployment.yaml +++ b/helm/templates/deployment.yaml @@ -80,6 +80,16 @@ spec: value: {{ .Values.log.level | quote }} - name: ACK_RESOURCE_TAGS value: {{ join "," .Values.resourceTags | quote }} + {{- if .Values.aws.credentials.secretName }} + - name: AWS_SHARED_CREDENTIALS_FILE + value: {{ include "aws.credentials.path" . }} + - name: AWS_PROFILE + value: {{ .Values.aws.credentials.profile }} + volumeMounts: + - name: {{ .Values.aws.credentials.secretName }} + mountPath: {{ include "aws.credentials.secret_mount_path" . }} + readOnly: true + {{- end }} securityContext: allowPrivilegeEscalation: false privileged: false @@ -101,3 +111,9 @@ spec: hostIPC: false hostNetwork: false hostPID: false + {{ if .Values.aws.credentials.secretName -}} + volumes: + - name: {{ .Values.aws.credentials.secretName }} + secret: + secretName: {{ .Values.aws.credentials.secretName }} + {{ end -}} diff --git a/helm/values.schema.json b/helm/values.schema.json index e503248..c80422e 100644 --- a/helm/values.schema.json +++ b/helm/values.schema.json @@ -153,6 +153,21 @@ }, "endpoint": { "type": "string" + }, + "credentials": { + "description": "AWS credentials information", + "properties": { + "secretName": { + "type": "string" + }, + "secretKey": { + "type": "string" + }, + "profile": { + "type": "string" + } + }, + "type": "object" } }, "type": "object" diff --git a/helm/values.yaml b/helm/values.yaml index 3f068d8..dded9c7 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -50,6 +50,13 @@ aws: # If specified, use the AWS region for AWS API calls region: "" endpoint_url: "" + credentials: + # If specified, Secret with shared credentials file to use. + secretName: "" + # Secret stringData key that contains the credentials + secretKey: "credentials" + # Profile used for AWS credentials + profile: "default" # log level for the controller log: diff --git a/pkg/resource/authorizer/references.go b/pkg/resource/authorizer/references.go index ad56570..bb7b8bc 100644 --- a/pkg/resource/authorizer/references.go +++ b/pkg/resource/authorizer/references.go @@ -50,6 +50,11 @@ func (rm *resourceManager) ResolveReferences( err = resolveReferenceForAPIID(ctx, apiReader, namespace, ko) } + // If there was an error while resolving any reference, reset all the + // resolved values so that they do not get persisted inside etcd + if err != nil { + ko = rm.concreteResource(res).ko.DeepCopy() + } if hasNonNilReferences(ko) { return ackcondition.WithReferencesResolvedCondition(&resource{ko}, err) } diff --git a/pkg/resource/deployment/references.go b/pkg/resource/deployment/references.go index 681165b..27f3b5a 100644 --- a/pkg/resource/deployment/references.go +++ b/pkg/resource/deployment/references.go @@ -50,6 +50,11 @@ func (rm *resourceManager) ResolveReferences( err = resolveReferenceForAPIID(ctx, apiReader, namespace, ko) } + // If there was an error while resolving any reference, reset all the + // resolved values so that they do not get persisted inside etcd + if err != nil { + ko = rm.concreteResource(res).ko.DeepCopy() + } if hasNonNilReferences(ko) { return ackcondition.WithReferencesResolvedCondition(&resource{ko}, err) } diff --git a/pkg/resource/integration/references.go b/pkg/resource/integration/references.go index 34bbb4a..ddac80d 100644 --- a/pkg/resource/integration/references.go +++ b/pkg/resource/integration/references.go @@ -53,6 +53,11 @@ func (rm *resourceManager) ResolveReferences( err = resolveReferenceForConnectionID(ctx, apiReader, namespace, ko) } + // If there was an error while resolving any reference, reset all the + // resolved values so that they do not get persisted inside etcd + if err != nil { + ko = rm.concreteResource(res).ko.DeepCopy() + } if hasNonNilReferences(ko) { return ackcondition.WithReferencesResolvedCondition(&resource{ko}, err) } diff --git a/pkg/resource/route/references.go b/pkg/resource/route/references.go index 33292db..0b26f3b 100644 --- a/pkg/resource/route/references.go +++ b/pkg/resource/route/references.go @@ -63,6 +63,11 @@ func (rm *resourceManager) ResolveReferences( ko.Spec.Target = &targetStr } + // If there was an error while resolving any reference, reset all the + // resolved values so that they do not get persisted inside etcd + if err != nil { + ko = rm.concreteResource(res).ko.DeepCopy() + } if hasNonNilReferences(ko) { return ackcondition.WithReferencesResolvedCondition(&resource{ko}, err) } diff --git a/pkg/resource/stage/references.go b/pkg/resource/stage/references.go index 66dd39c..cab20d8 100644 --- a/pkg/resource/stage/references.go +++ b/pkg/resource/stage/references.go @@ -53,6 +53,11 @@ func (rm *resourceManager) ResolveReferences( err = resolveReferenceForDeploymentID(ctx, apiReader, namespace, ko) } + // If there was an error while resolving any reference, reset all the + // resolved values so that they do not get persisted inside etcd + if err != nil { + ko = rm.concreteResource(res).ko.DeepCopy() + } if hasNonNilReferences(ko) { return ackcondition.WithReferencesResolvedCondition(&resource{ko}, err) }