Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[18.0-fr1] Ensure nodeSelector logic is consistent for all operators #498

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type IronicServiceTemplate struct {
// +kubebuilder:validation:Optional
// NodeSelector to target subset of worker nodes running this service. Setting here overrides
// any global NodeSelector settings within the Ironic CR
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
NodeSelector *map[string]string `json:"nodeSelector,omitempty"`

// +kubebuilder:validation:Optional
// Resources - Compute Resources required by this service (Limits/Requests).
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta1/ironic_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ type IronicSpecCore 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"`

// Storage class to host data. This is passed to IronicConductors unless
// storageClass is explicitly set for the conductor.
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta1/ironicinspector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type IronicInspectorTemplate struct {
// +kubebuilder:validation:Optional
// NodeSelector to target subset of worker nodes running this service. Setting here overrides
// any global NodeSelector settings within the Ironic CR
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
NodeSelector *map[string]string `json:"nodeSelector,omitempty"`

// +kubebuilder:validation:Optional
// +kubebuilder:default=true
Expand Down
30 changes: 21 additions & 9 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: 19 additions & 12 deletions controllers/ironic_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,11 @@ func (r *IronicReconciler) conductorDeploymentCreateOrUpdate(
KeystoneEndpoints: *keystoneEndpoints,
TLS: instance.Spec.IronicAPI.TLS.Ca,
}

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

deployment := &ironicv1.IronicConductor{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Expand All @@ -787,9 +792,6 @@ func (r *IronicReconciler) conductorDeploymentCreateOrUpdate(

op, err := controllerutil.CreateOrUpdate(context.TODO(), r.Client, deployment, func() error {
deployment.Spec = IronicConductorSpec
if len(deployment.Spec.NodeSelector) == 0 {
deployment.Spec.NodeSelector = instance.Spec.NodeSelector
}
if deployment.Spec.StorageClass == "" {
deployment.Spec.StorageClass = instance.Spec.StorageClass
}
Expand Down Expand Up @@ -822,6 +824,10 @@ func (r *IronicReconciler) apiDeploymentCreateOrUpdate(
KeystoneEndpoints: *keystoneEndpoints,
}

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

deployment := &ironicv1.IronicAPI{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-api", instance.Name),
Expand All @@ -831,9 +837,6 @@ func (r *IronicReconciler) apiDeploymentCreateOrUpdate(

op, err := controllerutil.CreateOrUpdate(context.TODO(), r.Client, deployment, func() error {
deployment.Spec = IronicAPISpec
if len(deployment.Spec.NodeSelector) == 0 {
deployment.Spec.NodeSelector = instance.Spec.NodeSelector
}
err := controllerutil.SetControllerReference(instance, deployment, r.Scheme)
if err != nil {
return err
Expand Down Expand Up @@ -977,6 +980,11 @@ func (r *IronicReconciler) inspectorDeploymentCreateOrUpdate(
RabbitMqClusterName: instance.Spec.RabbitMqClusterName,
Secret: instance.Spec.Secret,
}

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

deployment := &ironicv1.IronicInspector{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-inspector", instance.Name),
Expand All @@ -987,9 +995,6 @@ func (r *IronicReconciler) inspectorDeploymentCreateOrUpdate(
op, err := controllerutil.CreateOrUpdate(
context.TODO(), r.Client, deployment, func() error {
deployment.Spec = IronicInspectorSpec
if len(deployment.Spec.NodeSelector) == 0 {
deployment.Spec.NodeSelector = instance.Spec.NodeSelector
}
err := controllerutil.SetControllerReference(
instance, deployment, r.Scheme)
if err != nil {
Expand Down Expand Up @@ -1046,6 +1051,11 @@ func (r *IronicReconciler) ironicNeutronAgentDeploymentCreateOrUpdate(
ServiceUser: instance.Spec.ServiceUser,
TLS: instance.Spec.IronicAPI.TLS.Ca,
}

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

deployment := &ironicv1.IronicNeutronAgent{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-ironic-neutron-agent", instance.Name),
Expand All @@ -1056,9 +1066,6 @@ func (r *IronicReconciler) ironicNeutronAgentDeploymentCreateOrUpdate(
op, err := controllerutil.CreateOrUpdate(
context.TODO(), r.Client, deployment, func() error {
deployment.Spec = IronicNeutronAgentSpec
if len(deployment.Spec.NodeSelector) == 0 {
deployment.Spec.NodeSelector = instance.Spec.NodeSelector
}
err := controllerutil.SetControllerReference(
instance, deployment, r.Scheme)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/ironic/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
}
4 changes: 2 additions & 2 deletions pkg/ironicapi/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,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 := ironic.APIDetails{
Expand Down
4 changes: 2 additions & 2 deletions pkg/ironicconductor/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,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
}

// init.sh needs to detect and set ProvisionNetworkIP
Expand Down
4 changes: 4 additions & 0 deletions pkg/ironicinspector/dbsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,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
}
4 changes: 2 additions & 2 deletions pkg/ironicinspector/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ func StatefulSet(
[]string{ironic.ServiceName},
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
}

// init.sh needs to detect and set InspectionNetworkIP
Expand Down
4 changes: 2 additions & 2 deletions pkg/ironicneutronagent/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,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 := APIDetails{
Expand Down
9 changes: 6 additions & 3 deletions tests/functional/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,16 @@ func GetIronicNames(
},
InternalCertSecretName: types.NamespacedName{
Namespace: ironicName.Namespace,
Name: "internal-tls-certs"},
Name: "internal-tls-certs",
},
PublicCertSecretName: types.NamespacedName{
Namespace: ironicName.Namespace,
Name: "public-tls-certs"},
Name: "public-tls-certs",
},
CaBundleSecretName: types.NamespacedName{
Namespace: ironicName.Namespace,
Name: "combined-ca-bundle"},
Name: "combined-ca-bundle",
},
}
}

Expand Down
Loading
Loading