Skip to content

Commit b1bf4a9

Browse files
committed
Fix: added customizable ansibleEE env ConfigMap name
Currently there is only one hardcoded string `openstack-aee-default-env` for ansibleEE environment variable, which is applied throughout the cluser. This PR tries to let users ability to customize the ansibleEE env configMap for deployments and nodeset levels individually. The precedence order for ansibleEEEnvConfigMap is deployment > nodeset > default.
1 parent 38e6308 commit b1bf4a9

9 files changed

Lines changed: 79 additions & 5 deletions

‎api/bases/dataplane.openstack.org_openstackdataplanedeployments.yaml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ spec:
5959
description: OpenStackDataPlaneDeploymentSpec defines the desired state
6060
of OpenStackDataPlaneDeployment
6161
properties:
62+
ansibleEEEnvConfigMapName:
63+
description: |-
64+
AnsibleEEEnvConfigMapName is the name of the ConfigMap containing environment
65+
variables to inject into the Ansible Execution Environment pod.
66+
If set, this takes precedence over the NodeSet's AnsibleEEEnvConfigMapName.
67+
If not specified, the NodeSet's AnsibleEEEnvConfigMapName is used, or the
68+
default "openstack-aee-default-env" if neither is set.
69+
maxLength: 253
70+
type: string
6271
ansibleExtraVars:
6372
description: AnsibleExtraVars for ansible execution
6473
x-kubernetes-preserve-unknown-fields: true

‎api/bases/dataplane.openstack.org_openstackdataplanenodesets.yaml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ spec:
5555
description: OpenStackDataPlaneNodeSetSpec defines the desired state of
5656
OpenStackDataPlaneNodeSet
5757
properties:
58+
ansibleEEEnvConfigMapName:
59+
description: |-
60+
AnsibleEEEnvConfigMapName is the name of the ConfigMap containing environment
61+
variables to inject into the Ansible Execution Environment pod.
62+
The ConfigMap should contain environment variables used by ansible-runner
63+
such as ANSIBLE_VERBOSITY, ANSIBLE_FORCE_COLOR, or other runner settings.
64+
See https://ansible.readthedocs.io/projects/runner/en/stable/intro/#env-settings-settings-for-runner-itself
65+
If not specified, defaults to "openstack-aee-default-env".
66+
This can be overridden at the Deployment level.
67+
maxLength: 253
68+
type: string
5869
baremetalSetTemplate:
5970
description: BaremetalSetTemplate Template for BaremetalSet for the
6071
NodeSet

‎api/dataplane/v1beta1/common.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,7 @@ type AnsibleEESpec struct {
198198
// the ansible execution run with. Without specifying, it will run with
199199
// default serviceaccount
200200
ServiceAccountName string
201+
// AnsibleEEEnvConfigMapName is the name of ConfigMap containing environment
202+
// variables to inject to the Ansible execution environment pod.
203+
AnsibleEEEnvConfigMapName string `json:"ansibleEEEnvConfigMapName,omitempty"`
201204
}

‎api/dataplane/v1beta1/openstackdataplanedeployment_types.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ type OpenStackDataPlaneDeploymentSpec struct {
7171
// +kubebuilder:validation:Optional
7272
// AnsibleJobNodeSelector to target subset of worker nodes running the ansible jobs
7373
AnsibleJobNodeSelector map[string]string `json:"ansibleJobNodeSelector,omitempty"`
74+
75+
// +kubebuilder:validation:Optional
76+
// +kubebuilder:validation:MaxLength:=253
77+
// AnsibleEEEnvConfigMapName is the name of the ConfigMap containing environment
78+
// variables to inject into the Ansible Execution Environment pod.
79+
// If set, this takes precedence over the NodeSet's AnsibleEEEnvConfigMapName.
80+
// If not specified, the NodeSet's AnsibleEEEnvConfigMapName is used, or the
81+
// default "openstack-aee-default-env" if neither is set.
82+
AnsibleEEEnvConfigMapName string `json:"ansibleEEEnvConfigMapName,omitempty"`
7483
}
7584

7685
// OpenStackDataPlaneDeploymentStatus defines the observed state of OpenStackDataPlaneDeployment

‎api/dataplane/v1beta1/openstackdataplanenodeset_types.go‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,17 @@ type OpenStackDataPlaneNodeSetSpec struct {
8686
// +kubebuilder:default=true
8787
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:booleanSwitch"}
8888
TLSEnabled bool `json:"tlsEnabled" yaml:"tlsEnabled"`
89+
90+
// +kubebuilder:validation:Optional
91+
// +kubebuilder:validation:MaxLength:=253
92+
// AnsibleEEEnvConfigMapName is the name of the ConfigMap containing environment
93+
// variables to inject into the Ansible Execution Environment pod.
94+
// The ConfigMap should contain environment variables used by ansible-runner
95+
// such as ANSIBLE_VERBOSITY, ANSIBLE_FORCE_COLOR, or other runner settings.
96+
// See https://ansible.readthedocs.io/projects/runner/en/stable/intro/#env-settings-settings-for-runner-itself
97+
// If not specified, defaults to "openstack-aee-default-env".
98+
// This can be overridden at the Deployment level.
99+
AnsibleEEEnvConfigMapName string `json:"ansibleEEEnvConfigMapName,omitempty"`
89100
}
90101

