From 84fc0cde50918065412c7f8557e35da18e4bbf79 Mon Sep 17 00:00:00 2001 From: Amine Date: Fri, 19 May 2023 21:20:40 -0500 Subject: [PATCH] Support queues `RedriveAllowPolicy` Fixes https://github.com/aws-controllers-k8s/community/issues/1806 --- apis/v1alpha1/ack-generate-metadata.yaml | 8 ++++---- apis/v1alpha1/generator.yaml | 3 +++ apis/v1alpha1/queue.go | 1 + apis/v1alpha1/zz_generated.deepcopy.go | 5 +++++ config/controller/kustomization.yaml | 2 +- config/crd/bases/sqs.services.k8s.aws_queues.yaml | 2 ++ generator.yaml | 3 +++ helm/Chart.yaml | 4 ++-- helm/crds/sqs.services.k8s.aws_queues.yaml | 2 ++ helm/templates/NOTES.txt | 2 +- helm/values.yaml | 2 +- pkg/resource/queue/delta.go | 7 +++++++ pkg/resource/queue/sdk.go | 7 +++++++ test/e2e/tests/test_queue.py | 8 +++++++- 14 files changed, 46 insertions(+), 10 deletions(-) diff --git a/apis/v1alpha1/ack-generate-metadata.yaml b/apis/v1alpha1/ack-generate-metadata.yaml index 17f0d04..a0ed0b4 100755 --- a/apis/v1alpha1/ack-generate-metadata.yaml +++ b/apis/v1alpha1/ack-generate-metadata.yaml @@ -1,13 +1,13 @@ ack_generate_info: - build_date: "2023-05-15T22:57:03Z" + build_date: "2023-05-20T02:19:20Z" build_hash: 8f3ba427974fd6e769926778d54834eaee3b81a3 - go_version: go1.19 + go_version: go1.20.1 version: v0.26.1 -api_directory_checksum: 3741e855a47295ce5921a70cf58ca4fc020fae5d +api_directory_checksum: 3f2eabdb24056446ab978af269536dd7f2fef116 api_version: v1alpha1 aws_sdk_go_version: v1.44.93 generator_config_info: - file_checksum: 91bff6ceb1de65791e99fe6fa5f8edbc3dbd2323 + file_checksum: 9eac8d3730cfe212c3a88aa5173b22de93c2d0b7 original_file_name: generator.yaml last_modification: reason: API generation diff --git a/apis/v1alpha1/generator.yaml b/apis/v1alpha1/generator.yaml index 6b41eb9..d6e1730 100644 --- a/apis/v1alpha1/generator.yaml +++ b/apis/v1alpha1/generator.yaml @@ -56,6 +56,9 @@ resources: RedrivePolicy: is_attribute: true type: string + RedriveAllowPolicy: + is_attribute: true + type: string QueueArn: is_attribute: true is_arn: true diff --git a/apis/v1alpha1/queue.go b/apis/v1alpha1/queue.go index d184bae..394cdd6 100644 --- a/apis/v1alpha1/queue.go +++ b/apis/v1alpha1/queue.go @@ -35,6 +35,7 @@ type QueueSpec struct { // +kubebuilder:validation:Required QueueName *string `json:"queueName"` ReceiveMessageWaitTimeSeconds *string `json:"receiveMessageWaitTimeSeconds,omitempty"` + RedriveAllowPolicy *string `json:"redriveAllowPolicy,omitempty"` RedrivePolicy *string `json:"redrivePolicy,omitempty"` // Add cost allocation tags to the specified Amazon SQS queue. For an overview, // see Tagging Your Amazon SQS Queues (https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-queue-tags.html) diff --git a/apis/v1alpha1/zz_generated.deepcopy.go b/apis/v1alpha1/zz_generated.deepcopy.go index 5de831c..62a3163 100644 --- a/apis/v1alpha1/zz_generated.deepcopy.go +++ b/apis/v1alpha1/zz_generated.deepcopy.go @@ -357,6 +357,11 @@ func (in *QueueSpec) DeepCopyInto(out *QueueSpec) { *out = new(string) **out = **in } + if in.RedriveAllowPolicy != nil { + in, out := &in.RedriveAllowPolicy, &out.RedriveAllowPolicy + *out = new(string) + **out = **in + } if in.RedrivePolicy != nil { in, out := &in.RedrivePolicy, &out.RedrivePolicy *out = new(string) diff --git a/config/controller/kustomization.yaml b/config/controller/kustomization.yaml index cd4c063..8c8019d 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/sqs-controller - newTag: 1.0.3 + newTag: 1.0.2 diff --git a/config/crd/bases/sqs.services.k8s.aws_queues.yaml b/config/crd/bases/sqs.services.k8s.aws_queues.yaml index fc175e3..e7e2e5e 100644 --- a/config/crd/bases/sqs.services.k8s.aws_queues.yaml +++ b/config/crd/bases/sqs.services.k8s.aws_queues.yaml @@ -81,6 +81,8 @@ spec: type: string receiveMessageWaitTimeSeconds: type: string + redriveAllowPolicy: + type: string redrivePolicy: type: string tags: diff --git a/generator.yaml b/generator.yaml index 6b41eb9..d6e1730 100644 --- a/generator.yaml +++ b/generator.yaml @@ -56,6 +56,9 @@ resources: RedrivePolicy: is_attribute: true type: string + RedriveAllowPolicy: + is_attribute: true + type: string QueueArn: is_attribute: true is_arn: true diff --git a/helm/Chart.yaml b/helm/Chart.yaml index 01c326f..50b6a8e 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -1,8 +1,8 @@ apiVersion: v1 name: sqs-chart description: A Helm chart for the ACK service controller for Amazon Simple Queue Service (SQS) -version: 1.0.3 -appVersion: 1.0.3 +version: 1.0.2 +appVersion: 1.0.2 home: https://github.com/aws-controllers-k8s/sqs-controller icon: https://raw.githubusercontent.com/aws/eks-charts/master/docs/logo/aws.png sources: diff --git a/helm/crds/sqs.services.k8s.aws_queues.yaml b/helm/crds/sqs.services.k8s.aws_queues.yaml index 0499c4b..8402419 100644 --- a/helm/crds/sqs.services.k8s.aws_queues.yaml +++ b/helm/crds/sqs.services.k8s.aws_queues.yaml @@ -81,6 +81,8 @@ spec: type: string receiveMessageWaitTimeSeconds: type: string + redriveAllowPolicy: + type: string redrivePolicy: type: string tags: diff --git a/helm/templates/NOTES.txt b/helm/templates/NOTES.txt index 703da79..6df1052 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/sqs-controller:1.0.3". +This chart deploys "public.ecr.aws/aws-controllers-k8s/sqs-controller:1.0.2". 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 c247968..03ad4ae 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -4,7 +4,7 @@ image: repository: public.ecr.aws/aws-controllers-k8s/sqs-controller - tag: 1.0.3 + tag: 1.0.2 pullPolicy: IfNotPresent pullSecrets: [] diff --git a/pkg/resource/queue/delta.go b/pkg/resource/queue/delta.go index 69045e2..19c6e9a 100644 --- a/pkg/resource/queue/delta.go +++ b/pkg/resource/queue/delta.go @@ -119,6 +119,13 @@ func newResourceDelta( delta.Add("Spec.ReceiveMessageWaitTimeSeconds", a.ko.Spec.ReceiveMessageWaitTimeSeconds, b.ko.Spec.ReceiveMessageWaitTimeSeconds) } } + if ackcompare.HasNilDifference(a.ko.Spec.RedriveAllowPolicy, b.ko.Spec.RedriveAllowPolicy) { + delta.Add("Spec.RedriveAllowPolicy", a.ko.Spec.RedriveAllowPolicy, b.ko.Spec.RedriveAllowPolicy) + } else if a.ko.Spec.RedriveAllowPolicy != nil && b.ko.Spec.RedriveAllowPolicy != nil { + if *a.ko.Spec.RedriveAllowPolicy != *b.ko.Spec.RedriveAllowPolicy { + delta.Add("Spec.RedriveAllowPolicy", a.ko.Spec.RedriveAllowPolicy, b.ko.Spec.RedriveAllowPolicy) + } + } if ackcompare.HasNilDifference(a.ko.Spec.RedrivePolicy, b.ko.Spec.RedrivePolicy) { delta.Add("Spec.RedrivePolicy", a.ko.Spec.RedrivePolicy, b.ko.Spec.RedrivePolicy) } else if a.ko.Spec.RedrivePolicy != nil && b.ko.Spec.RedrivePolicy != nil { diff --git a/pkg/resource/queue/sdk.go b/pkg/resource/queue/sdk.go index 5deb57e..31ebfe0 100644 --- a/pkg/resource/queue/sdk.go +++ b/pkg/resource/queue/sdk.go @@ -100,6 +100,7 @@ func (rm *resourceManager) sdkFind( tmpARN := ackv1alpha1.AWSResourceName(*resp.Attributes["QueueArn"]) ko.Status.ACKResourceMetadata.ARN = &tmpARN ko.Spec.ReceiveMessageWaitTimeSeconds = resp.Attributes["ReceiveMessageWaitTimeSeconds"] + ko.Spec.RedriveAllowPolicy = resp.Attributes["RedriveAllowPolicy"] ko.Spec.RedrivePolicy = resp.Attributes["RedrivePolicy"] ko.Spec.VisibilityTimeout = resp.Attributes["VisibilityTimeout"] @@ -229,6 +230,9 @@ func (rm *resourceManager) newCreateRequestPayload( if r.ko.Spec.ReceiveMessageWaitTimeSeconds != nil { attrMap["ReceiveMessageWaitTimeSeconds"] = r.ko.Spec.ReceiveMessageWaitTimeSeconds } + if r.ko.Spec.RedriveAllowPolicy != nil { + attrMap["RedriveAllowPolicy"] = r.ko.Spec.RedriveAllowPolicy + } if r.ko.Spec.RedrivePolicy != nil { attrMap["RedrivePolicy"] = r.ko.Spec.RedrivePolicy } @@ -356,6 +360,9 @@ func (rm *resourceManager) newSetAttributesRequestPayload( if r.ko.Spec.ReceiveMessageWaitTimeSeconds != nil { attrMap["ReceiveMessageWaitTimeSeconds"] = r.ko.Spec.ReceiveMessageWaitTimeSeconds } + if r.ko.Spec.RedriveAllowPolicy != nil { + attrMap["RedriveAllowPolicy"] = r.ko.Spec.RedriveAllowPolicy + } if r.ko.Spec.RedrivePolicy != nil { attrMap["RedrivePolicy"] = r.ko.Spec.RedrivePolicy } diff --git a/test/e2e/tests/test_queue.py b/test/e2e/tests/test_queue.py index 570207a..c4e9f28 100644 --- a/test/e2e/tests/test_queue.py +++ b/test/e2e/tests/test_queue.py @@ -100,8 +100,13 @@ def test_crud(self, simple_queue): # Test updating one of the attributes... new_delay = "10" + redrive_policy = '{"redrivePermission":"denyAll"}' + updates = { - "spec": {"delaySeconds": new_delay}, + "spec": { + "delaySeconds": new_delay, + "redriveAllowPolicy": redrive_policy, + }, } k8s.patch_custom_resource(ref, updates) time.sleep(MODIFY_WAIT_AFTER_SECONDS) @@ -109,6 +114,7 @@ def test_crud(self, simple_queue): latest_attrs = sqsqueue.get_attributes(queue_url) assert 'DelaySeconds' in latest_attrs assert latest_attrs['DelaySeconds'] == new_delay + assert latest_attrs['RedriveAllowPolicy'] == redrive_policy # Test updating tags... assert 'tags' in cr['spec']