@@ -35,6 +35,7 @@ def simple_config():
35
35
resource_name = random_suffix_name ("my-config" , 24 )
36
36
replacements = REPLACEMENT_VALUES .copy ()
37
37
replacements ["CONFIG_NAME" ] = resource_name
38
+ replacements ["DELETION_POLICY" ] = "delete"
38
39
39
40
resource_data = load_resource (
40
41
"configuration_simple" , additional_replacements = replacements
@@ -61,6 +62,66 @@ def simple_config():
61
62
except :
62
63
pass
63
64
65
+ @pytest .fixture (scope = "module" )
66
+ def adoption_config ():
67
+ resource_name = random_suffix_name ("my-config" , 24 )
68
+ replacements = REPLACEMENT_VALUES .copy ()
69
+ replacements ["CONFIG_NAME" ] = resource_name
70
+ replacements ["DELETION_POLICY" ] = "retain"
71
+
72
+ resource_data = load_resource (
73
+ "configuration_simple" , additional_replacements = replacements
74
+ )
75
+
76
+ ref = k8s .CustomResourceReference (
77
+ CRD_GROUP ,
78
+ CRD_VERSION ,
79
+ CONFIG_RESOURCE_PLURAL ,
80
+ resource_name ,
81
+ namespace = "default" ,
82
+ )
83
+ k8s .create_custom_resource (ref , resource_data )
84
+ cr = k8s .wait_resource_consumed_by_controller (ref )
85
+
86
+ assert cr is not None
87
+ assert k8s .get_resource_exists (ref )
88
+ time .sleep (CREATE_WAIT_SECONDS )
89
+
90
+ assert "status" in cr
91
+ assert "ackResourceMetadata" in cr ["status" ]
92
+ assert "arn" in cr ["status" ]["ackResourceMetadata" ]
93
+ arn = cr ["status" ]["ackResourceMetadata" ]["arn" ]
94
+
95
+ #Delete with retain policy allows us to adopt same resource
96
+ _ , deleted = k8s .delete_custom_resource (ref , 3 , 10 )
97
+ assert deleted
98
+
99
+ replacements ["ADOPTION_FIELDS" ] = f'{{\\ \" arn\\ \" : \\ \" { arn } \\ \" }}'
100
+ resource_data = load_resource (
101
+ "configuration_adopt" , additional_replacements = replacements
102
+ )
103
+
104
+ ref = k8s .CustomResourceReference (
105
+ CRD_GROUP ,
106
+ CRD_VERSION ,
107
+ CONFIG_RESOURCE_PLURAL ,
108
+ resource_name ,
109
+ namespace = "default" ,
110
+ )
111
+ k8s .create_custom_resource (ref , resource_data )
112
+ cr = k8s .wait_resource_consumed_by_controller (ref )
113
+
114
+ assert cr is not None
115
+ assert k8s .get_resource_exists (ref )
116
+
117
+ yield (ref , cr )
118
+
119
+ try :
120
+ _ , deleted = k8s .delete_custom_resource (ref , DELETE_WAIT_SECONDS )
121
+ assert deleted
122
+ except :
123
+ pass
124
+
64
125
65
126
@service_marker
66
127
@pytest .mark .canary
@@ -101,3 +162,15 @@ def test_crud(self, simple_config):
101
162
102
163
latest = get_by_arn (config_arn )
103
164
assert latest is None
165
+
166
+ def test_adopt (seld , adoption_config ):
167
+ ref , cr = adoption_config
168
+ time .sleep (CREATE_WAIT_SECONDS )
169
+
170
+ assert "status" in cr
171
+ assert "ackResourceMetadata" in cr ["status" ]
172
+ assert "arn" in cr ["status" ]["ackResourceMetadata" ]
173
+
174
+ assert "spec" in cr
175
+ assert "serverProperties" in cr ["spec" ]
176
+
0 commit comments