From 9164efeaf90731317a3434c7266c30559ae74e47 Mon Sep 17 00:00:00 2001 From: Oliver Walsh Date: Tue, 12 Nov 2024 22:11:56 +0000 Subject: [PATCH 1/2] Allow empty nodeselector --- api/v1beta1/common_types.go | 2 +- api/v1beta1/designate_types.go | 2 +- api/v1beta1/zz_generated.deepcopy.go | 20 ++++++--- controllers/designate_controller.go | 56 +++++++++++++++---------- pkg/designateapi/deployment.go | 5 +-- pkg/designatebackendbind9/deployment.go | 5 +-- pkg/designatecentral/deployment.go | 5 +-- pkg/designatemdns/daemonset.go | 5 +-- pkg/designateproducer/deployment.go | 5 +-- pkg/designateunbound/deployment.go | 4 +- pkg/designateworker/deployment.go | 5 +-- 11 files changed, 65 insertions(+), 49 deletions(-) diff --git a/api/v1beta1/common_types.go b/api/v1beta1/common_types.go index 72e67cc0..5951832c 100644 --- a/api/v1beta1/common_types.go +++ b/api/v1beta1/common_types.go @@ -86,7 +86,7 @@ type DesignateServiceTemplateCore struct { // +kubebuilder:validation:Optional // NodeSelector to target subset of worker nodes running this service. Setting here overrides // any global NodeSelector settings within the Designate CR. - NodeSelector map[string]string `json:"nodeSelector,omitempty"` + NodeSelector *map[string]string `json:"nodeSelector,omitempty"` // +kubebuilder:validation:Optional // CustomServiceConfig - customize the service config using this parameter to change service defaults, diff --git a/api/v1beta1/designate_types.go b/api/v1beta1/designate_types.go index 3d9c3853..011cfbc6 100644 --- a/api/v1beta1/designate_types.go +++ b/api/v1beta1/designate_types.go @@ -152,7 +152,7 @@ type DesignateSpecBase 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 44d8be9b..7dba4d35 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -995,9 +995,13 @@ func (in *DesignateServiceTemplateCore) DeepCopyInto(out *DesignateServiceTempla *out = *in 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.CustomServiceConfigSecrets != nil { @@ -1059,9 +1063,13 @@ func (in *DesignateSpecBase) DeepCopyInto(out *DesignateSpecBase) { 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/controllers/designate_controller.go b/controllers/designate_controller.go index 43b8a811..4a58af65 100644 --- a/controllers/designate_controller.go +++ b/controllers/designate_controller.go @@ -1394,6 +1394,10 @@ func (r *DesignateReconciler) apiDeploymentCreateOrUpdate(ctx context.Context, i }, } + if instance.Spec.DesignateAPI.NodeSelector == nil { + instance.Spec.DesignateAPI.NodeSelector = instance.Spec.NodeSelector + } + op, err := controllerutil.CreateOrUpdate(ctx, r.Client, deployment, func() error { deployment.Spec = instance.Spec.DesignateAPI // Add in transfers from umbrella Designate (this instance) spec @@ -1405,9 +1409,7 @@ func (r *DesignateReconciler) apiDeploymentCreateOrUpdate(ctx context.Context, i deployment.Spec.ServiceAccount = instance.RbacResourceName() deployment.Spec.TLS = instance.Spec.DesignateAPI.TLS deployment.Spec.TransportURLSecret = instance.Status.TransportURLSecret - if len(deployment.Spec.NodeSelector) == 0 { - deployment.Spec.NodeSelector = instance.Spec.NodeSelector - } + deployment.Spec.NodeSelector = instance.Spec.DesignateAPI.NodeSelector err := controllerutil.SetControllerReference(instance, deployment, r.Scheme) if err != nil { @@ -1428,6 +1430,10 @@ func (r *DesignateReconciler) centralDeploymentCreateOrUpdate(ctx context.Contex }, } + if instance.Spec.DesignateCentral.NodeSelector == nil { + instance.Spec.DesignateCentral.NodeSelector = instance.Spec.NodeSelector + } + op, err := controllerutil.CreateOrUpdate(ctx, r.Client, deployment, func() error { deployment.Spec = instance.Spec.DesignateCentral // Add in transfers from umbrella Designate CR (this instance) spec @@ -1439,9 +1445,7 @@ func (r *DesignateReconciler) centralDeploymentCreateOrUpdate(ctx context.Contex deployment.Spec.TransportURLSecret = instance.Status.TransportURLSecret deployment.Spec.ServiceAccount = instance.RbacResourceName() deployment.Spec.TLS = instance.Spec.DesignateAPI.TLS.Ca - if len(deployment.Spec.NodeSelector) == 0 { - deployment.Spec.NodeSelector = instance.Spec.NodeSelector - } + deployment.Spec.NodeSelector = instance.Spec.DesignateProducer.NodeSelector err := controllerutil.SetControllerReference(instance, deployment, r.Scheme) if err != nil { @@ -1462,6 +1466,10 @@ func (r *DesignateReconciler) workerDeploymentCreateOrUpdate(ctx context.Context }, } + if instance.Spec.DesignateWorker.NodeSelector == nil { + instance.Spec.DesignateWorker.NodeSelector = instance.Spec.NodeSelector + } + op, err := controllerutil.CreateOrUpdate(ctx, r.Client, deployment, func() error { deployment.Spec = instance.Spec.DesignateWorker // Add in transfers from umbrella Designate CR (this instance) spec @@ -1473,9 +1481,7 @@ func (r *DesignateReconciler) workerDeploymentCreateOrUpdate(ctx context.Context deployment.Spec.TransportURLSecret = instance.Status.TransportURLSecret deployment.Spec.ServiceAccount = instance.RbacResourceName() deployment.Spec.TLS = instance.Spec.DesignateAPI.TLS.Ca - if len(deployment.Spec.NodeSelector) == 0 { - deployment.Spec.NodeSelector = instance.Spec.NodeSelector - } + deployment.Spec.NodeSelector = instance.Spec.DesignateWorker.NodeSelector err := controllerutil.SetControllerReference(instance, deployment, r.Scheme) if err != nil { @@ -1496,6 +1502,10 @@ func (r *DesignateReconciler) mdnsDaemonSetCreateOrUpdate(ctx context.Context, i }, } + if instance.Spec.DesignateMdns.NodeSelector == nil { + instance.Spec.DesignateMdns.NodeSelector = instance.Spec.NodeSelector + } + op, err := controllerutil.CreateOrUpdate(ctx, r.Client, daemonset, func() error { daemonset.Spec = instance.Spec.DesignateMdns // Add in transfers from umbrella Designate CR (this instance) spec @@ -1507,9 +1517,7 @@ func (r *DesignateReconciler) mdnsDaemonSetCreateOrUpdate(ctx context.Context, i daemonset.Spec.TransportURLSecret = instance.Status.TransportURLSecret daemonset.Spec.ServiceAccount = instance.RbacResourceName() daemonset.Spec.TLS = instance.Spec.DesignateAPI.TLS.Ca - if len(daemonset.Spec.NodeSelector) == 0 { - daemonset.Spec.NodeSelector = instance.Spec.NodeSelector - } + daemonset.Spec.NodeSelector = instance.Spec.DesignateMdns.NodeSelector err := controllerutil.SetControllerReference(instance, daemonset, r.Scheme) if err != nil { @@ -1530,6 +1538,10 @@ func (r *DesignateReconciler) producerDeploymentCreateOrUpdate(ctx context.Conte }, } + if instance.Spec.DesignateProducer.NodeSelector == nil { + instance.Spec.DesignateProducer.NodeSelector = instance.Spec.NodeSelector + } + op, err := controllerutil.CreateOrUpdate(ctx, r.Client, deployment, func() error { deployment.Spec = instance.Spec.DesignateProducer // Add in transfers from umbrella Designate CR (this instance) spec @@ -1541,9 +1553,7 @@ func (r *DesignateReconciler) producerDeploymentCreateOrUpdate(ctx context.Conte deployment.Spec.TransportURLSecret = instance.Status.TransportURLSecret deployment.Spec.ServiceAccount = instance.RbacResourceName() deployment.Spec.TLS = instance.Spec.DesignateAPI.TLS.Ca - if len(deployment.Spec.NodeSelector) == 0 { - deployment.Spec.NodeSelector = instance.Spec.NodeSelector - } + deployment.Spec.NodeSelector = instance.Spec.DesignateCentral.NodeSelector err := controllerutil.SetControllerReference(instance, deployment, r.Scheme) if err != nil { @@ -1564,6 +1574,10 @@ func (r *DesignateReconciler) backendbind9StatefulSetCreateOrUpdate(ctx context. }, } + if instance.Spec.DesignateBackendbind9.NodeSelector == nil { + instance.Spec.DesignateBackendbind9.NodeSelector = instance.Spec.NodeSelector + } + op, err := controllerutil.CreateOrUpdate(ctx, r.Client, statefulSet, func() error { statefulSet.Spec = instance.Spec.DesignateBackendbind9 // Add in transfers from umbrella Designate CR (this instance) spec @@ -1572,9 +1586,7 @@ func (r *DesignateReconciler) backendbind9StatefulSetCreateOrUpdate(ctx context. statefulSet.Spec.Secret = instance.Spec.Secret statefulSet.Spec.PasswordSelectors = instance.Spec.PasswordSelectors statefulSet.Spec.ServiceAccount = instance.RbacResourceName() - if len(statefulSet.Spec.NodeSelector) == 0 { - statefulSet.Spec.NodeSelector = instance.Spec.NodeSelector - } + statefulSet.Spec.NodeSelector = instance.Spec.DesignateBackendbind9.NodeSelector err := controllerutil.SetControllerReference(instance, statefulSet, r.Scheme) if err != nil { @@ -1598,14 +1610,16 @@ func (r *DesignateReconciler) unboundDeploymentCreateOrUpdate( }, } + if instance.Spec.DesignateUnbound.NodeSelector == nil { + instance.Spec.DesignateUnbound.NodeSelector = instance.Spec.NodeSelector + } + op, err := controllerutil.CreateOrUpdate(ctx, r.Client, deployment, func() error { deployment.Spec = instance.Spec.DesignateUnbound // Add in transfers from umbrella Designate CR (this instance) spec // TODO: Add logic to determine when to set/overwrite, etc deployment.Spec.ServiceAccount = instance.RbacResourceName() - if len(deployment.Spec.NodeSelector) == 0 { - deployment.Spec.NodeSelector = instance.Spec.NodeSelector - } + deployment.Spec.NodeSelector = instance.Spec.DesignateUnbound.NodeSelector err := controllerutil.SetControllerReference(instance, deployment, r.Scheme) if err != nil { diff --git a/pkg/designateapi/deployment.go b/pkg/designateapi/deployment.go index cccae378..d1d73431 100644 --- a/pkg/designateapi/deployment.go +++ b/pkg/designateapi/deployment.go @@ -145,7 +145,6 @@ func Deployment( LivenessProbe: livenessProbe, }, }, - NodeSelector: instance.Spec.NodeSelector, }, }, }, @@ -161,8 +160,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 { + deployment.Spec.Template.Spec.NodeSelector = *instance.Spec.NodeSelector } initContainerDetails := designate.APIDetails{ diff --git a/pkg/designatebackendbind9/deployment.go b/pkg/designatebackendbind9/deployment.go index d94e0c2f..70d92c0a 100644 --- a/pkg/designatebackendbind9/deployment.go +++ b/pkg/designatebackendbind9/deployment.go @@ -111,7 +111,6 @@ func StatefulSet( ReadinessProbe: readinessProbe, }, }, - NodeSelector: instance.Spec.NodeSelector, }, }, }, @@ -157,8 +156,8 @@ func StatefulSet( }, corev1.LabelHostname, ) - if instance.Spec.NodeSelector != nil && len(instance.Spec.NodeSelector) > 0 { - statefulSet.Spec.Template.Spec.NodeSelector = instance.Spec.NodeSelector + if instance.Spec.NodeSelector != nil { + statefulSet.Spec.Template.Spec.NodeSelector = *instance.Spec.NodeSelector } // TODO: bind's init container doesn't need most of this stuff. It doesn't use rabbitmq, redis or access the diff --git a/pkg/designatecentral/deployment.go b/pkg/designatecentral/deployment.go index 79a5f122..c9930389 100644 --- a/pkg/designatecentral/deployment.go +++ b/pkg/designatecentral/deployment.go @@ -122,7 +122,6 @@ func Deployment( LivenessProbe: livenessProbe, }, }, - NodeSelector: instance.Spec.NodeSelector, }, }, }, @@ -138,8 +137,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 { + deployment.Spec.Template.Spec.NodeSelector = *instance.Spec.NodeSelector } initContainerDetails := designate.APIDetails{ diff --git a/pkg/designatemdns/daemonset.go b/pkg/designatemdns/daemonset.go index a0245cdc..67e81d69 100644 --- a/pkg/designatemdns/daemonset.go +++ b/pkg/designatemdns/daemonset.go @@ -114,7 +114,6 @@ func DaemonSet( LivenessProbe: livenessProbe, }, }, - NodeSelector: instance.Spec.NodeSelector, }, }, }, @@ -130,8 +129,8 @@ func DaemonSet( }, corev1.LabelHostname, ) - if instance.Spec.NodeSelector != nil && len(instance.Spec.NodeSelector) > 0 { - daemonset.Spec.Template.Spec.NodeSelector = instance.Spec.NodeSelector + if instance.Spec.NodeSelector != nil { + daemonset.Spec.Template.Spec.NodeSelector = *instance.Spec.NodeSelector } initContainerDetails := designate.APIDetails{ diff --git a/pkg/designateproducer/deployment.go b/pkg/designateproducer/deployment.go index d7f27b1c..0c50a00d 100644 --- a/pkg/designateproducer/deployment.go +++ b/pkg/designateproducer/deployment.go @@ -118,7 +118,6 @@ func Deployment( LivenessProbe: livenessProbe, }, }, - NodeSelector: instance.Spec.NodeSelector, }, }, }, @@ -134,8 +133,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 { + deployment.Spec.Template.Spec.NodeSelector = *instance.Spec.NodeSelector } initContainerDetails := designate.APIDetails{ diff --git a/pkg/designateunbound/deployment.go b/pkg/designateunbound/deployment.go index 7f6403bd..71b65aa1 100644 --- a/pkg/designateunbound/deployment.go +++ b/pkg/designateunbound/deployment.go @@ -146,8 +146,8 @@ func Deployment(instance *designatev1beta1.DesignateUnbound, }, 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 { + deployment.Spec.Template.Spec.NodeSelector = *instance.Spec.NodeSelector } return deployment diff --git a/pkg/designateworker/deployment.go b/pkg/designateworker/deployment.go index 58503e0d..b58e2ae4 100644 --- a/pkg/designateworker/deployment.go +++ b/pkg/designateworker/deployment.go @@ -114,7 +114,6 @@ func Deployment( LivenessProbe: livenessProbe, }, }, - NodeSelector: instance.Spec.NodeSelector, }, }, }, @@ -130,8 +129,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 { + deployment.Spec.Template.Spec.NodeSelector = *instance.Spec.NodeSelector } initContainerDetails := designate.APIDetails{ From 758e4a59e949a38fcb3834bdc022b65a33bd1698 Mon Sep 17 00:00:00 2001 From: Oliver Walsh Date: Wed, 20 Nov 2024 14:30:35 +0000 Subject: [PATCH 2/2] Set nodeSelector on dbsync jobs --- pkg/designate/dbsync.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/designate/dbsync.go b/pkg/designate/dbsync.go index 7e1df5d3..239a3b47 100644 --- a/pkg/designate/dbsync.go +++ b/pkg/designate/dbsync.go @@ -95,5 +95,9 @@ func DbSyncJob( } job.Spec.Template.Spec.InitContainers = InitContainer(initContainerDetails) + if instance.Spec.NodeSelector != nil { + job.Spec.Template.Spec.NodeSelector = *instance.Spec.NodeSelector + } + return job }