From 50b52dbd7dcacbfcfe6aa4d104c37a58451c74d9 Mon Sep 17 00:00:00 2001 From: Irbe Krumina Date: Tue, 16 Jan 2024 12:51:10 +0000 Subject: [PATCH] cmd/k8s-operator: sync StatefulSet labels to their Pods (#10861) So that users have predictable label values to use when configuring network policies. Updates tailscale/tailscale#10854 Signed-off-by: Irbe Krumina --- cmd/k8s-operator/sts.go | 3 +++ cmd/k8s-operator/testutils_test.go | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd/k8s-operator/sts.go b/cmd/k8s-operator/sts.go index 3104d2775..1c8063521 100644 --- a/cmd/k8s-operator/sts.go +++ b/cmd/k8s-operator/sts.go @@ -411,6 +411,9 @@ func (a *tailscaleSTSReconciler) reconcileSTS(ctx context.Context, logger *zap.S }, } mak.Set(&ss.Spec.Template.Labels, "app", sts.ParentResourceUID) + for key, val := range sts.ChildResourceLabels { + ss.Spec.Template.Labels[key] = val // sync StatefulSet labels to Pod to make it easier for users to select the Pod + } // Generic containerboot configuration options. container.Env = append(container.Env, diff --git a/cmd/k8s-operator/testutils_test.go b/cmd/k8s-operator/testutils_test.go index e91fcda02..a5aea24cd 100644 --- a/cmd/k8s-operator/testutils_test.go +++ b/cmd/k8s-operator/testutils_test.go @@ -147,7 +147,13 @@ func expectedSTS(opts configOpts) *appsv1.StatefulSet { ObjectMeta: metav1.ObjectMeta{ Annotations: annots, DeletionGracePeriodSeconds: ptr.To[int64](10), - Labels: map[string]string{"app": "1234-UID"}, + Labels: map[string]string{ + "tailscale.com/managed": "true", + "tailscale.com/parent-resource": "test", + "tailscale.com/parent-resource-ns": opts.namespace, + "tailscale.com/parent-resource-type": opts.parentType, + "app": "1234-UID", + }, }, Spec: corev1.PodSpec{ ServiceAccountName: "proxies",