From 02ff015f13c82ea0f7dd6131510445ebb05aa10a Mon Sep 17 00:00:00 2001 From: Muvaffak Onus Date: Wed, 17 Nov 2021 02:54:44 +0300 Subject: [PATCH 1/3] kms.alias: make it manually-written because removing parameters cause empty spec which makes the for loops in conversion functions throw compile errors since there is nothing to process and variables end up unused Signed-off-by: Muvaffak Onus (cherry picked from commit 8245751816c49c4d8b1e2356cf85011eb33b71a3) --- apis/kms/v1alpha1/{zz_alias.go => alias.go} | 39 +++++++++++---- apis/kms/v1alpha1/custom_types.go | 17 ------- apis/kms/v1alpha1/generator-config.yaml | 8 +-- apis/kms/v1alpha1/zz_generated.deepcopy.go | 50 +++++-------------- ...ferencers.go => zz_generated.resolvers.go} | 31 ++++++++---- apis/kms/v1alpha1/zz_types.go | 2 - examples/kms/alias.yaml | 3 +- .../crds/kms.aws.crossplane.io_aliases.yaml | 22 +++----- .../alias/{zz_controller.go => controller.go} | 2 - .../{zz_conversions.go => conversions.go} | 32 +++--------- pkg/controller/kms/alias/setup.go | 49 ++++++++---------- 11 files changed, 98 insertions(+), 157 deletions(-) rename apis/kms/v1alpha1/{zz_alias.go => alias.go} (68%) rename apis/kms/v1alpha1/{referencers.go => zz_generated.resolvers.go} (67%) rename pkg/controller/kms/alias/{zz_controller.go => controller.go} (99%) rename pkg/controller/kms/alias/{zz_conversions.go => conversions.go} (73%) diff --git a/apis/kms/v1alpha1/zz_alias.go b/apis/kms/v1alpha1/alias.go similarity index 68% rename from apis/kms/v1alpha1/zz_alias.go rename to apis/kms/v1alpha1/alias.go index 4465ddfe1d..326cf16de8 100644 --- a/apis/kms/v1alpha1/zz_alias.go +++ b/apis/kms/v1alpha1/alias.go @@ -14,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by ack-generate. DO NOT EDIT. - package v1alpha1 import ( @@ -29,16 +27,35 @@ type AliasParameters struct { // Region is which region the Alias will be created. // +kubebuilder:validation:Required Region string `json:"region"` - // Specifies the alias name. This value must begin with alias/ followed by a - // name, such as alias/ExampleAlias. + + // Associates the alias with the specified customer managed CMK (https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#customer-cmk). + // The CMK must be in the same AWS Region. // - // The AliasName value must be string of 1-256 characters. It can contain only - // alphanumeric characters, forward slashes (/), underscores (_), and dashes - // (-). The alias name cannot begin with alias/aws/. The alias/aws/ prefix is - // reserved for AWS managed CMKs (https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#aws-managed-cmk). - // +kubebuilder:validation:Required - AliasName *string `json:"aliasName"` - CustomAliasParameters `json:",inline"` + // A valid CMK ID is required. If you supply a null or empty string value, this + // operation returns an error. + // + // For help finding the key ID and ARN, see Finding the Key ID and ARN (https://docs.aws.amazon.com/kms/latest/developerguide/viewing-keys.html#find-cmk-id-arn) + // in the AWS Key Management Service Developer Guide. + // + // Specify the key ID or the Amazon Resource Name (ARN) of the CMK. + // + // For example: + // + // * Key ID: 1234abcd-12ab-34cd-56ef-1234567890ab + // + // * Key ARN: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab + // + // To get the key ID and key ARN for a CMK, use ListKeys or DescribeKey. + // +crossplane:generate:reference:type=Key + TargetKeyID *string `json:"targetKeyId,omitempty"` + + // TargetKeyIDRef is a reference to a KMS Key used to set TargetKeyID. + // +optional + TargetKeyIDRef *xpv1.Reference `json:"targetKeyIdRef,omitempty"` + + // TargetKeyIDSelector selects a reference to a KMS Key used to set TargetKeyID. + // +optional + TargetKeyIDSelector *xpv1.Selector `json:"targetKeyIdSelector,omitempty"` } // AliasSpec defines the desired state of Alias diff --git a/apis/kms/v1alpha1/custom_types.go b/apis/kms/v1alpha1/custom_types.go index 06ac457f2d..3fcf5b6141 100644 --- a/apis/kms/v1alpha1/custom_types.go +++ b/apis/kms/v1alpha1/custom_types.go @@ -1,7 +1,5 @@ package v1alpha1 -import xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" - // CustomKeyParameters are custom parameters for Key. type CustomKeyParameters struct { // Specifies whether the CMK is enabled. @@ -10,18 +8,3 @@ type CustomKeyParameters struct { // Specifies how many days the Key is retained when scheduled for deletion. Defaults to 30 days. PendingWindowInDays *int64 `json:"pendingWindowInDays,omitempty"` } - -// CustomAliasParameters are custom parameters for Alias. -type CustomAliasParameters struct { - // Associates the alias with the specified customer managed CMK (https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#customer-cmk). The CMK must be in the same AWS Region. \n A valid CMK ID is required. If you supply a null or empty string value, this operation returns an error. \n For help finding the key ID and ARN, see Finding the Key ID and ARN (https://docs.aws.amazon.com/kms/latest/developerguide/viewing-keys.html#find-cmk-id-arn) in the AWS Key Management Service Developer Guide. \n Specify the key ID or the Amazon Resource Name (ARN) of the CMK. \n For example: \n * Key ID: 1234abcd-12ab-34cd-56ef-1234567890ab \n * Key ARN: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab \n To get the key ID and key ARN for a CMK, use ListKeys or DescribeKey. - // +optional - TargetKeyID *string `json:"targetKeyID,omitempty"` - - // TargetKeyIDRef is a reference to a KMS Key used to set TargetKeyID. - // +optional - TargetKeyIDRef *xpv1.Reference `json:"targetKeyIDRef,omitempty"` - - // TargetKeyIDSelector selects a reference to a KMS Key used to set TargetKeyID. - // +optional - TargetKeyIDSelector *xpv1.Selector `json:"targetKeyIDSelector,omitempty"` -} diff --git a/apis/kms/v1alpha1/generator-config.yaml b/apis/kms/v1alpha1/generator-config.yaml index e9a1deea29..e6fdf82ab9 100644 --- a/apis/kms/v1alpha1/generator-config.yaml +++ b/apis/kms/v1alpha1/generator-config.yaml @@ -2,8 +2,7 @@ ignore: resource_names: - CustomKeyStore - Grant - field_paths: - - CreateAliasInput.TargetKeyId + - Alias resources: Key: exceptions: @@ -12,8 +11,3 @@ resources: # so the IsNotFound() function is generated correctly 404: code: NotFoundException - Alias: - exceptions: - errors: - 404: - code: NotFoundException diff --git a/apis/kms/v1alpha1/zz_generated.deepcopy.go b/apis/kms/v1alpha1/zz_generated.deepcopy.go index 4316fb7eda..6beb24b9b5 100644 --- a/apis/kms/v1alpha1/zz_generated.deepcopy.go +++ b/apis/kms/v1alpha1/zz_generated.deepcopy.go @@ -92,11 +92,6 @@ func (in *AliasListEntry) DeepCopyInto(out *AliasListEntry) { *out = new(string) **out = **in } - if in.AliasName != nil { - in, out := &in.AliasName, &out.AliasName - *out = new(string) - **out = **in - } if in.CreationDate != nil { in, out := &in.CreationDate, &out.CreationDate *out = (*in).DeepCopy() @@ -140,12 +135,21 @@ func (in *AliasObservation) DeepCopy() *AliasObservation { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *AliasParameters) DeepCopyInto(out *AliasParameters) { *out = *in - if in.AliasName != nil { - in, out := &in.AliasName, &out.AliasName + if in.TargetKeyID != nil { + in, out := &in.TargetKeyID, &out.TargetKeyID *out = new(string) **out = **in } - in.CustomAliasParameters.DeepCopyInto(&out.CustomAliasParameters) + if in.TargetKeyIDRef != nil { + in, out := &in.TargetKeyIDRef, &out.TargetKeyIDRef + *out = new(v1.Reference) + **out = **in + } + if in.TargetKeyIDSelector != nil { + in, out := &in.TargetKeyIDSelector, &out.TargetKeyIDSelector + *out = new(v1.Selector) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AliasParameters. @@ -192,36 +196,6 @@ func (in *AliasStatus) DeepCopy() *AliasStatus { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CustomAliasParameters) DeepCopyInto(out *CustomAliasParameters) { - *out = *in - if in.TargetKeyID != nil { - in, out := &in.TargetKeyID, &out.TargetKeyID - *out = new(string) - **out = **in - } - if in.TargetKeyIDRef != nil { - in, out := &in.TargetKeyIDRef, &out.TargetKeyIDRef - *out = new(v1.Reference) - **out = **in - } - if in.TargetKeyIDSelector != nil { - in, out := &in.TargetKeyIDSelector, &out.TargetKeyIDSelector - *out = new(v1.Selector) - (*in).DeepCopyInto(*out) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CustomAliasParameters. -func (in *CustomAliasParameters) DeepCopy() *CustomAliasParameters { - if in == nil { - return nil - } - out := new(CustomAliasParameters) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CustomKeyParameters) DeepCopyInto(out *CustomKeyParameters) { *out = *in diff --git a/apis/kms/v1alpha1/referencers.go b/apis/kms/v1alpha1/zz_generated.resolvers.go similarity index 67% rename from apis/kms/v1alpha1/referencers.go rename to apis/kms/v1alpha1/zz_generated.resolvers.go index ba319a957b..05b6b1c2a9 100644 --- a/apis/kms/v1alpha1/referencers.go +++ b/apis/kms/v1alpha1/zz_generated.resolvers.go @@ -1,9 +1,12 @@ /* -Copyright 2021 The Crossplane Authors. +Copyright 2020 The Crossplane Authors. + Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -11,30 +14,36 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Code generated by angryjet. DO NOT EDIT. + package v1alpha1 import ( "context" - - "github.com/crossplane/crossplane-runtime/pkg/reference" - "github.com/pkg/errors" - "sigs.k8s.io/controller-runtime/pkg/client" + reference "github.com/crossplane/crossplane-runtime/pkg/reference" + errors "github.com/pkg/errors" + client "sigs.k8s.io/controller-runtime/pkg/client" ) -// ResolveReferences of this Alias +// ResolveReferences of this Alias. func (mg *Alias) ResolveReferences(ctx context.Context, c client.Reader) error { r := reference.NewAPIResolver(c, mg) - // Resolve spec.forProvider.targetKeyID - rsp, err := r.Resolve(ctx, reference.ResolutionRequest{ + var rsp reference.ResolutionResponse + var err error + + rsp, err = r.Resolve(ctx, reference.ResolutionRequest{ CurrentValue: reference.FromPtrValue(mg.Spec.ForProvider.TargetKeyID), + Extract: reference.ExternalName(), Reference: mg.Spec.ForProvider.TargetKeyIDRef, Selector: mg.Spec.ForProvider.TargetKeyIDSelector, - To: reference.To{Managed: &Key{}, List: &KeyList{}}, - Extract: reference.ExternalName(), + To: reference.To{ + List: &KeyList{}, + Managed: &Key{}, + }, }) if err != nil { - return errors.Wrap(err, "spec.forProvider.targetKeyID") + return errors.Wrap(err, "mg.Spec.ForProvider.TargetKeyID") } mg.Spec.ForProvider.TargetKeyID = reference.ToPtrValue(rsp.ResolvedValue) mg.Spec.ForProvider.TargetKeyIDRef = rsp.ResolvedReference diff --git a/apis/kms/v1alpha1/zz_types.go b/apis/kms/v1alpha1/zz_types.go index a43f25b449..153ea22ea3 100644 --- a/apis/kms/v1alpha1/zz_types.go +++ b/apis/kms/v1alpha1/zz_types.go @@ -30,8 +30,6 @@ var ( type AliasListEntry struct { AliasARN *string `json:"aliasARN,omitempty"` - AliasName *string `json:"aliasName,omitempty"` - CreationDate *metav1.Time `json:"creationDate,omitempty"` LastUpdatedDate *metav1.Time `json:"lastUpdatedDate,omitempty"` diff --git a/examples/kms/alias.yaml b/examples/kms/alias.yaml index e296eea338..9c27a42055 100644 --- a/examples/kms/alias.yaml +++ b/examples/kms/alias.yaml @@ -5,8 +5,7 @@ metadata: spec: forProvider: region: us-east-1 - aliasName: alias/dev-key - targetKeyIDRef: + targetKeyIdRef: name: dev-key providerConfigRef: name: example diff --git a/package/crds/kms.aws.crossplane.io_aliases.yaml b/package/crds/kms.aws.crossplane.io_aliases.yaml index 050932e6f2..2a97095b1a 100644 --- a/package/crds/kms.aws.crossplane.io_aliases.yaml +++ b/package/crds/kms.aws.crossplane.io_aliases.yaml @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.4.0 + controller-gen.kubebuilder.io/version: v0.6.2 creationTimestamp: null name: aliases.kms.aws.crossplane.io spec: @@ -60,20 +60,11 @@ spec: forProvider: description: AliasParameters defines the desired state of Alias properties: - aliasName: - description: "Specifies the alias name. This value must begin - with alias/ followed by a name, such as alias/ExampleAlias. - \n The AliasName value must be string of 1-256 characters. It - can contain only alphanumeric characters, forward slashes (/), - underscores (_), and dashes (-). The alias name cannot begin - with alias/aws/. The alias/aws/ prefix is reserved for AWS managed - CMKs (https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#aws-managed-cmk)." - type: string region: description: Region is which region the Alias will be created. type: string - targetKeyID: - description: 'Associates the alias with the specified customer + targetKeyId: + description: "Associates the alias with the specified customer managed CMK (https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#customer-cmk). The CMK must be in the same AWS Region. \n A valid CMK ID is required. If you supply a null or empty string value, this operation @@ -84,9 +75,9 @@ spec: For example: \n * Key ID: 1234abcd-12ab-34cd-56ef-1234567890ab \n * Key ARN: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab \n To get the key ID and key ARN for a CMK, use ListKeys or - DescribeKey.' + DescribeKey." type: string - targetKeyIDRef: + targetKeyIdRef: description: TargetKeyIDRef is a reference to a KMS Key used to set TargetKeyID. properties: @@ -96,7 +87,7 @@ spec: required: - name type: object - targetKeyIDSelector: + targetKeyIdSelector: description: TargetKeyIDSelector selects a reference to a KMS Key used to set TargetKeyID. properties: @@ -112,7 +103,6 @@ spec: type: object type: object required: - - aliasName - region type: object providerConfigRef: diff --git a/pkg/controller/kms/alias/zz_controller.go b/pkg/controller/kms/alias/controller.go similarity index 99% rename from pkg/controller/kms/alias/zz_controller.go rename to pkg/controller/kms/alias/controller.go index d426981b80..6612c9903e 100644 --- a/pkg/controller/kms/alias/zz_controller.go +++ b/pkg/controller/kms/alias/controller.go @@ -14,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by ack-generate. DO NOT EDIT. - package alias import ( diff --git a/pkg/controller/kms/alias/zz_conversions.go b/pkg/controller/kms/alias/conversions.go similarity index 73% rename from pkg/controller/kms/alias/zz_conversions.go rename to pkg/controller/kms/alias/conversions.go index a32b96c39a..3c20de6889 100644 --- a/pkg/controller/kms/alias/zz_conversions.go +++ b/pkg/controller/kms/alias/conversions.go @@ -14,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by ack-generate. DO NOT EDIT. - package alias import ( @@ -30,7 +28,7 @@ import ( // GenerateListAliasesInput returns input for read // operation. -func GenerateListAliasesInput(cr *svcapitypes.Alias) *svcsdk.ListAliasesInput { +func GenerateListAliasesInput(_ *svcapitypes.Alias) *svcsdk.ListAliasesInput { res := &svcsdk.ListAliasesInput{} return res @@ -39,21 +37,11 @@ func GenerateListAliasesInput(cr *svcapitypes.Alias) *svcsdk.ListAliasesInput { // GenerateAlias returns the current state in the form of *svcapitypes.Alias. func GenerateAlias(resp *svcsdk.ListAliasesOutput) *svcapitypes.Alias { cr := &svcapitypes.Alias{} - - found := false for _, elem := range resp.Aliases { - if elem.AliasName != nil { - cr.Spec.ForProvider.AliasName = elem.AliasName - } else { - cr.Spec.ForProvider.AliasName = nil + if elem.TargetKeyId != nil { + cr.Spec.ForProvider.TargetKeyID = elem.TargetKeyId } - found = true - break - } - if !found { - return cr } - return cr } @@ -61,8 +49,8 @@ func GenerateAlias(resp *svcsdk.ListAliasesOutput) *svcapitypes.Alias { func GenerateCreateAliasInput(cr *svcapitypes.Alias) *svcsdk.CreateAliasInput { res := &svcsdk.CreateAliasInput{} - if cr.Spec.ForProvider.AliasName != nil { - res.SetAliasName(*cr.Spec.ForProvider.AliasName) + if cr.Spec.ForProvider.TargetKeyID != nil { + res.SetTargetKeyId(*cr.Spec.ForProvider.TargetKeyID) } return res @@ -72,21 +60,17 @@ func GenerateCreateAliasInput(cr *svcapitypes.Alias) *svcsdk.CreateAliasInput { func GenerateUpdateAliasInput(cr *svcapitypes.Alias) *svcsdk.UpdateAliasInput { res := &svcsdk.UpdateAliasInput{} - if cr.Spec.ForProvider.AliasName != nil { - res.SetAliasName(*cr.Spec.ForProvider.AliasName) + if cr.Spec.ForProvider.TargetKeyID != nil { + res.SetTargetKeyId(*cr.Spec.ForProvider.TargetKeyID) } return res } // GenerateDeleteAliasInput returns a deletion input. -func GenerateDeleteAliasInput(cr *svcapitypes.Alias) *svcsdk.DeleteAliasInput { +func GenerateDeleteAliasInput(_ *svcapitypes.Alias) *svcsdk.DeleteAliasInput { res := &svcsdk.DeleteAliasInput{} - if cr.Spec.ForProvider.AliasName != nil { - res.SetAliasName(*cr.Spec.ForProvider.AliasName) - } - return res } diff --git a/pkg/controller/kms/alias/setup.go b/pkg/controller/kms/alias/setup.go index d8971e5f78..4d6ba2f1f9 100644 --- a/pkg/controller/kms/alias/setup.go +++ b/pkg/controller/kms/alias/setup.go @@ -15,7 +15,6 @@ package alias import ( "context" - "strings" "time" xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" @@ -40,57 +39,53 @@ func SetupAlias(mgr ctrl.Manager, l logging.Logger, limiter workqueue.RateLimite name := managed.ControllerName(svcapitypes.AliasGroupKind) opts := []option{ func(e *external) { - e.postCreate = postCreate + e.preObserve = preObserve e.postObserve = postObserve e.preCreate = preCreate + e.preUpdate = preUpdate + e.preDelete = preDelete }, } return ctrl.NewControllerManagedBy(mgr). Named(name). WithOptions(controller.Options{ - RateLimiter: ratelimiter.NewDefaultManagedRateLimiter(limiter), + RateLimiter: ratelimiter.NewController(limiter), }). For(&svcapitypes.Alias{}). Complete(managed.NewReconciler(mgr, resource.ManagedKind(svcapitypes.AliasGroupVersionKind), - managed.WithInitializers(managed.NewDefaultProviderConfig(mgr.GetClient())), managed.WithExternalConnecter(&connector{kube: mgr.GetClient(), opts: opts}), managed.WithPollInterval(poll), managed.WithLogger(l.WithValues("controller", name)), managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))))) } +func preObserve(_ context.Context, cr *svcapitypes.Alias, obj *svcsdk.ListAliasesInput) error { + obj.KeyId = cr.Spec.ForProvider.TargetKeyID + return nil +} + func preCreate(_ context.Context, cr *svcapitypes.Alias, obj *svcsdk.CreateAliasInput) error { + obj.AliasName = awsclients.String("alias/" + meta.GetExternalName(cr)) obj.TargetKeyId = cr.Spec.ForProvider.TargetKeyID return nil } -func postCreate(_ context.Context, cr *svcapitypes.Alias, obj *svcsdk.CreateAliasOutput, cre managed.ExternalCreation, err error) (managed.ExternalCreation, error) { - if err != nil { - return managed.ExternalCreation{}, err - } - // CreateAliasOutput is empty - meta.SetExternalName(cr, *cr.Spec.ForProvider.AliasName) - return managed.ExternalCreation{ExternalNameAssigned: true}, nil +func preUpdate(_ context.Context, cr *svcapitypes.Alias, obj *svcsdk.UpdateAliasInput) error { + obj.AliasName = awsclients.String("alias/" + meta.GetExternalName(cr)) + obj.TargetKeyId = cr.Spec.ForProvider.TargetKeyID + return nil +} + +func preDelete(_ context.Context, cr *svcapitypes.Alias, obj *svcsdk.DeleteAliasInput) (bool, error) { + obj.AliasName = awsclients.String("alias/" + meta.GetExternalName(cr)) + return false, nil } -func postObserve(_ context.Context, cr *svcapitypes.Alias, obj *svcsdk.ListAliasesOutput, obs managed.ExternalObservation, err error) (managed.ExternalObservation, error) { +func postObserve(_ context.Context, cr *svcapitypes.Alias, _ *svcsdk.ListAliasesOutput, obs managed.ExternalObservation, err error) (managed.ExternalObservation, error) { if err != nil { return managed.ExternalObservation{}, err } - - // get all alias - for i := range obj.Aliases { - if awsclients.StringValue(obj.Aliases[i].AliasName) == awsclients.StringValue(cr.Spec.ForProvider.AliasName) { - // obj.Aliases[i].TargetKeyId is in ListAliasesOutput the KMSKey.ARN - if strings.Contains(awsclients.StringValue(cr.Spec.ForProvider.TargetKeyID), awsclients.StringValue(obj.Aliases[i].TargetKeyId)) { - // alias found and TargetKeyId included - cr.SetConditions(xpv1.Available()) - return obs, nil - } - } - } - - cr.SetConditions(xpv1.Unavailable()) - return managed.ExternalObservation{}, err + cr.SetConditions(xpv1.Available()) + return obs, nil } From 041f07641a0fd5ee534504865b9e33609d4234f2 Mon Sep 17 00:00:00 2001 From: Muvaffak Onus Date: Wed, 17 Nov 2021 03:18:33 +0300 Subject: [PATCH 2/3] kms.key: assume the key is removed once it is in pendingdeletion state otherwise it will not go away for days. Signed-off-by: Muvaffak Onus (cherry picked from commit 80e13ee37ced99c3ec9ec57d9585b3c5c5adfdc4) --- pkg/controller/kms/key/setup.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/controller/kms/key/setup.go b/pkg/controller/kms/key/setup.go index f40a26f0a4..8b1d6d7fe2 100644 --- a/pkg/controller/kms/key/setup.go +++ b/pkg/controller/kms/key/setup.go @@ -72,6 +72,7 @@ func postObserve(_ context.Context, cr *svcapitypes.Key, obj *svcsdk.DescribeKey cr.SetConditions(xpv1.Unavailable()) case string(svcapitypes.KeyState_PendingDeletion): cr.SetConditions(xpv1.Deleting()) + return managed.ExternalObservation{ResourceExists: false}, nil case string(svcapitypes.KeyState_PendingImport): cr.SetConditions(xpv1.Unavailable()) case string(svcapitypes.KeyState_Unavailable): From 6410d9e5e9e0f5ba555f43128ed65607ad4af758 Mon Sep 17 00:00:00 2001 From: Muvaffak Onus Date: Wed, 17 Nov 2021 03:47:25 +0300 Subject: [PATCH 3/3] kms.alias: filter the alias list with alias name Signed-off-by: Muvaffak Onus (cherry picked from commit 4980bd551a801866285fe66b9d7e57ac94de23b4) --- apis/kms/v1alpha1/alias.go | 3 +++ examples/kms/alias.yaml | 2 +- pkg/controller/kms/alias/controller.go | 3 +++ pkg/controller/kms/alias/conversions.go | 3 +++ pkg/controller/kms/alias/setup.go | 13 +++++++++++++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/apis/kms/v1alpha1/alias.go b/apis/kms/v1alpha1/alias.go index 326cf16de8..73d31e25da 100644 --- a/apis/kms/v1alpha1/alias.go +++ b/apis/kms/v1alpha1/alias.go @@ -14,6 +14,9 @@ See the License for the specific language governing permissions and limitations under the License. */ +// NOTE(muvaf): This code ported from ACK-generated code. See details here: +// https://github.com/crossplane/provider-aws/pull/950#issue-1055573793 + package v1alpha1 import ( diff --git a/examples/kms/alias.yaml b/examples/kms/alias.yaml index 9c27a42055..aaa120d8c2 100644 --- a/examples/kms/alias.yaml +++ b/examples/kms/alias.yaml @@ -1,7 +1,7 @@ apiVersion: kms.aws.crossplane.io/v1alpha1 kind: Alias metadata: - name: dev-key + name: dev-alias spec: forProvider: region: us-east-1 diff --git a/pkg/controller/kms/alias/controller.go b/pkg/controller/kms/alias/controller.go index 6612c9903e..8ad3c8dd1a 100644 --- a/pkg/controller/kms/alias/controller.go +++ b/pkg/controller/kms/alias/controller.go @@ -14,6 +14,9 @@ See the License for the specific language governing permissions and limitations under the License. */ +// NOTE(muvaf): This code ported from ACK-generated code. See details here: +// https://github.com/crossplane/provider-aws/pull/950#issue-1055573793 + package alias import ( diff --git a/pkg/controller/kms/alias/conversions.go b/pkg/controller/kms/alias/conversions.go index 3c20de6889..1dfbba802a 100644 --- a/pkg/controller/kms/alias/conversions.go +++ b/pkg/controller/kms/alias/conversions.go @@ -14,6 +14,9 @@ See the License for the specific language governing permissions and limitations under the License. */ +// NOTE(muvaf): This code ported from ACK-generated code. See details here: +// https://github.com/crossplane/provider-aws/pull/950#issue-1055573793 + package alias import ( diff --git a/pkg/controller/kms/alias/setup.go b/pkg/controller/kms/alias/setup.go index 4d6ba2f1f9..7e355611de 100644 --- a/pkg/controller/kms/alias/setup.go +++ b/pkg/controller/kms/alias/setup.go @@ -44,6 +44,7 @@ func SetupAlias(mgr ctrl.Manager, l logging.Logger, limiter workqueue.RateLimite e.preCreate = preCreate e.preUpdate = preUpdate e.preDelete = preDelete + e.filterList = filterList }, } return ctrl.NewControllerManagedBy(mgr). @@ -60,6 +61,18 @@ func SetupAlias(mgr ctrl.Manager, l logging.Logger, limiter workqueue.RateLimite managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))))) } +func filterList(cr *svcapitypes.Alias, list *svcsdk.ListAliasesOutput) *svcsdk.ListAliasesOutput { + for i := range list.Aliases { + if awsclients.StringValue(list.Aliases[i].AliasName) == "alias/"+meta.GetExternalName(cr) { + return &svcsdk.ListAliasesOutput{ + Aliases: []*svcsdk.AliasListEntry{ + list.Aliases[i], + }} + } + } + return &svcsdk.ListAliasesOutput{} +} + func preObserve(_ context.Context, cr *svcapitypes.Alias, obj *svcsdk.ListAliasesInput) error { obj.KeyId = cr.Spec.ForProvider.TargetKeyID return nil