Skip to content

Commit 6fdc461

Browse files
committed
Add unique label to pooled pods
Signed-off-by: Anton Ippolitov <anton.ippolitov@datadoghq.com>
1 parent 78e023b commit 6fdc461

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

extensions/controllers/sandboxwarmpool_controller.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
k8serrors "k8s.io/apimachinery/pkg/api/errors"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
"k8s.io/apimachinery/pkg/labels"
28+
"k8s.io/apimachinery/pkg/util/uuid"
2829
ctrl "sigs.k8s.io/controller-runtime"
2930
"sigs.k8s.io/controller-runtime/pkg/client"
3031
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
@@ -36,6 +37,7 @@ import (
3637

3738
const (
3839
poolLabel = "agents.x-k8s.io/pool"
40+
poolPodIDLabel = "agents.x-k8s.io/pool-pod-id"
3941
sandboxTemplateRefHash = "agents.x-k8s.io/sandbox-template-ref-hash"
4042
)
4143

@@ -248,7 +250,7 @@ func (r *SandboxWarmPoolReconciler) createPoolPod(ctx context.Context, warmPool
248250
Spec: template.Spec.PodTemplate.Spec,
249251
}
250252

251-
// pod.Labels[podNameLabel] = sandboxcontrollers.NameHash(pod.Name)
253+
pod.Labels[poolPodIDLabel] = string(uuid.NewUUID())
252254

253255
// Set controller reference so the Pod is owned by the SandboxWarmPool
254256
if err := ctrl.SetControllerReference(warmPool, pod, r.Scheme()); err != nil {

extensions/controllers/sandboxwarmpool_controller_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,18 @@ func TestPoolLabelValueInIntegration(t *testing.T) {
468468
// Verify sandbox template metadata annotations are not propagated
469469
require.NotContains(t, pod.Annotations, "description")
470470
}
471+
472+
// Verify each pod has a unique pool-pod-id label
473+
podIDs := make(map[string]struct{})
474+
for _, pod := range list.Items {
475+
id, ok := pod.Labels[poolPodIDLabel]
476+
require.True(t, ok, "pod %s should have %s label", pod.Name, poolPodIDLabel)
477+
require.NotEmpty(t, id, "pool-pod-id should not be empty")
478+
_, duplicate := podIDs[id]
479+
require.False(t, duplicate, "pool-pod-id %s is not unique across pods", id)
480+
podIDs[id] = struct{}{}
481+
}
482+
require.Len(t, podIDs, int(replicas))
471483
})
472484
}
473485

0 commit comments

Comments
 (0)