Skip to content

Commit

Permalink
Merge pull request openstack-k8s-operators#1154 from rabi/job_nodesel…
Browse files Browse the repository at this point in the history
…ector

Add nodeselector for ansible jobs
  • Loading branch information
openshift-merge-bot[bot] authored Oct 26, 2024
2 parents 0b1d305 + 02f47e5 commit c2f6677
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 c2f6677

Please sign in to comment.