66import yaml
77from kopf ._core .intents .causes import Reason
88
9- from app .api .tests .factories import BASE64_OF_VALID_CA_CERT
109from app .crds import ResourceType
1110from app .handlers .handlers_services import (
1211 ALLOWED_EXTRA_ANNOTATIONS ,
1514 service_to_twingate_resource ,
1615 twingate_service_create ,
1716)
18- from app .utils_k8s import get_ca_cert
1917
2018# Ignore the fact we use _cogs here
2119
@@ -173,25 +171,13 @@ def test_with_extra_annotation(
173171 assert result == expected
174172
175173 def test_kubernetes_resource_type_annotation (
176- self ,
177- example_cluster_ip_gateway_service_body ,
178- k8s_core_client_mock ,
179- k8s_tls_secret_mock ,
174+ self , example_cluster_ip_gateway_service_body
180175 ):
181176 tls_object_name = "gateway-tls"
182177 namespace = "custom-namespace"
183- k8s_core_client_mock .read_namespaced_secret .return_value = k8s_tls_secret_mock
184-
185- with patch (
186- "app.handlers.handlers_services.get_ca_cert" , wraps = get_ca_cert
187- ) as get_ca_cert_mock :
188- result = service_to_twingate_resource (
189- example_cluster_ip_gateway_service_body , namespace
190- )
191178
192- get_ca_cert_mock .assert_called_once_with (k8s_tls_secret_mock )
193- k8s_core_client_mock .read_namespaced_secret .assert_called_once_with (
194- namespace = namespace , name = tls_object_name
179+ result = service_to_twingate_resource (
180+ example_cluster_ip_gateway_service_body , namespace
195181 )
196182
197183 assert result ["spec" ] == {
@@ -200,7 +186,10 @@ def test_kubernetes_resource_type_annotation(
200186 "alias" : "alias.int" ,
201187 "proxy" : {
202188 "address" : "kubernetes-gateway.custom-namespace.svc.cluster.local" ,
203- "certificateAuthorityCert" : BASE64_OF_VALID_CA_CERT ,
189+ "certificateAuthorityCertSecretRef" : {
190+ "name" : tls_object_name ,
191+ "namespace" : namespace ,
192+ },
204193 },
205194 "protocols" : {
206195 "allowIcmp" : False ,
@@ -231,19 +220,6 @@ def test_kubernetes_resource_type_annotation_without_tls_secret_annotation(
231220 example_cluster_ip_gateway_service_body , "default"
232221 )
233222
234- def test_kubernetes_resource_type_annotation_without_k8s_secret_object (
235- self , example_cluster_ip_gateway_service_body , k8s_core_client_mock
236- ):
237- k8s_core_client_mock .read_namespaced_secret .return_value = None
238-
239- with pytest .raises (
240- kopf .PermanentError ,
241- match = r"Kubernetes Secret object: gateway-tls is missing." ,
242- ):
243- service_to_twingate_resource (
244- example_cluster_ip_gateway_service_body , "default"
245- )
246-
247223 @pytest .mark .parametrize (
248224 ("status" , "expected" ),
249225 [
@@ -255,16 +231,10 @@ def test_kubernetes_resource_type_annotation_without_k8s_secret_object(
255231 ],
256232 )
257233 def test_kubernetes_resource_with_load_balancer_service_type (
258- self ,
259- example_load_balancer_gateway_service_body ,
260- k8s_core_client_mock ,
261- k8s_tls_secret_mock ,
262- status ,
263- expected ,
234+ self , example_load_balancer_gateway_service_body , status , expected
264235 ):
265236 tls_object_name = "gateway-tls"
266237 namespace = "default"
267- k8s_core_client_mock .read_namespaced_secret .return_value = k8s_tls_secret_mock
268238
269239 with patch (
270240 "kopf._cogs.structs.bodies.Body.status" ,
@@ -275,17 +245,16 @@ def test_kubernetes_resource_with_load_balancer_service_type(
275245 example_load_balancer_gateway_service_body , namespace
276246 )
277247
278- k8s_core_client_mock .read_namespaced_secret .assert_called_once_with (
279- namespace = namespace , name = tls_object_name
280- )
281-
282248 assert result ["spec" ] == {
283249 "name" : "kubernetes-gateway-resource" ,
284250 "address" : "kubernetes.default.svc.cluster.local" ,
285251 "alias" : "alias.int" ,
286252 "proxy" : {
287253 "address" : expected ,
288- "certificateAuthorityCert" : BASE64_OF_VALID_CA_CERT ,
254+ "certificateAuthorityCertSecretRef" : {
255+ "name" : tls_object_name ,
256+ "namespace" : namespace ,
257+ },
289258 },
290259 "protocols" : {
291260 "allowIcmp" : False ,
0 commit comments