Skip to content

Commit

Permalink
Add nodeselector for ansible jobs
Browse files Browse the repository at this point in the history
This way we can run the jobs only on nodes where required NAD
networks are available.

jira: OSPRH-10939
Signed-off-by: rabi <[email protected]>
  • Loading branch information
rabi committed Oct 25, 2024
1 parent 9b7f46d commit 02f47e5
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ spec:
properties:
ansibleExtraVars:
x-kubernetes-preserve-unknown-fields: true
ansibleJobNodeSelector:
additionalProperties:
type: string
type: object
ansibleLimit:
type: string
ansibleSkipTags:
Expand Down
4 changes: 4 additions & 0 deletions apis/dataplane/v1beta1/openstackdataplanedeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ type OpenStackDataPlaneDeploymentSpec struct {
// +kubebuilder:validation:Minimum:=1
// +kubebuilder:default:=15
DeploymentRequeueTime int `json:"deploymentRequeueTime"`

// +kubebuilder:validation:Optional
// AnsibleJobNodeSelector to target subset of worker nodes running the ansible jobs
AnsibleJobNodeSelector map[string]string `json:"ansibleJobNodeSelector,omitempty"`
}

// OpenStackDataPlaneDeploymentStatus defines the observed state of OpenStackDataPlaneDeployment
Expand Down
7 changes: 7 additions & 0 deletions apis/dataplane/v1beta1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ spec:
properties:
ansibleExtraVars:
x-kubernetes-preserve-unknown-fields: true
ansibleJobNodeSelector:
additionalProperties:
type: string
type: object
ansibleLimit:
type: string
ansibleSkipTags:
Expand Down
1 change: 1 addition & 0 deletions pkg/dataplane/util/ansible_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func AnsibleExecution(

ansibleEE.ExtraMounts = append(aeeSpec.ExtraMounts, []storage.VolMounts{ansibleEEMounts}...)
ansibleEE.Env = aeeSpec.Env
ansibleEE.NodeSelector = deployment.Spec.AnsibleJobNodeSelector

currentJobHash := deployment.Status.AnsibleEEHashes[ansibleEE.Name]
jobDef, err := ansibleEE.JobForOpenStackAnsibleEE(helper)
Expand Down
6 changes: 6 additions & 0 deletions pkg/dataplane/util/ansibleee.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ type EEJob struct {
Annotations map[string]string `json:"annotations,omitempty"`
// Env is a list containing the environment variables to pass to the pod
Env []corev1.EnvVar `json:"env,omitempty"`
// NodeSelector to target subset of worker nodes running the ansible jobs
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
}

// JobForOpenStackAnsibleEE returns a openstackansibleee Job object
Expand Down Expand Up @@ -103,6 +105,10 @@ func (a *EEJob) JobForOpenStackAnsibleEE(h *helper.Helper) (*batchv1.Job, error)
}},
}

if a.NodeSelector != nil && len(a.NodeSelector) > 0 {
podSpec.NodeSelector = a.NodeSelector
}

if a.DNSConfig != nil {
podSpec.DNSConfig = a.DNSConfig
podSpec.DNSPolicy = "None"
Expand Down

0 comments on commit 02f47e5

Please sign in to comment.