From b7a779a310c8f35393be82ad9eaad53ff99893f6 Mon Sep 17 00:00:00 2001 From: Martin Kopec Date: Fri, 13 Oct 2023 17:47:13 +0300 Subject: [PATCH] Add python-tempestconf options --- api/bases/test.openstack.org_tempests.yaml | 8 ++++++++ api/v1beta1/tempest_types.go | 12 ++++++++++- api/v1beta1/zz_generated.deepcopy.go | 20 +++++++++++++++++++ .../bases/test.openstack.org_tempests.yaml | 8 ++++++++ controllers/tempest_controller.go | 12 +++++++++++ pkg/tempest/job.go | 15 ++++++++++++++ 6 files changed, 74 insertions(+), 1 deletion(-) diff --git a/api/bases/test.openstack.org_tempests.yaml b/api/bases/test.openstack.org_tempests.yaml index 516f5582..30c0cf97 100644 --- a/api/bases/test.openstack.org_tempests.yaml +++ b/api/bases/test.openstack.org_tempests.yaml @@ -109,6 +109,14 @@ spec: description: OpenStackConfigSecret is the name of the Secret containing the secure.yaml type: string + pythonTempestconfRun: + description: TempestSpec PythonTempestconf parts + properties: + create: + default: false + description: Create + type: boolean + type: object tempestRun: description: TempestSpec TempestRun parts properties: diff --git a/api/v1beta1/tempest_types.go b/api/v1beta1/tempest_types.go index 86f5213c..2b2bebb3 100644 --- a/api/v1beta1/tempest_types.go +++ b/api/v1beta1/tempest_types.go @@ -56,6 +56,14 @@ type TempestRunSpec struct { WorkerFile string `json:"workerFile,omitempty"` } +// TempestSpec PythonTempestconf parts +type PythonTempestconfRunSpec struct { + // +kubebuilder:validation:Optional + // +kubebuilder:default=false + // Create + Create bool `json:"create"` +} + // TempestSpec defines the desired state of Tempest type TempestSpec struct { // +kubebuilder:validation:Required @@ -92,10 +100,12 @@ type TempestSpec struct { // +kubebuilder:validation:Optional TempestRun *TempestRunSpec `json:"tempestRun,omitempty"` + // +kubebuilder:validation:Optional + PythonTempestconfRun *PythonTempestconfRunSpec `json:"pythonTempestconfRun,omitempty"` + // TODO(slaweq): add more tempest run parameters here } - // MetalLBConfig to configure the MetalLB loadbalancer service type MetalLBConfig struct { // +kubebuilder:validation:Required diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 3f631537..c8f94062 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -61,6 +61,21 @@ func (in *MetalLBConfig) DeepCopy() *MetalLBConfig { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PythonTempestconfRunSpec) DeepCopyInto(out *PythonTempestconfRunSpec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PythonTempestconfRunSpec. +func (in *PythonTempestconfRunSpec) DeepCopy() *PythonTempestconfRunSpec { + if in == nil { + return nil + } + out := new(PythonTempestconfRunSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Tempest) DeepCopyInto(out *Tempest) { *out = *in @@ -182,6 +197,11 @@ func (in *TempestSpec) DeepCopyInto(out *TempestSpec) { *out = new(TempestRunSpec) (*in).DeepCopyInto(*out) } + if in.PythonTempestconfRun != nil { + in, out := &in.PythonTempestconfRun, &out.PythonTempestconfRun + *out = new(PythonTempestconfRunSpec) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TempestSpec. diff --git a/config/crd/bases/test.openstack.org_tempests.yaml b/config/crd/bases/test.openstack.org_tempests.yaml index 516f5582..30c0cf97 100644 --- a/config/crd/bases/test.openstack.org_tempests.yaml +++ b/config/crd/bases/test.openstack.org_tempests.yaml @@ -109,6 +109,14 @@ spec: description: OpenStackConfigSecret is the name of the Secret containing the secure.yaml type: string + pythonTempestconfRun: + description: TempestSpec PythonTempestconf parts + properties: + create: + default: false + description: Create + type: boolean + type: object tempestRun: description: TempestSpec TempestRun parts properties: diff --git a/controllers/tempest_controller.go b/controllers/tempest_controller.go index e1b47367..faa897e2 100644 --- a/controllers/tempest_controller.go +++ b/controllers/tempest_controller.go @@ -43,6 +43,9 @@ import ( corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" k8s_errors "k8s.io/apimachinery/pkg/api/errors" + "sigs.k8s.io/controller-runtime/pkg/log" + + "strconv" ) // TempestReconciler reconciles a Tempest object @@ -87,6 +90,8 @@ func (r *TempestReconciler) GetScheme() *runtime.Scheme { // Reconcile - Tempest func (r *TempestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error) { + logging := log.FromContext(ctx) + _ = r.Log.WithValues("tempest", req.NamespacedName) // Fetch the Tempest instance @@ -103,6 +108,10 @@ func (r *TempestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re return ctrl.Result{}, err } + str := strconv.FormatBool(instance.Spec.PythonTempestconfRun.Create) + logging.Info("Hello world!") + logging.Info(str) + helper, err := helper.NewHelper( instance, r.Client, @@ -394,6 +403,8 @@ func (r *TempestReconciler) generateServiceConfigMaps( templateParameters["AllowedTests"] = instance.Spec.TempestRun.AllowedTests templateParameters["SkippedTests"] = instance.Spec.TempestRun.SkippedTests + customData["CREATE"] = strconv.FormatBool(instance.Spec.PythonTempestconfRun.Create) + cms := []util.Template{ // ScriptsConfigMap { @@ -414,5 +425,6 @@ func (r *TempestReconciler) generateServiceConfigMaps( CustomData: customData, }, } + return configmap.EnsureConfigMaps(ctx, h, instance, cms, nil) } diff --git a/pkg/tempest/job.go b/pkg/tempest/job.go index a5ecf5de..c03946b9 100644 --- a/pkg/tempest/job.go +++ b/pkg/tempest/job.go @@ -25,6 +25,12 @@ func Job( envVars["TEMPEST_CONCURRENCY"] = env.SetValue("0") } + if instance.Spec.PythonTempestconfRun.Create { + envVars["TEMPESTCONF_CREATE"] = env.SetValue("True") + } else { + envVars["TEMPESTCONF_CREATE"] = env.SetValue("False") + } + job := &batchv1.Job{ ObjectMeta: metav1.ObjectMeta{ Name: instance.Name, @@ -52,6 +58,15 @@ func Job( Args: []string{}, Env: env.MergeEnvs([]corev1.EnvVar{}, envVars), VolumeMounts: GetVolumeMounts(), + EnvFrom: []corev1.EnvFromSource{ + { + ConfigMapRef: &corev1.ConfigMapEnvSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: instance.Name + "-config-data", + }, + }, + }, + }, }, }, Volumes: GetVolumes(instance),