From 6bf1827e154bce320c64060c9a975db38239faf5 Mon Sep 17 00:00:00 2001 From: Mallory Hill Date: Mon, 29 Jun 2026 15:52:07 -0400 Subject: [PATCH] HYPERFLEET-1108 - feat: Add run id labels to the adapter configs for cleanup --- Makefile | 2 +- env.gcp | 5 ++++- env.kind | 7 +++++-- helm/namespace-cleaner/values.yaml | 2 +- .../adapters/cl-deployment/adapter-task-config.yaml | 4 ++++ .../adapter-task-resource-deployment.yaml | 3 +++ .../e2e/adapters/cl-job/adapter-task-config.yaml | 4 ++++ .../adapters/cl-job/adapter-task-resource-job.yaml | 4 ++++ .../e2e/adapters/cl-maestro/adapter-task-config.yaml | 5 +++++ .../adapter-task-resource-manifestwork.yaml | 3 +++ .../adapters/cl-namespace/adapter-task-config.yaml | 11 +++++------ .../adapters/np-configmap/adapter-task-config.yaml | 4 ++++ .../np-configmap/adapter-task-resource-configmap.yaml | 1 + helmfile/helmfile.yaml.gotmpl | 4 +++- helmfile/values/base-adapter.yaml.gotmpl | 5 +++++ 15 files changed, 52 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 801a054..1047d48 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ KUBECONFIG ?= $(HOME)/.kube/config CLEANER_NAMESPACE ?= $(NAMESPACE) CLEANER_SCHEDULE ?= 0 * * * * -CLEANER_LABEL_SELECTOR ?= hyperfleet.io/cluster-id hyperfleet.io/test-run +CLEANER_LABEL_SELECTOR ?= hyperfleet.io/cluster-id hyperfleet.io/test-run e2e/hyperfleet.io/run-id CLEANER_AGE_MINUTES ?= 180 CLEANER_MAESTRO_URL ?= http://maestro.$(MAESTRO_NAMESPACE).svc.cluster.local:8000 diff --git a/env.gcp b/env.gcp index 06e4f68..6bbf5c2 100644 --- a/env.gcp +++ b/env.gcp @@ -21,9 +21,12 @@ SENTINEL_IMAGE_TAG ?= dev ADAPTER_IMAGE_TAG ?= dev IMAGE_PULL_POLICY ?= Always -# Kubernetes Namespaces + +# Default Namespace is set depending on helmfile environment +# RUN_ID is needed for e2e testing ifeq ($(findstring e2e,$(HELMFILE_ENV)),e2e) NAMESPACE ?= hyperfleet-e2e-$(shell echo $(or $(USER),default) | tr '[:upper:]' '[:lower:]') + RUN_ID ?= $(NAMESPACE) else NAMESPACE ?= hyperfleet endif diff --git a/env.kind b/env.kind index 15b5b17..55e6f99 100644 --- a/env.kind +++ b/env.kind @@ -21,11 +21,14 @@ SENTINEL_IMAGE_TAG ?= local ADAPTER_IMAGE_TAG ?= local IMAGE_PULL_POLICY ?= IfNotPresent -# Kubernetes Namespaces + +# Default Namespace is set depending on helmfile environment +# RUN_ID is needed for e2e testing ifeq ($(findstring e2e,$(HELMFILE_ENV)),e2e) NAMESPACE ?= hyperfleet-e2e + RUN_ID ?= $(NAMESPACE) else - NAMESPACE ?= hyperfleet-local + NAMESPACE ?= hyperfleet-local endif diff --git a/helm/namespace-cleaner/values.yaml b/helm/namespace-cleaner/values.yaml index 1a04ec4..65914dd 100644 --- a/helm/namespace-cleaner/values.yaml +++ b/helm/namespace-cleaner/values.yaml @@ -10,7 +10,7 @@ schedule: "0 * * * *" # Space-separated label selectors used to identify namespaces eligible for deletion. # Each selector is matched independently (OR semantics). -labelSelector: "hyperfleet.io/cluster-id hyperfleet.io/test-run" +labelSelector: "hyperfleet.io/cluster-id hyperfleet.io/test-run e2e.hyperfleet.io/run-id" # Delete namespaces older than this many minutes ageMinutes: 180 diff --git a/helmfile/configs/e2e/adapters/cl-deployment/adapter-task-config.yaml b/helmfile/configs/e2e/adapters/cl-deployment/adapter-task-config.yaml index 406ae4e..7f4f388 100644 --- a/helmfile/configs/e2e/adapters/cl-deployment/adapter-task-config.yaml +++ b/helmfile/configs/e2e/adapters/cl-deployment/adapter-task-config.yaml @@ -6,6 +6,10 @@ params: source: "event.id" type: "string" required: true + - name: "runId" + source: "env.RUN_ID" + type: "string" + required: true # Preconditions with valid operators and CEL expressions preconditions: diff --git a/helmfile/configs/e2e/adapters/cl-deployment/adapter-task-resource-deployment.yaml b/helmfile/configs/e2e/adapters/cl-deployment/adapter-task-resource-deployment.yaml index 6f66b37..b28672e 100644 --- a/helmfile/configs/e2e/adapters/cl-deployment/adapter-task-resource-deployment.yaml +++ b/helmfile/configs/e2e/adapters/cl-deployment/adapter-task-resource-deployment.yaml @@ -7,6 +7,7 @@ metadata: labels: hyperfleet.io/cluster-id: "{{ .clusterId }}" hyperfleet.io/resource-type: "deployment" + e2e.hyperfleet.io/run-id: "{{ .runId }}" annotations: hyperfleet.io/generation: "{{ .generationSpec }}" spec: @@ -15,11 +16,13 @@ spec: matchLabels: app: test hyperfleet.io/cluster-id: "{{ .clusterId }}" + e2e.hyperfleet.io/run-id: "{{ .runId }}" template: metadata: labels: app: test hyperfleet.io/cluster-id: "{{ .clusterId }}" + e2e.hyperfleet.io/run-id: "{{ .runId }}" spec: containers: - name: test diff --git a/helmfile/configs/e2e/adapters/cl-job/adapter-task-config.yaml b/helmfile/configs/e2e/adapters/cl-job/adapter-task-config.yaml index a59aac1..e8d774a 100644 --- a/helmfile/configs/e2e/adapters/cl-job/adapter-task-config.yaml +++ b/helmfile/configs/e2e/adapters/cl-job/adapter-task-config.yaml @@ -6,6 +6,10 @@ params: source: "event.id" type: "string" required: true + - name: "runId" + source: "env.RUN_ID" + type: "string" + required: true # Preconditions with valid operators and CEL expressions preconditions: diff --git a/helmfile/configs/e2e/adapters/cl-job/adapter-task-resource-job.yaml b/helmfile/configs/e2e/adapters/cl-job/adapter-task-resource-job.yaml index bf61887..ca05797 100644 --- a/helmfile/configs/e2e/adapters/cl-job/adapter-task-resource-job.yaml +++ b/helmfile/configs/e2e/adapters/cl-job/adapter-task-resource-job.yaml @@ -7,12 +7,16 @@ metadata: labels: hyperfleet.io/cluster-id: "{{ .clusterId }}" hyperfleet.io/resource-type: "job" + e2e.hyperfleet.io/run-id: "{{ .runId }}" app: test-job annotations: hyperfleet.io/generation: "{{ .generationSpec }}" spec: backoffLimit: 0 template: + metadata: + labels: + e2e.hyperfleet.io/run-id: "{{ .runId }}" spec: restartPolicy: Never containers: diff --git a/helmfile/configs/e2e/adapters/cl-maestro/adapter-task-config.yaml b/helmfile/configs/e2e/adapters/cl-maestro/adapter-task-config.yaml index 8978adf..08f067a 100644 --- a/helmfile/configs/e2e/adapters/cl-maestro/adapter-task-config.yaml +++ b/helmfile/configs/e2e/adapters/cl-maestro/adapter-task-config.yaml @@ -17,6 +17,11 @@ params: source: "env.NAMESPACE" type: "string" + - name: "runId" + source: "env.RUN_ID" + type: "string" + required: true + # Preconditions with valid operators and CEL expressions preconditions: - name: "clusterStatus" diff --git a/helmfile/configs/e2e/adapters/cl-maestro/adapter-task-resource-manifestwork.yaml b/helmfile/configs/e2e/adapters/cl-maestro/adapter-task-resource-manifestwork.yaml index 87dd7a8..413fdec 100644 --- a/helmfile/configs/e2e/adapters/cl-maestro/adapter-task-resource-manifestwork.yaml +++ b/helmfile/configs/e2e/adapters/cl-maestro/adapter-task-resource-manifestwork.yaml @@ -27,6 +27,7 @@ metadata: app.kubernetes.io/part-of: "hyperfleet" app.kubernetes.io/managed-by: "cl-maestro" app.kubernetes.io/created-by: "{{ .adapter.name }}" + e2e.hyperfleet.io/run-id: "{{ .runId }}" {{ if .platformType }} hyperfleet.io/platform-type: "{{ .platformType }}" {{ end }} @@ -65,6 +66,7 @@ spec: app.kubernetes.io/instance: "{{ .adapter.name }}" app.kubernetes.io/name: cl-maestro app.kubernetes.io/transport: maestro + e2e.hyperfleet.io/run-id: "{{ .runId }}" annotations: hyperfleet.io/generation: "{{ .generation }}" - apiVersion: v1 @@ -91,6 +93,7 @@ spec: app.kubernetes.io/name: cl-maestro app.kubernetes.io/version: 1.0.0 app.kubernetes.io/transport: maestro + e2e.hyperfleet.io/run-id: "{{ .runId }}" annotations: hyperfleet.io/generation: "{{ .generation }}" diff --git a/helmfile/configs/e2e/adapters/cl-namespace/adapter-task-config.yaml b/helmfile/configs/e2e/adapters/cl-namespace/adapter-task-config.yaml index fc519bd..6186acd 100644 --- a/helmfile/configs/e2e/adapters/cl-namespace/adapter-task-config.yaml +++ b/helmfile/configs/e2e/adapters/cl-namespace/adapter-task-config.yaml @@ -6,16 +6,15 @@ params: source: "event.id" type: "string" required: true - - name: "testRunId" - source: "env.TEST_RUN_ID" - type: "string" - required: false - default: "TEST_RUN_ID" - name: "ci" source: "env.CI" type: "string" required: false default: "false" + - name: "runId" + source: "env.RUN_ID" + type: "string" + required: true # Preconditions with valid operators and CEL expressions preconditions: @@ -64,9 +63,9 @@ resources: labels: hyperfleet.io/cluster-id: "{{ .clusterId }}" hyperfleet.io/cluster-name: "{{ .clusterName }}" - e2e.hyperfleet.io/test-run-id: "{{ .testRunId }}" e2e.hyperfleet.io/ci: "{{ .ci }}" e2e.hyperfleet.io/managed-by: "test-framework" + e2e.hyperfleet.io/run-id: "{{ .runId }}" annotations: hyperfleet.io/generation: "{{ .generationSpec }}" discovery: diff --git a/helmfile/configs/e2e/adapters/np-configmap/adapter-task-config.yaml b/helmfile/configs/e2e/adapters/np-configmap/adapter-task-config.yaml index 0e56379..a056a9c 100644 --- a/helmfile/configs/e2e/adapters/np-configmap/adapter-task-config.yaml +++ b/helmfile/configs/e2e/adapters/np-configmap/adapter-task-config.yaml @@ -10,6 +10,10 @@ params: source: "event.id" type: "string" required: true + - name: "runId" + source: "env.RUN_ID" + type: "string" + required: true # Preconditions with valid operators and CEL expressions preconditions: diff --git a/helmfile/configs/e2e/adapters/np-configmap/adapter-task-resource-configmap.yaml b/helmfile/configs/e2e/adapters/np-configmap/adapter-task-resource-configmap.yaml index 750344b..e01b756 100644 --- a/helmfile/configs/e2e/adapters/np-configmap/adapter-task-resource-configmap.yaml +++ b/helmfile/configs/e2e/adapters/np-configmap/adapter-task-resource-configmap.yaml @@ -9,6 +9,7 @@ metadata: hyperfleet.io/nodepool-id: "{{ .nodepoolId }}" hyperfleet.io/nodepool-name: "{{ .nodepoolName }}" hyperfleet.io/resource-type: "configmap" + e2e.hyperfleet.io/run-id: "{{ .runId }}" annotations: hyperfleet.io/generation: "{{ .generationSpec }}" data: diff --git a/helmfile/helmfile.yaml.gotmpl b/helmfile/helmfile.yaml.gotmpl index 4852c35..99f3669 100644 --- a/helmfile/helmfile.yaml.gotmpl +++ b/helmfile/helmfile.yaml.gotmpl @@ -27,12 +27,14 @@ environments: - projectId: {{ env "PROJECT_ID" | default "hcm-hyperfleet" }} brokerType: googlepubsub serviceType: {{ env "API_SERVICE_TYPE" | default "LoadBalancer" }} + runId: {{ requiredEnv "RUN_ID" | quote }} - environments/e2e-gcp/adapter-configs.yaml.gotmpl - environments/e2e-gcp/sentinel-configs.yaml e2e-kind: values: - brokerType: rabbitmq serviceType: {{ env "API_SERVICE_TYPE" | default "ClusterIP" }} + runId: {{ requiredEnv "RUN_ID" | quote }} - environments/e2e-kind/adapter-configs.yaml.gotmpl - environments/e2e-kind/sentinel-configs.yaml kind: @@ -74,7 +76,7 @@ releases: # HyperFleet API - name: hyperfleet-api namespace: {{ .Values.namespace }} - chart: hyperfleet-api/hyperfleet-api + chart: hyperfleet-api/hyperfleet-api labels: component: api values: diff --git a/helmfile/values/base-adapter.yaml.gotmpl b/helmfile/values/base-adapter.yaml.gotmpl index 3600936..4282898 100644 --- a/helmfile/values/base-adapter.yaml.gotmpl +++ b/helmfile/values/base-adapter.yaml.gotmpl @@ -6,6 +6,7 @@ image: tag: {{ env "ADAPTER_IMAGE_TAG" | default "dev" }} pullPolicy: {{ env "IMAGE_PULL_POLICY" | default "IfNotPresent" }} + adapterConfig: log: level: debug @@ -30,3 +31,7 @@ env: valueFrom: fieldRef: fieldPath: metadata.namespace + {{- if .Values.runId }} + - name: RUN_ID + value: {{ .Values.runId | quote }} + {{ end }}