-
Notifications
You must be signed in to change notification settings - Fork 9
feat: Support certificateAuthorityCertSecretRef on TwingateResource CRD
#807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
clement0010
wants to merge
12
commits into
main
Choose a base branch
from
feat/support-ca-cert-secret-ref
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+408
−131
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e0bedce
Refactor `k8s_get_tls_secret` and `get_ca_cert` to common util
clement0010 618107a
Support `certificateAuthorityCertSecretRef` to `TwingateResource` CRD
clement0010 fe84bfc
Update test
clement0010 9ea0ddb
Update `k8s_get_tls_secret` to `k8s_get_secret`
clement0010 66ae0e4
Remove tls in secret name variable
clement0010 cffd976
Update `tls_secret_name` to `secret_name`
clement0010 bc85869
Address PR review
clement0010 9b33d72
Update service handler
clement0010 e02c366
Merge branch 'main' into feat/support-ca-cert-secret-ref
clement0010 cd5436e
Merge branch 'main' into feat/support-ca-cert-secret-ref
ekampf e31b36e
Update min connector version
clement0010 575fe1e
Merge branch 'main' into feat/support-ca-cert-secret-ref
clement0010 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,11 +7,10 @@ | |
| from kopf._core.intents.causes import Reason | ||
|
|
||
| from app.api.tests.factories import BASE64_OF_VALID_CA_CERT | ||
| from app.crds import ResourceType | ||
| from app.crds import ResourceProxy, ResourceType | ||
| from app.handlers.handlers_services import ( | ||
| ALLOWED_EXTRA_ANNOTATIONS, | ||
| TLS_OBJECT_ANNOTATION, | ||
| k8s_get_tls_secret, | ||
| k8s_get_twingate_resource, | ||
| service_to_twingate_resource, | ||
| twingate_service_create, | ||
|
|
@@ -114,15 +113,6 @@ def example_load_balancer_gateway_service_body(): | |
| return kopf.Body(yaml.safe_load(yaml_str)) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def k8s_tls_secret_mock(): | ||
| return kubernetes.client.V1Secret( | ||
| type="kubernetes.io/tls", | ||
| metadata=kubernetes.client.V1ObjectMeta(name="gateway-tls"), | ||
| data={"ca.crt": BASE64_OF_VALID_CA_CERT}, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def k8s_customobjects_client_mock(): | ||
| client_mock = MagicMock() | ||
|
|
@@ -185,15 +175,21 @@ def test_kubernetes_resource_type_annotation( | |
| self, | ||
| example_cluster_ip_gateway_service_body, | ||
| k8s_core_client_mock, | ||
| k8s_tls_secret_mock, | ||
| k8s_secret_mock, | ||
| ): | ||
| tls_object_name = "gateway-tls" | ||
| namespace = "custom-namespace" | ||
| k8s_core_client_mock.read_namespaced_secret.return_value = k8s_tls_secret_mock | ||
| k8s_core_client_mock.read_namespaced_secret.return_value = k8s_secret_mock | ||
|
|
||
| result = service_to_twingate_resource( | ||
| example_cluster_ip_gateway_service_body, namespace | ||
| ) | ||
| with patch( | ||
| "app.handlers.handlers_services.ResourceProxy.read_certificate_authority_cert_from_secret", | ||
| wraps=ResourceProxy.read_certificate_authority_cert_from_secret, | ||
| ) as read_ca_cert_mock: | ||
| result = service_to_twingate_resource( | ||
| example_cluster_ip_gateway_service_body, namespace | ||
| ) | ||
|
|
||
| read_ca_cert_mock.assert_called_once_with(k8s_secret_mock) | ||
| k8s_core_client_mock.read_namespaced_secret.assert_called_once_with( | ||
| namespace=namespace, name=tls_object_name | ||
| ) | ||
|
|
@@ -248,59 +244,6 @@ def test_kubernetes_resource_type_annotation_without_k8s_secret_object( | |
| example_cluster_ip_gateway_service_body, "default" | ||
| ) | ||
|
|
||
| def test_kubernetes_resource_type_annotation_with_invalid_secret_type( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests are moved to |
||
| self, | ||
| example_cluster_ip_gateway_service_body, | ||
| k8s_core_client_mock, | ||
| k8s_tls_secret_mock, | ||
| ): | ||
| k8s_tls_secret_mock.type = "kubernetes.io/token" | ||
| k8s_core_client_mock.read_namespaced_secret.return_value = k8s_tls_secret_mock | ||
|
|
||
| with pytest.raises( | ||
| kopf.PermanentError, | ||
| match=r"Kubernetes Secret object: gateway-tls type is invalid.", | ||
| ): | ||
| service_to_twingate_resource( | ||
| example_cluster_ip_gateway_service_body, "default" | ||
| ) | ||
|
|
||
| def test_kubernetes_resource_type_annotation_without_ca_cert( | ||
| self, | ||
| example_cluster_ip_gateway_service_body, | ||
| k8s_core_client_mock, | ||
| k8s_tls_secret_mock, | ||
| ): | ||
| k8s_tls_secret_mock.data = {} | ||
| k8s_core_client_mock.read_namespaced_secret.return_value = k8s_tls_secret_mock | ||
|
|
||
| with pytest.raises( | ||
| kopf.PermanentError, | ||
| match=r"Kubernetes Secret object: gateway-tls is missing ca.crt.", | ||
| ): | ||
| service_to_twingate_resource( | ||
| example_cluster_ip_gateway_service_body, "default" | ||
| ) | ||
|
|
||
| def test_kubernetes_resource_type_annotation_with_invalid_ca_cert( | ||
| self, | ||
| example_cluster_ip_gateway_service_body, | ||
| k8s_core_client_mock, | ||
| k8s_tls_secret_mock, | ||
| ): | ||
| k8s_tls_secret_mock.data["ca.crt"] = ( | ||
| "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tIE1JSUZmakNDQTJhZ0F3SUJBZ0lVQk50IC0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0=" | ||
| ) | ||
| k8s_core_client_mock.read_namespaced_secret.return_value = k8s_tls_secret_mock | ||
|
|
||
| with pytest.raises( | ||
| kopf.PermanentError, | ||
| match=r"Kubernetes Secret object: gateway-tls ca.crt is invalid.", | ||
| ): | ||
| service_to_twingate_resource( | ||
| example_cluster_ip_gateway_service_body, "default" | ||
| ) | ||
|
|
||
| @pytest.mark.parametrize( | ||
| ("status", "expected"), | ||
| [ | ||
|
|
@@ -315,13 +258,13 @@ def test_kubernetes_resource_with_load_balancer_service_type( | |
| self, | ||
| example_load_balancer_gateway_service_body, | ||
| k8s_core_client_mock, | ||
| k8s_tls_secret_mock, | ||
| k8s_secret_mock, | ||
| status, | ||
| expected, | ||
| ): | ||
| tls_object_name = "gateway-tls" | ||
| namespace = "default" | ||
| k8s_core_client_mock.read_namespaced_secret.return_value = k8s_tls_secret_mock | ||
| k8s_core_client_mock.read_namespaced_secret.return_value = k8s_secret_mock | ||
|
|
||
| with patch( | ||
| "kopf._cogs.structs.bodies.Body.status", | ||
|
|
@@ -406,21 +349,6 @@ def test_reraises_non_404_exceptions(self, k8s_customobjects_client_mock): | |
| k8s_get_twingate_resource("default", "test") | ||
|
|
||
|
|
||
| class TestK8sGetTLSSecret: | ||
| def test_handles_404_returns_none(self, k8s_core_client_mock): | ||
| k8s_core_client_mock.read_namespaced_secret.side_effect = ( | ||
| kubernetes.client.exceptions.ApiException(status=404) | ||
| ) | ||
| assert k8s_get_tls_secret("default", "test") is None | ||
|
|
||
| def test_reraises_non_404_exceptions(self, k8s_core_client_mock): | ||
| k8s_core_client_mock.read_namespaced_secret.side_effect = ( | ||
| kubernetes.client.exceptions.ApiException(status=500) | ||
| ) | ||
| with pytest.raises(kubernetes.client.exceptions.ApiException): | ||
| k8s_get_tls_secret("default", "test") | ||
|
|
||
|
|
||
| class TestTwingateServiceCreate: | ||
| def test_create_service_triggers_creation_of_twingate_resource( | ||
| self, example_service_body, kopf_handler_runner, k8s_customobjects_client_mock | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is conversion is temporary, it'll be removed in this PR