Skip to content

Commit

Permalink
Merge pull request #360 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 21, 2024
2 parents 21b7f58 + b8938d3 commit bfd56f1
Show file tree
Hide file tree
Showing 11 changed files with 248 additions and 31 deletions.
2 changes: 1 addition & 1 deletion api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type ManilaServiceTemplate struct {
// +kubebuilder:validation:Optional
// NodeSelector to target subset of worker nodes running this service. Setting here overrides
// any global NodeSelector settings within the Manila CR.
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
NodeSelector *map[string]string `json:"nodeSelector,omitempty"`

// +kubebuilder:validation:Optional
// +kubebuilder:default="# add your customization here"
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta1/manila_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ type ManilaSpecBase 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 -
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.

23 changes: 12 additions & 11 deletions controllers/manila_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -977,12 +977,13 @@ func (r *ManilaReconciler) apiDeploymentCreateOrUpdate(ctx context.Context, inst
ServiceAccount: instance.RbacResourceName(),
}

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

op, err := controllerutil.CreateOrUpdate(ctx, r.Client, deployment, func() error {
deployment.Spec = apiSpec

if len(deployment.Spec.NodeSelector) == 0 {
deployment.Spec.NodeSelector = instance.Spec.NodeSelector
}
deployment.Spec.TransportURLSecret = instance.Status.TransportURLSecret

err := controllerutil.SetControllerReference(instance, deployment, r.Scheme)
Expand Down Expand Up @@ -1014,12 +1015,12 @@ func (r *ManilaReconciler) schedulerDeploymentCreateOrUpdate(ctx context.Context
TLS: instance.Spec.ManilaAPI.TLS.Ca,
}

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

op, err := controllerutil.CreateOrUpdate(ctx, r.Client, deployment, func() error {
deployment.Spec = schedulerSpec

if len(deployment.Spec.NodeSelector) == 0 {
deployment.Spec.NodeSelector = instance.Spec.NodeSelector
}
deployment.Spec.TransportURLSecret = instance.Status.TransportURLSecret

err := controllerutil.SetControllerReference(instance, deployment, r.Scheme)
Expand Down Expand Up @@ -1061,12 +1062,12 @@ func (r *ManilaReconciler) shareDeploymentCreateOrUpdate(
TLS: instance.Spec.ManilaAPI.TLS.Ca,
}

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

op, err := controllerutil.CreateOrUpdate(ctx, r.Client, deployment, func() error {
deployment.Spec = shareSpec

if len(deployment.Spec.NodeSelector) == 0 {
deployment.Spec.NodeSelector = instance.Spec.NodeSelector
}
deployment.Spec.TransportURLSecret = instance.Status.TransportURLSecret

err := controllerutil.SetControllerReference(instance, deployment, r.Scheme)
Expand Down
5 changes: 3 additions & 2 deletions pkg/manila/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ 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
Expand Down
4 changes: 4 additions & 0 deletions pkg/manila/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package manila

import (
"fmt"

"github.com/openstack-k8s-operators/lib-common/modules/common/env"
manilav1 "github.com/openstack-k8s-operators/manila-operator/api/v1beta1"
batchv1 "k8s.io/api/batch/v1"
Expand Down Expand Up @@ -119,5 +120,8 @@ func Job(
// Setting TTL to delete the job after it has completed
job.Spec.TTLSecondsAfterFinished = ttl
}
if instance.Spec.NodeSelector != nil {
job.Spec.Template.Spec.NodeSelector = *instance.Spec.NodeSelector
}
return job
}
9 changes: 6 additions & 3 deletions pkg/manilaapi/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,16 @@ func StatefulSet(
LivenessProbe: livenessProbe,
},
},
Affinity: manila.GetPodAffinity(ComponentName),
NodeSelector: instance.Spec.NodeSelector,
Volumes: volumes,
Affinity: manila.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/manilascheduler/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,16 @@ func StatefulSet(
VolumeMounts: volumeMounts,
},
},
Affinity: manila.GetPodAffinity(ComponentName),
NodeSelector: instance.Spec.NodeSelector,
Volumes: volumes,
Affinity: manila.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/manilashare/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,16 @@ func StatefulSet(
VolumeMounts: volumeMounts,
},
},
Affinity: manila.GetPodAffinity(ComponentName),
NodeSelector: instance.Spec.NodeSelector,
Volumes: volumes,
Affinity: manila.GetPodAffinity(ComponentName),
Volumes: volumes,
},
},
},
}

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

return statefulset
}
4 changes: 3 additions & 1 deletion test/functional/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ func GetDefaultManilaSpec() map[string]interface{} {
"secret": SecretName,
"manilaAPI": GetDefaultManilaAPISpec(),
"manilaScheduler": GetDefaultManilaSchedulerSpec(),
"manilaShare": GetDefaultManilaShareSpec(),
"manilaShares": map[string]interface{}{
"share0": GetDefaultManilaShareSpec(),
},
}
}

Expand Down
Loading

0 comments on commit bfd56f1

Please sign in to comment.