diff --git a/apis/bases/dataplane.openstack.org_openstackdataplanedeployments.yaml b/apis/bases/dataplane.openstack.org_openstackdataplanedeployments.yaml index 403b30db0..939559fd1 100644 --- a/apis/bases/dataplane.openstack.org_openstackdataplanedeployments.yaml +++ b/apis/bases/dataplane.openstack.org_openstackdataplanedeployments.yaml @@ -46,6 +46,10 @@ spec: properties: ansibleExtraVars: x-kubernetes-preserve-unknown-fields: true + ansibleJobNodeSelector: + additionalProperties: + type: string + type: object ansibleLimit: type: string ansibleSkipTags: diff --git a/apis/dataplane/v1beta1/openstackdataplanedeployment_types.go b/apis/dataplane/v1beta1/openstackdataplanedeployment_types.go index 4f062da84..a810cb6c0 100644 --- a/apis/dataplane/v1beta1/openstackdataplanedeployment_types.go +++ b/apis/dataplane/v1beta1/openstackdataplanedeployment_types.go @@ -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 diff --git a/apis/dataplane/v1beta1/zz_generated.deepcopy.go b/apis/dataplane/v1beta1/zz_generated.deepcopy.go index dec42fefe..ebe72aef3 100644 --- a/apis/dataplane/v1beta1/zz_generated.deepcopy.go +++ b/apis/dataplane/v1beta1/zz_generated.deepcopy.go @@ -355,6 +355,13 @@ func (in *OpenStackDataPlaneDeploymentSpec) DeepCopyInto(out *OpenStackDataPlane *out = make([]string, len(*in)) copy(*out, *in) } + if in.AnsibleJobNodeSelector != nil { + in, out := &in.AnsibleJobNodeSelector, &out.AnsibleJobNodeSelector + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OpenStackDataPlaneDeploymentSpec. diff --git a/config/crd/bases/dataplane.openstack.org_openstackdataplanedeployments.yaml b/config/crd/bases/dataplane.openstack.org_openstackdataplanedeployments.yaml index 403b30db0..939559fd1 100644 --- a/config/crd/bases/dataplane.openstack.org_openstackdataplanedeployments.yaml +++ b/config/crd/bases/dataplane.openstack.org_openstackdataplanedeployments.yaml @@ -46,6 +46,10 @@ spec: properties: ansibleExtraVars: x-kubernetes-preserve-unknown-fields: true + ansibleJobNodeSelector: + additionalProperties: + type: string + type: object ansibleLimit: type: string ansibleSkipTags: diff --git a/pkg/dataplane/util/ansible_execution.go b/pkg/dataplane/util/ansible_execution.go index a18aacb5e..910f88611 100644 --- a/pkg/dataplane/util/ansible_execution.go +++ b/pkg/dataplane/util/ansible_execution.go @@ -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) diff --git a/pkg/dataplane/util/ansibleee.go b/pkg/dataplane/util/ansibleee.go index e5b73d143..9b1af497d 100644 --- a/pkg/dataplane/util/ansibleee.go +++ b/pkg/dataplane/util/ansibleee.go @@ -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 @@ -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"