91102
// +kubebuilder:object:root=true
@@ -205,10 +216,11 @@ func (instance *OpenStackDataPlaneNodeSet) InitConditions() {
205216
// GetAnsibleEESpec - get the fields that will be passed to AEE Job
206217
func (instance OpenStackDataPlaneNodeSet) GetAnsibleEESpec() AnsibleEESpec {
207218
return AnsibleEESpec{
208-
NetworkAttachments: instance.Spec.NetworkAttachments,
209-
ExtraMounts: instance.Spec.NodeTemplate.ExtraMounts,
210-
Env: instance.Spec.Env,
211-
ServiceAccountName: instance.Name,
219+
NetworkAttachments: instance.Spec.NetworkAttachments,
220+
ExtraMounts: instance.Spec.NodeTemplate.ExtraMounts,
221+
Env: instance.Spec.Env,
222+
ServiceAccountName: instance.Name,
223+
AnsibleEEEnvConfigMapName: instance.Spec.AnsibleEEEnvConfigMapName,
212224
}
213225
}
214226

‎config/crd/bases/dataplane.openstack.org_openstackdataplanedeployments.yaml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ spec:
5959
description: OpenStackDataPlaneDeploymentSpec defines the desired state
6060
of OpenStackDataPlaneDeployment
6161
properties:
62+
ansibleEEEnvConfigMapName:
63+
description: |-
64+
AnsibleEEEnvConfigMapName is the name of the ConfigMap containing environment
65+
variables to inject into the Ansible Execution Environment pod.
66+
If set, this takes precedence over the NodeSet's AnsibleEEEnvConfigMapName.
67+
If not specified, the NodeSet's AnsibleEEEnvConfigMapName is used, or the
68+
default "openstack-aee-default-env" if neither is set.
69+
maxLength: 253
70+
type: string
6271
ansibleExtraVars:
6372
description: AnsibleExtraVars for ansible execution
6473
x-kubernetes-preserve-unknown-fields: true

‎config/crd/bases/dataplane.openstack.org_openstackdataplanenodesets.yaml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ spec:
5555
description: OpenStackDataPlaneNodeSetSpec defines the desired state of
5656
OpenStackDataPlaneNodeSet
5757
properties:
58+
ansibleEEEnvConfigMapName:
59+
description: |-
60+
AnsibleEEEnvConfigMapName is the name of the ConfigMap containing environment
61+
variables to inject into the Ansible Execution Environment pod.
62+
The ConfigMap should contain environment variables used by ansible-runner
63+
such as ANSIBLE_VERBOSITY, ANSIBLE_FORCE_COLOR, or other runner settings.
64+
See https://ansible.readthedocs.io/projects/runner/en/stable/intro/#env-settings-settings-for-runner-itself
65+
If not specified, defaults to "openstack-aee-default-env".
66+
This can be overridden at the Deployment level.
67+
maxLength: 253
68+
type: string
5869
baremetalSetTemplate:
5970
description: BaremetalSetTemplate Template for BaremetalSet for the
6071
NodeSet

‎internal/controller/dataplane/openstackdataplanedeployment_controller.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ func (r *OpenStackDataPlaneDeploymentReconciler) Reconcile(ctx context.Context,
288288
ansibleEESpec.AnsibleSkipTags = instance.Spec.AnsibleSkipTags
289289
ansibleEESpec.AnsibleLimit = instance.Spec.AnsibleLimit
290290
ansibleEESpec.ExtraVars = instance.Spec.AnsibleExtraVars
291+
if instance.Spec.AnsibleEEEnvConfigMapName != "" {
292+
ansibleEESpec.AnsibleEEEnvConfigMapName = instance.Spec.AnsibleEEEnvConfigMapName
293+
}
291294

292295
if nodeSet.Status.DNSClusterAddresses != nil && nodeSet.Status.CtlplaneSearchDomain != "" {
293296
ansibleEESpec.DNSConfig = &corev1.PodDNSConfig{

‎internal/dataplane/util/ansible_execution.go‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import (
4040
dataplanev1 "github.com/openstack-k8s-operators/openstack-operator/api/dataplane/v1beta1"
4141
)
4242

43+
const DefaultAnsibleEEEnvConfigMapName = "openstack-aee-default-env"
44+
4345
// AnsibleExecution creates a batchv1 Job to execute Ansible
4446
func AnsibleExecution(
4547
ctx context.Context,
@@ -65,11 +67,16 @@ func AnsibleExecution(
6567
return nil
6668
}
6769

70+
ansibleEEEnvConfigMapName := aeeSpec.AnsibleEEEnvConfigMapName
71+
if ansibleEEEnvConfigMapName == "" {
72+
ansibleEEEnvConfigMapName = DefaultAnsibleEEEnvConfigMapName
73+
}
74+
6875
ansibleEE := EEJob{
6976
Name: executionName,
7077
Namespace: deployment.GetNamespace(),
7178
Labels: labels,
72-
EnvConfigMapName: "openstack-aee-default-env",
79+
EnvConfigMapName: ansibleEEEnvConfigMapName,
7380
}
7481

7582
ansibleEE.NetworkAttachments = aeeSpec.NetworkAttachments

0 commit comments

Comments
 (0)