Skip to content

Commit eeda204

Browse files
committed
Add Adoption by annotation tests
1 parent b1893a4 commit eeda204

File tree

9 files changed

+124
-14
lines changed

9 files changed

+124
-14
lines changed

apis/v1alpha1/ack-generate-metadata.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
ack_generate_info:
2-
build_date: "2024-10-10T04:12:55Z"
3-
build_hash: 36c2d234498c2bc4f60773ab8df632af4067f43b
2+
build_date: "2024-12-02T23:36:35Z"
3+
build_hash: ce8a66e1fd3d15afacc33069bb788795863a4245
44
go_version: go1.23.2
5-
version: v0.39.1
5+
version: v0.39.1-6-gce8a66e
66
api_directory_checksum: 82bfc8d45e816b2a02a83a4b7cedd72056accddd
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.44.93

config/controller/deployment.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ spec:
4141
- "$(LEADER_ELECTION_NAMESPACE)"
4242
- --reconcile-default-max-concurrent-syncs
4343
- "$(RECONCILE_DEFAULT_MAX_CONCURRENT_SYNCS)"
44+
- --feature-gates
45+
- "$(FEATURE_GATES)"
4446
image: controller:latest
4547
name: controller
4648
ports:
@@ -76,6 +78,8 @@ spec:
7678
value: "ack-system"
7779
- name: "RECONCILE_DEFAULT_MAX_CONCURRENT_SYNCS"
7880
value: "1"
81+
- name: "FEATURE_GATES"
82+
value: ""
7983
securityContext:
8084
allowPrivilegeEscalation: false
8185
privileged: false

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.22.0
55
toolchain go1.22.5
66

77
require (
8-
github.com/aws-controllers-k8s/runtime v0.39.0
8+
github.com/aws-controllers-k8s/runtime v0.39.1-0.20241202082353-a6b0014a8130
99
github.com/aws/aws-sdk-go v1.49.0
1010
github.com/go-logr/logr v1.4.2
1111
github.com/pkg/errors v0.9.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/aws-controllers-k8s/runtime v0.39.0 h1:IgOXluSzvb4UcDr9eU7SPw5MJnL7kt5R6DuF5Qu9zVQ=
2-
github.com/aws-controllers-k8s/runtime v0.39.0/go.mod h1:G07g26y1cxyZO6Ngp+LwXf03CqFyLNL7os4Py4IdyGY=
1+
github.com/aws-controllers-k8s/runtime v0.39.1-0.20241202082353-a6b0014a8130 h1:EoXYRrpBX2hi5B1IawKr2LJTsVsreHsJdxULLlMNO9U=
2+
github.com/aws-controllers-k8s/runtime v0.39.1-0.20241202082353-a6b0014a8130/go.mod h1:G07g26y1cxyZO6Ngp+LwXf03CqFyLNL7os4Py4IdyGY=
33
github.com/aws/aws-sdk-go v1.49.0 h1:g9BkW1fo9GqKfwg2+zCD+TW/D36Ux+vtfJ8guF4AYmY=
44
github.com/aws/aws-sdk-go v1.49.0/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
55
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=

helm/templates/caches-role-binding.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ roleRef:
88
name: ack-namespaces-cache-s3-controller
99
subjects:
1010
- kind: ServiceAccount
11-
name: ack-s3-controller
11+
name: {{ include "ack-s3-controller.service-account.name" . }}
1212
namespace: {{ .Release.Namespace }}
1313
---
1414
apiVersion: rbac.authorization.k8s.io/v1
@@ -22,5 +22,5 @@ roleRef:
2222
name: ack-configmaps-cache-s3-controller
2323
subjects:
2424
- kind: ServiceAccount
25-
name: ack-s3-controller
26-
namespace: {{ .Release.Namespace }}
25+
name: {{ include "ack-s3-controller.service-account.name" . }}
26+
namespace: {{ .Release.Namespace }}

pkg/resource/bucket/descriptor.go

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/resource/bucket/resource.go

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: s3.services.k8s.aws/v1alpha1
2+
kind: Bucket
3+
metadata:
4+
name: $BUCKET_NAME
5+
annotations:
6+
services.k8s.aws/adoption-policy: $ADOPTION_POLICY
7+
services.k8s.aws/adoption-fields: $ADOPTION_FIELDS
8+
services.k8s.aws/deletion-policy: retain
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
# not use this file except in compliance with the License. A copy of the
5+
# License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is distributed
10+
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
# express or implied. See the License for the specific language governing
12+
# permissions and limitations under the License.
13+
14+
"""Integration tests for the deletion policy annotation on Bucket.
15+
"""
16+
17+
from enum import Enum
18+
import pytest
19+
import time
20+
import logging
21+
import itertools
22+
from typing import TYPE_CHECKING, Generator, List, NamedTuple, Tuple
23+
24+
from acktest.resources import random_suffix_name
25+
from acktest.k8s import resource as k8s
26+
from acktest import adoption as adoption
27+
from acktest import tags as tags
28+
from e2e import service_marker, CRD_GROUP, CRD_VERSION, load_s3_resource
29+
from e2e.tests.test_bucket import Bucket, bucket_exists, create_bucket, delete_bucket
30+
from e2e.replacement_values import REPLACEMENT_VALUES
31+
32+
CREATE_WAIT_AFTER_SECONDS = 10
33+
MODIFY_WAIT_AFTER_SECONDS = 10
34+
DELETE_WAIT_AFTER_SECONDS = 10
35+
36+
class AdoptionPolicy(str, Enum):
37+
NONE = ""
38+
ADOPT = "adopt"
39+
ADOPT_OR_CREATE = "adopt-or-create"
40+
41+
42+
@pytest.fixture(scope="function")
43+
def adoption_policy_adopt_bucket(s3_client):
44+
replacements = REPLACEMENT_VALUES.copy()
45+
bucket_name = replacements["REPLICATION_BUCKET_NAME"]
46+
replacements["BUCKET_NAME"] = bucket_name
47+
replacements["ADOPTION_POLICY"] = AdoptionPolicy.ADOPT
48+
replacements["ADOPTION_FIELDS"] = f'{{\"name\": \"{bucket_name}\"}}'
49+
50+
resource_data = load_s3_resource(
51+
"bucket_adoption_policy",
52+
additional_replacements=replacements,
53+
)
54+
55+
# Create k8s resource
56+
ref = k8s.CustomResourceReference(
57+
CRD_GROUP, CRD_VERSION, "buckets",
58+
bucket_name, namespace="default")
59+
k8s.create_custom_resource(ref, resource_data)
60+
61+
time.sleep(CREATE_WAIT_AFTER_SECONDS)
62+
cr = k8s.wait_resource_consumed_by_controller(ref)
63+
64+
assert cr is not None
65+
assert k8s.get_resource_exists(ref)
66+
67+
yield (ref, cr)
68+
69+
_, deleted = k8s.delete_custom_resource(ref, DELETE_WAIT_AFTER_SECONDS)
70+
assert deleted
71+
72+
73+
class TestAdoptionPolicyBucket:
74+
@pytest.mark.parametrize()
75+
def test_deletion_policy(
76+
self, adoption_policy_adopt_bucket, s3_client
77+
):
78+
(ref, cr) = adoption_policy_adopt_bucket
79+
80+
# Spec will be added by controller
81+
assert 'spec' in cr
82+
assert 'name' in cr['spec']
83+
bucket_name = cr['spec']['name']
84+
assert k8s.assert_synced(ref)
85+
# Check that the bucket exists in S3
86+
assert bucket_exists(s3_client, bucket_name)
87+

0 commit comments

Comments
 (0)