Skip to content

feat(cilium): support cluster-id and cluster-name annotations for ck-network - #75

Draft
shipperizer wants to merge 1 commit into
canonical:mainfrom
shipperizer:cilium-cluster-identity
Draft

shipperizer wants to merge 1 commit into
canonical:mainfrom
shipperizer:cilium-cluster-identity

Conversation

@shipperizer

Copy link
Copy Markdown

What this PR does

Consumes the new k8s-snap-api annotation constants and translates them into Helm values for the ck-network (Cilium) release:

  • consume k8sd/v1alpha1/cilium/cluster-id → cluster.id (int, range 0–255)
  • k8sd/v1alpha1/cilium/cluster-name → cluster.name (string, ≤32 chars, lower-case alphanumeric and dashes, no leading/trailing dash)

Validation lives in internal.go (validateClusterID, validateClusterName); a cross-check rejects a non-zero ID with the default/empty name, which violates the chart constraint. The cluster values map is rendered only when at least one annotation is set, preserving current behavior for existing clusters.

Testing

Unit tests extended in internal_test.go (12 new cases) and network_test.go (new ClusterIDAndName / ClusterIDAndNameInvalid sub-tests). Run with:

go test ./pkg/k8sd/features/cilium/...

Notes for reviewers

  • go.mod currently contains a dev-only replace pointing to the local k8s-snap-api checkout. Before merge, update to the tagged k8s-snap-api release that includes the new constants.
  • Sibling PRs: canonical/k8s-snap-api (constants), canonical/k8s-snap (proposal, docs, integration test).

Part of: Cilium ClusterMesh identity support.

@shipperizer

Copy link
Copy Markdown
Author

Summary of Changes

  • Implements validateClusterID and validateClusterName in pkg/k8sd/features/cilium/internal.go.
  • Defines ciliumDefaultClusterName = "default" in chart.go.
  • Renders values["cluster"] in pkg/k8sd/features/cilium/network.go when identity annotations are provided.
  • Adds comprehensive unit testing in internal_test.go and network_test.go.

Review & Assessment

  • Validation Logic:
    • validateClusterID: Accurately parses numeric input and checks the 0..255 range.
    • validateClusterName: Iterates over runes to enforce length ($\le 32$), character set ([a-z0-9-]), and checks that hyphens are neither leading nor trailing. Avoids regex compilation overhead.
    • Cross-Validation: Early rejection of clusterID != 0 when clusterName is empty or "default" prevents cryptic downstream Helm deployment failures.
  • Backward Compatibility:
    • If neither annotation is present, values["cluster"] is not injected, leaving default Helm values untouched for existing clusters.

Suggested Test Additions (Non-Blocking)

  • internal_test.go:
    • Upper boundary test: AnnotationClusterID: "255".
    • Name length boundary: exactly 32 chars (valid) and 33 chars (invalid).
    • Empty name annotation: AnnotationClusterName: "" to test explicit empty string error path.
  • network_test.go:
    • Subtest for ClusterNameOnly in ApplyNetwork verifying that setting only cluster-name renders cluster: { id: 0, name: "my-cluster" }.

Pre-Merge Requirement

Verdict

LGTM / Approve (Pending dependency release).


Reviewed by Gemini 3.7 Flash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant