Skip to content

Commit

Permalink
feat: TwingateConnector - allow defining extra pod annotations with `…
Browse files Browse the repository at this point in the history
…podAnnotations` (#225)
  • Loading branch information
ekampf committed Mar 26, 2024
1 parent 68e188e commit 7b44838
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 1 deletion.
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 | {ANNOTATION_POD_SPEC_VERSION: ANNOTATION_POD_SPEC_VERSION_VALUE}

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 @@ -88,6 +88,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

0 comments on commit 7b44838

Please sign in to comment.