Skip to content

Commit

Permalink
Set nodeSelector on jobs and allow empty nodeSelector
Browse files Browse the repository at this point in the history
Switch to a pointer for nodeSelector to allow different logic for empty vs unset
  • Loading branch information
olliewalsh authored and openshift-merge-bot[bot] committed Nov 19, 2024
1 parent 9566e1f commit 6494d7b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/v1beta1/placementapi_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type PlacementAPISpecCore 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
10 changes: 7 additions & 3 deletions api/v1beta1/zz_generated.deepcopy.go

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

4 changes: 4 additions & 0 deletions pkg/placement/dbsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,9 @@ func DbSyncJob(
},
}

if instance.Spec.NodeSelector != nil && len(*instance.Spec.NodeSelector) > 0 {
job.Spec.Template.Spec.NodeSelector = *instance.Spec.NodeSelector
}

return job
}
4 changes: 2 additions & 2 deletions pkg/placement/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,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 && len(*instance.Spec.NodeSelector) > 0 {
deployment.Spec.Template.Spec.NodeSelector = *instance.Spec.NodeSelector
}

return deployment, nil
Expand Down

0 comments on commit 6494d7b

Please sign in to comment.