Skip to content
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

feat: TwingateConnector - allow defining extra pod annotations with podAnnotations #225

Merged
merged 4 commits into from Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions app/crds.py
Expand Up @@ -305,6 +305,7 @@ class ConnectorSpec(BaseModel):
image_policy: ConnectorImagePolicy | None = None
container_extra: dict[str, Any] = {}
pod_extra: dict[str, Any] = {}
pod_annotations: dict[str, Any] = {}

remote_network_id: str = Field(
default_factory=lambda: get_settings().remote_network_id
Expand Down
3 changes: 2 additions & 1 deletion app/handlers/handlers_connectors.py
Expand Up @@ -74,8 +74,9 @@ def get_connector_pod(
],
**spec.pod_extra,
}
pod_annotations = spec.pod_annotations.copy().update({ANNOTATION_POD_SPEC_VERSION: ANNOTATION_POD_SPEC_VERSION_VALUE})
ekampf marked this conversation as resolved.
Show resolved Hide resolved

pod_meta = V1ObjectMeta(annotations={ANNOTATION_POD_SPEC_VERSION: ANNOTATION_POD_SPEC_VERSION_VALUE})
pod_meta = V1ObjectMeta(annotations=pod_annotations)

# fmt: on
return kubernetes.client.V1Pod(spec=pod_spec, metadata=pod_meta)
Expand Down
Expand Up @@ -85,6 +85,9 @@ spec:
podExtra:
type: object
x-kubernetes-preserve-unknown-fields: true
podAnnotations:
type: object
x-kubernetes-preserve-unknown-fields: true
status:
type: object
x-kubernetes-preserve-unknown-fields: true
Expand Down
4 changes: 4 additions & 0 deletions examples/connector.yaml
Expand Up @@ -16,6 +16,8 @@ spec:
cpu: 500m
memory: 128Mi
podExtra: {}
podAnnotations:
some/annotation: "some-value"
---
apiVersion: twingate.com/v1beta
kind: TwingateConnector
Expand All @@ -39,3 +41,5 @@ spec:
cpu: 500m
memory: 128Mi
podExtra: {}
podAnnotations:
some/annotation: "some-value"
2 changes: 2 additions & 0 deletions tests_integration/test_connector_flows.py
Expand Up @@ -97,6 +97,7 @@ def test_connector_flows(run_kopf, ci_run_number):
"spec": {
"containerExtra": {"env": [{"name": "FOO", "value": "bar"}]},
"podExtra": {"restartPolicy": "OnFailure"},
"podAnnotations": {"some/annotation": "some-value"},
}
},
)
Expand All @@ -107,6 +108,7 @@ def test_connector_flows(run_kopf, ci_run_number):
assert pod["spec"]["restartPolicy"] == "OnFailure"
assert pod["spec"]["containers"][0]["env"][-1]["name"] == "FOO"
assert pod["spec"]["containers"][0]["env"][-1]["value"] == "bar"
assert pod["metadata"]["annotations"]["some/annotation"] == "some-value"

kubectl_delete(f"tc/{connector_name}")
time.sleep(10)
Expand Down