From 6494d7b704f0715e27b034f4f6095badd13ddca1 Mon Sep 17 00:00:00 2001 From: Oliver Walsh Date: Wed, 13 Nov 2024 20:59:53 +0000 Subject: [PATCH] Set nodeSelector on jobs and allow empty nodeSelector Switch to a pointer for nodeSelector to allow different logic for empty vs unset --- api/v1beta1/placementapi_types.go | 2 +- api/v1beta1/zz_generated.deepcopy.go | 10 +++++++--- pkg/placement/dbsync.go | 4 ++++ pkg/placement/deployment.go | 4 ++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/api/v1beta1/placementapi_types.go b/api/v1beta1/placementapi_types.go index fe1fbc07..e0ac84fd 100644 --- a/api/v1beta1/placementapi_types.go +++ b/api/v1beta1/placementapi_types.go @@ -84,7 +84,7 @@ type PlacementAPISpecCore struct { // +kubebuilder:validation:Optional // NodeSelector to target subset of worker nodes running this service - NodeSelector map[string]string `json:"nodeSelector,omitempty"` + NodeSelector *map[string]string `json:"nodeSelector,omitempty"` // +kubebuilder:validation:Optional // +kubebuilder:default=false diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index c3399e6d..71f9678b 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -165,9 +165,13 @@ func (in *PlacementAPISpecCore) DeepCopyInto(out *PlacementAPISpecCore) { out.PasswordSelectors = in.PasswordSelectors if in.NodeSelector != nil { in, out := &in.NodeSelector, &out.NodeSelector - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val + *out = new(map[string]string) + if **in != nil { + in, out := *in, *out + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } } } if in.DefaultConfigOverwrite != nil { diff --git a/pkg/placement/dbsync.go b/pkg/placement/dbsync.go index dc966487..8de09fab 100644 --- a/pkg/placement/dbsync.go +++ b/pkg/placement/dbsync.go @@ -83,5 +83,9 @@ func DbSyncJob( }, } + if instance.Spec.NodeSelector != nil && len(*instance.Spec.NodeSelector) > 0 { + job.Spec.Template.Spec.NodeSelector = *instance.Spec.NodeSelector + } + return job } diff --git a/pkg/placement/deployment.go b/pkg/placement/deployment.go index 42dbfa9d..e839b564 100644 --- a/pkg/placement/deployment.go +++ b/pkg/placement/deployment.go @@ -174,8 +174,8 @@ func Deployment( }, corev1.LabelHostname, ) - if instance.Spec.NodeSelector != nil && len(instance.Spec.NodeSelector) > 0 { - deployment.Spec.Template.Spec.NodeSelector = instance.Spec.NodeSelector + if instance.Spec.NodeSelector != nil && len(*instance.Spec.NodeSelector) > 0 { + deployment.Spec.Template.Spec.NodeSelector = *instance.Spec.NodeSelector } return deployment, nil