Skip to content

Commit

Permalink
Merge pull request #252 from openshift-cherrypick-robot/cherry-pick-2…
Browse files Browse the repository at this point in the history
…50-to-18.0-fr1

[18.0-fr1] Ensure nodeSelector logic is consistent for all operators
  • Loading branch information
openshift-merge-bot[bot] authored Nov 22, 2024
2 parents ba17591 + 758e4a5 commit b998769
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 49 deletions.
2 changes: 1 addition & 1 deletion api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta1/designate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 14 additions & 6 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 35 additions & 21 deletions controllers/designate_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions pkg/designate/dbsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 2 additions & 3 deletions pkg/designateapi/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ func Deployment(
LivenessProbe: livenessProbe,
},
},
NodeSelector: instance.Spec.NodeSelector,
},
},
},
Expand All @@ -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{
Expand Down
5 changes: 2 additions & 3 deletions pkg/designatebackendbind9/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ func StatefulSet(
ReadinessProbe: readinessProbe,
},
},
NodeSelector: instance.Spec.NodeSelector,
},
},
},
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions pkg/designatecentral/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ func Deployment(
LivenessProbe: livenessProbe,
},
},
NodeSelector: instance.Spec.NodeSelector,
},
},
},
Expand All @@ -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{
Expand Down
5 changes: 2 additions & 3 deletions pkg/designatemdns/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ func DaemonSet(
LivenessProbe: livenessProbe,
},
},
NodeSelector: instance.Spec.NodeSelector,
},
},
},
Expand All @@ -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{
Expand Down
5 changes: 2 additions & 3 deletions pkg/designateproducer/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ func Deployment(
LivenessProbe: livenessProbe,
},
},
NodeSelector: instance.Spec.NodeSelector,
},
},
},
Expand All @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions pkg/designateunbound/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions pkg/designateworker/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ func Deployment(
LivenessProbe: livenessProbe,
},
},
NodeSelector: instance.Spec.NodeSelector,
},
},
},
Expand All @@ -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{
Expand Down

0 comments on commit b998769

Please sign in to comment.