Skip to content

Commit

Permalink
Merge pull request #466 from olliewalsh/node_selectors
Browse files Browse the repository at this point in the history
Ensure nodeSelector logic is consistent for all operators
  • Loading branch information
openshift-merge-bot[bot] authored Nov 20, 2024
2 parents 8cd575c + 0fd9df2 commit 9e97663
Showing 13 changed files with 276 additions and 37 deletions.
2 changes: 1 addition & 1 deletion api/v1beta1/cinder_types.go
Original file line number Diff line number Diff line change
@@ -93,7 +93,7 @@ type CinderSpecBase struct {
// NodeSelector to target subset of worker nodes running this service. Setting
// NodeSelector here acts as a default value and can be overridden by service
// specific NodeSelector Settings.
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
NodeSelector *map[string]string `json:"nodeSelector,omitempty"`

// +kubebuilder:validation:Optional
// DBPurge parameters -
2 changes: 1 addition & 1 deletion api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ type CinderServiceTemplate struct {
// +kubebuilder:validation:Optional
// NodeSelector to target subset of worker nodes running this service. Setting here overrides
// any global NodeSelector settings within the Cinder 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,
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.

31 changes: 16 additions & 15 deletions controllers/cinder_controller.go
Original file line number Diff line number Diff line change
@@ -1020,6 +1020,10 @@ func (r *CinderReconciler) apiDeploymentCreateOrUpdate(ctx context.Context, inst
ServiceAccount: instance.RbacResourceName(),
}

if cinderAPISpec.NodeSelector == nil {
cinderAPISpec.NodeSelector = instance.Spec.NodeSelector
}

deployment := &cinderv1beta1.CinderAPI{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-api", instance.Name),
@@ -1029,9 +1033,6 @@ func (r *CinderReconciler) apiDeploymentCreateOrUpdate(ctx context.Context, inst

op, err := controllerutil.CreateOrUpdate(ctx, r.Client, deployment, func() error {
deployment.Spec = cinderAPISpec
if len(deployment.Spec.NodeSelector) == 0 {
deployment.Spec.NodeSelector = instance.Spec.NodeSelector
}

err := controllerutil.SetControllerReference(instance, deployment, r.Scheme)
if err != nil {
@@ -1055,6 +1056,10 @@ func (r *CinderReconciler) schedulerDeploymentCreateOrUpdate(ctx context.Context
TLS: instance.Spec.CinderAPI.TLS.Ca,
}

if cinderSchedulerSpec.NodeSelector == nil {
cinderSchedulerSpec.NodeSelector = instance.Spec.NodeSelector
}

deployment := &cinderv1beta1.CinderScheduler{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-scheduler", instance.Name),
@@ -1064,9 +1069,6 @@ func (r *CinderReconciler) schedulerDeploymentCreateOrUpdate(ctx context.Context

op, err := controllerutil.CreateOrUpdate(ctx, r.Client, deployment, func() error {
deployment.Spec = cinderSchedulerSpec
if len(deployment.Spec.NodeSelector) == 0 {
deployment.Spec.NodeSelector = instance.Spec.NodeSelector
}

err := controllerutil.SetControllerReference(instance, deployment, r.Scheme)
if err != nil {
@@ -1090,6 +1092,10 @@ func (r *CinderReconciler) backupDeploymentCreateOrUpdate(ctx context.Context, i
TLS: instance.Spec.CinderAPI.TLS.Ca,
}

if cinderBackupSpec.NodeSelector == nil {
cinderBackupSpec.NodeSelector = instance.Spec.NodeSelector
}

deployment := &cinderv1beta1.CinderBackup{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-backup", instance.Name),
@@ -1099,9 +1105,6 @@ func (r *CinderReconciler) backupDeploymentCreateOrUpdate(ctx context.Context, i

op, err := controllerutil.CreateOrUpdate(ctx, r.Client, deployment, func() error {
deployment.Spec = cinderBackupSpec
if len(deployment.Spec.NodeSelector) == 0 {
deployment.Spec.NodeSelector = instance.Spec.NodeSelector
}

err := controllerutil.SetControllerReference(instance, deployment, r.Scheme)
if err != nil {
@@ -1152,6 +1155,10 @@ func (r *CinderReconciler) volumeDeploymentCreateOrUpdate(ctx context.Context, i
TLS: instance.Spec.CinderAPI.TLS.Ca,
}

if cinderVolumeSpec.CinderVolumeTemplate.NodeSelector == nil {
cinderVolumeSpec.CinderVolumeTemplate.NodeSelector = instance.Spec.NodeSelector
}

deployment := &cinderv1beta1.CinderVolume{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-volume-%s", instance.Name, name),
@@ -1163,12 +1170,6 @@ func (r *CinderReconciler) volumeDeploymentCreateOrUpdate(ctx context.Context, i
op, err := controllerutil.CreateOrUpdate(ctx, r.Client, deployment, func() error {
deployment.Spec = cinderVolumeSpec

// If NodeSelector is not specified in volumeTemplate, the current
// cinder-volume instance inherits the value from the top-level CR
if len(volTemplate.NodeSelector) == 0 {
deployment.Spec.NodeSelector = instance.Spec.NodeSelector
}

err := controllerutil.SetControllerReference(instance, deployment, r.Scheme)
if err != nil {
return err
6 changes: 4 additions & 2 deletions pkg/cinder/cronjob.go
Original file line number Diff line number Diff line change
@@ -134,8 +134,10 @@ func CronJob(
},
},
}
if instance.Spec.NodeSelector != nil && len(instance.Spec.NodeSelector) > 0 {
cronjob.Spec.JobTemplate.Spec.Template.Spec.NodeSelector = instance.Spec.NodeSelector

if instance.Spec.NodeSelector != nil {
cronjob.Spec.JobTemplate.Spec.Template.Spec.NodeSelector = *instance.Spec.NodeSelector
}

return cronjob
}
4 changes: 4 additions & 0 deletions pkg/cinder/dbsync.go
Original file line number Diff line number Diff line change
@@ -115,5 +115,9 @@ func DbSyncJob(instance *cinderv1beta1.Cinder, labels map[string]string, annotat
},
}

if instance.Spec.NodeSelector != nil {
job.Spec.Template.Spec.NodeSelector = *instance.Spec.NodeSelector
}

return job
}
9 changes: 6 additions & 3 deletions pkg/cinderapi/statefuleset.go
Original file line number Diff line number Diff line change
@@ -165,13 +165,16 @@ func StatefulSet(
LivenessProbe: livenessProbe,
},
},
Affinity: cinder.GetPodAffinity(ComponentName),
NodeSelector: instance.Spec.NodeSelector,
Volumes: volumes,
Affinity: cinder.GetPodAffinity(ComponentName),
Volumes: volumes,
},
},
},
}

if instance.Spec.NodeSelector != nil {
statefulset.Spec.Template.Spec.NodeSelector = *instance.Spec.NodeSelector
}

return statefulset, nil
}
9 changes: 6 additions & 3 deletions pkg/cinderbackup/statefulset.go
Original file line number Diff line number Diff line change
@@ -146,13 +146,16 @@ func StatefulSet(
VolumeMounts: volumeMounts,
},
},
Affinity: cinder.GetPodAffinity(ComponentName),
NodeSelector: instance.Spec.NodeSelector,
Volumes: volumes,
Affinity: cinder.GetPodAffinity(ComponentName),
Volumes: volumes,
},
},
},
}

if instance.Spec.NodeSelector != nil {
statefulset.Spec.Template.Spec.NodeSelector = *instance.Spec.NodeSelector
}

return statefulset
}
9 changes: 6 additions & 3 deletions pkg/cinderscheduler/statefulset.go
Original file line number Diff line number Diff line change
@@ -131,13 +131,16 @@ func StatefulSet(
VolumeMounts: volumeMounts,
},
},
Affinity: cinder.GetPodAffinity(ComponentName),
NodeSelector: instance.Spec.NodeSelector,
Volumes: volumes,
Affinity: cinder.GetPodAffinity(ComponentName),
Volumes: volumes,
},
},
},
}

if instance.Spec.NodeSelector != nil {
statefulset.Spec.Template.Spec.NodeSelector = *instance.Spec.NodeSelector
}

return statefulset
}
9 changes: 6 additions & 3 deletions pkg/cindervolume/statefulset.go
Original file line number Diff line number Diff line change
@@ -153,13 +153,16 @@ func StatefulSet(
VolumeMounts: volumeMounts,
},
},
Affinity: cinder.GetPodAffinity(ComponentName),
NodeSelector: instance.Spec.NodeSelector,
Volumes: volumes,
Affinity: cinder.GetPodAffinity(ComponentName),
Volumes: volumes,
},
},
},
}

if instance.Spec.NodeSelector != nil {
statefulset.Spec.Template.Spec.NodeSelector = *instance.Spec.NodeSelector
}

return statefulset
}
9 changes: 9 additions & 0 deletions test/functional/base_test.go
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ import (
"golang.org/x/exp/maps"

. "github.com/onsi/gomega" //revive:disable:dot-imports
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -230,6 +231,14 @@ func GetCinderVolume(name types.NamespacedName) *cinderv1.CinderVolume {
return instance
}

func GetCronJob(name types.NamespacedName) *batchv1.CronJob {
instance := &batchv1.CronJob{}
Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(ctx, name, instance)).Should(Succeed())
}, timeout, interval).Should(Succeed())
return instance
}

func CinderAPIConditionGetter(name types.NamespacedName) condition.Conditions {
instance := GetCinderAPI(name)
return instance.Status.Conditions
Loading

0 comments on commit 9e97663

Please sign in to comment.