From e1da4cad7824cdbc7a9120ca9cba92706a47f217 Mon Sep 17 00:00:00 2001 From: Mathew Wicks <5735406+thesuperzapper@users.noreply.github.com> Date: Tue, 4 Feb 2025 09:23:36 -0800 Subject: [PATCH] fix(ws): handle empty pod metadata in controller (#193) Signed-off-by: Mathew Wicks <5735406+thesuperzapper@users.noreply.github.com> --- .../controller/workspace_controller.go | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/workspaces/controller/internal/controller/workspace_controller.go b/workspaces/controller/internal/controller/workspace_controller.go index c985b0e9..1af67d3c 100644 --- a/workspaces/controller/internal/controller/workspace_controller.go +++ b/workspaces/controller/internal/controller/workspace_controller.go @@ -584,8 +584,25 @@ func generateStatefulSet(workspace *kubefloworgv1beta1.Workspace, workspaceKind } // generate pod metadata - podAnnotations := labels.Merge(workspaceKind.Spec.PodTemplate.PodMetadata.Annotations, workspace.Spec.PodTemplate.PodMetadata.Annotations) - podLabels := labels.Merge(workspaceKind.Spec.PodTemplate.PodMetadata.Labels, workspace.Spec.PodTemplate.PodMetadata.Labels) + // NOTE: pod metadata from the Workspace takes precedence over the WorkspaceKind + podAnnotations := make(map[string]string) + podLabels := make(map[string]string) + if workspaceKind.Spec.PodTemplate.PodMetadata != nil { + for k, v := range workspaceKind.Spec.PodTemplate.PodMetadata.Annotations { + podAnnotations[k] = v + } + for k, v := range workspaceKind.Spec.PodTemplate.PodMetadata.Labels { + podLabels[k] = v + } + } + if workspace.Spec.PodTemplate.PodMetadata != nil { + for k, v := range workspace.Spec.PodTemplate.PodMetadata.Annotations { + podAnnotations[k] = v + } + for k, v := range workspace.Spec.PodTemplate.PodMetadata.Labels { + podLabels[k] = v + } + } // generate container imagePullPolicy imagePullPolicy := corev1.PullIfNotPresent