diff --git a/api/bases/test.openstack.org_ansibletests.yaml b/api/bases/test.openstack.org_ansibletests.yaml index 8ec26de0..fef0db9b 100644 --- a/api/bases/test.openstack.org_ansibletests.yaml +++ b/api/bases/test.openstack.org_ansibletests.yaml @@ -87,21 +87,21 @@ spec: description: Extra configmaps for mounting in the pod. items: properties: - Name: - description: The name of an existing config map for mounting. - type: string mountPath: description: Path within the container at which the volume should be mounted. type: string + name: + description: The name of an existing config map for mounting. + type: string subPath: default: "" description: Config map subpath for mounting, defaults to configmap root. type: string required: - - Name - mountPath + - name - subPath type: object type: array @@ -166,21 +166,21 @@ spec: description: Extra configmaps for mounting in the pod items: properties: - Name: - description: The name of an existing config map for mounting. - type: string mountPath: description: Path within the container at which the volume should be mounted. type: string + name: + description: The name of an existing config map for mounting. + type: string subPath: default: "" description: Config map subpath for mounting, defaults to configmap root. type: string required: - - Name - mountPath + - name - subPath type: object type: array diff --git a/api/bases/test.openstack.org_tempests.yaml b/api/bases/test.openstack.org_tempests.yaml index bc75eac8..1748cb9c 100644 --- a/api/bases/test.openstack.org_tempests.yaml +++ b/api/bases/test.openstack.org_tempests.yaml @@ -73,6 +73,28 @@ spec: corresponding Tempest CR is deleted. This allows the user to debug any potential troubles with `oc rsh`. type: boolean + extraConfigmapsMounts: + description: Extra configmaps for mounting in the pod. + items: + properties: + mountPath: + description: Path within the container at which the volume should + be mounted. + type: string + name: + description: The name of an existing config map for mounting. + type: string + subPath: + default: "" + description: Config map subpath for mounting, defaults to configmap + root. + type: string + required: + - mountPath + - name + - subPath + type: object + type: array networkAttachments: description: NetworkAttachments is a list of NetworkAttachment resource names to expose the services to the given network diff --git a/api/v1beta1/ansibletest_types.go b/api/v1beta1/ansibletest_types.go index fb16c780..ed2ae02d 100644 --- a/api/v1beta1/ansibletest_types.go +++ b/api/v1beta1/ansibletest_types.go @@ -24,30 +24,12 @@ import ( // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. -type extraConfigmapsMounts struct { - // +operator-sdk:csv:customresourcedefinitions:type=spec - // +kubebuilder:validation:Required - // The name of an existing config map for mounting. - Name string `json:"Name"` - - // +operator-sdk:csv:customresourcedefinitions:type=spec - // +kubebuilder:validation:Required - // Path within the container at which the volume should be mounted. - MountPath string `json:"mountPath"` - - // +operator-sdk:csv:customresourcedefinitions:type=spec - // +kubebuilder:validation:optional - // +kubebuilder:default="" - // Config map subpath for mounting, defaults to configmap root. - SubPath string `json:"subPath"` -} - // AnsibleTestSpec defines the desired state of AnsibleTest type AnsibleTestSpec struct { // +operator-sdk:csv:customresourcedefinitions:type=spec // +kubebuilder:validation:Optional // Extra configmaps for mounting in the pod. - ExtraMounts []extraConfigmapsMounts `json:"extraMounts"` + ExtraMounts []extraConfigmapsMounts `json:"extraMounts,omitempty"` // +operator-sdk:csv:customresourcedefinitions:type=spec // +kubebuilder:validation:Required @@ -146,7 +128,7 @@ type AnsibleTestWorkflowSpec struct { // +operator-sdk:csv:customresourcedefinitions:type=spec // +kubebuilder:validation:Optional // Extra configmaps for mounting in the pod - ExtraMounts []extraConfigmapsMounts `json:"extraMounts"` + ExtraMounts []extraConfigmapsMounts `json:"extraMounts,omitempty"` // +operator-sdk:csv:customresourcedefinitions:type=spec // +kubebuilder:validation:Required diff --git a/api/v1beta1/common.go b/api/v1beta1/common.go new file mode 100644 index 00000000..86ddefbf --- /dev/null +++ b/api/v1beta1/common.go @@ -0,0 +1,36 @@ +/* +Copyright 2023. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1beta1 + + +type extraConfigmapsMounts struct { + // +operator-sdk:csv:customresourcedefinitions:type=spec + // +kubebuilder:validation:Required + // The name of an existing config map for mounting. + Name string `json:"name"` + + // +operator-sdk:csv:customresourcedefinitions:type=spec + // +kubebuilder:validation:Required + // Path within the container at which the volume should be mounted. + MountPath string `json:"mountPath"` + + // +operator-sdk:csv:customresourcedefinitions:type=spec + // +kubebuilder:validation:optional + // +kubebuilder:default="" + // Config map subpath for mounting, defaults to configmap root. + SubPath string `json:"subPath"` +} \ No newline at end of file diff --git a/api/v1beta1/tempest_types.go b/api/v1beta1/tempest_types.go index 43873e92..fc534263 100644 --- a/api/v1beta1/tempest_types.go +++ b/api/v1beta1/tempest_types.go @@ -192,7 +192,7 @@ type TempestRunSpec struct { ExternalPlugin []ExternalPluginType `json:"externalPlugin,omitempty"` // +kubebuilder:validation:Optional - // +operator-sdk:csv:customresourcedefinitions:type=spec + // +operator-sdk:csv:customresourcedefinitions:type=spec // A list URLs that point to RPMs that should be downloaded and installed // inside the tempest test pod. ExtraRPMs []string `json:"extraRPMs,omitempty"` @@ -370,6 +370,10 @@ type TempestconfRunSpec struct { // TempestSpec - configuration of execution of tempest. For specific configuration // of tempest see TempestRunSpec and for discover-tempest-config see TempestconfRunSpec. type TempestSpec struct { + // +operator-sdk:csv:customresourcedefinitions:type=spec + // +kubebuilder:validation:Optional + // Extra configmaps for mounting in the pod. + ExtraConfigmapsMounts []extraConfigmapsMounts `json:"extraConfigmapsMounts,omitempty"` // +kubebuilder:validation:Optional // +operator-sdk:csv:customresourcedefinitions:type=spec diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 3a7d3a52..a1073431 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -493,6 +493,11 @@ func (in *TempestRunSpec) DeepCopy() *TempestRunSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TempestSpec) DeepCopyInto(out *TempestSpec) { *out = *in + if in.ExtraConfigmapsMounts != nil { + in, out := &in.ExtraConfigmapsMounts, &out.ExtraConfigmapsMounts + *out = make([]extraConfigmapsMounts, len(*in)) + copy(*out, *in) + } if in.NodeSelector != nil { in, out := &in.NodeSelector, &out.NodeSelector *out = make(map[string]string, len(*in)) diff --git a/config/crd/bases/test.openstack.org_ansibletests.yaml b/config/crd/bases/test.openstack.org_ansibletests.yaml index 8ec26de0..fef0db9b 100644 --- a/config/crd/bases/test.openstack.org_ansibletests.yaml +++ b/config/crd/bases/test.openstack.org_ansibletests.yaml @@ -87,21 +87,21 @@ spec: description: Extra configmaps for mounting in the pod. items: properties: - Name: - description: The name of an existing config map for mounting. - type: string mountPath: description: Path within the container at which the volume should be mounted. type: string + name: + description: The name of an existing config map for mounting. + type: string subPath: default: "" description: Config map subpath for mounting, defaults to configmap root. type: string required: - - Name - mountPath + - name - subPath type: object type: array @@ -166,21 +166,21 @@ spec: description: Extra configmaps for mounting in the pod items: properties: - Name: - description: The name of an existing config map for mounting. - type: string mountPath: description: Path within the container at which the volume should be mounted. type: string + name: + description: The name of an existing config map for mounting. + type: string subPath: default: "" description: Config map subpath for mounting, defaults to configmap root. type: string required: - - Name - mountPath + - name - subPath type: object type: array diff --git a/config/crd/bases/test.openstack.org_tempests.yaml b/config/crd/bases/test.openstack.org_tempests.yaml index bc75eac8..1748cb9c 100644 --- a/config/crd/bases/test.openstack.org_tempests.yaml +++ b/config/crd/bases/test.openstack.org_tempests.yaml @@ -73,6 +73,28 @@ spec: corresponding Tempest CR is deleted. This allows the user to debug any potential troubles with `oc rsh`. type: boolean + extraConfigmapsMounts: + description: Extra configmaps for mounting in the pod. + items: + properties: + mountPath: + description: Path within the container at which the volume should + be mounted. + type: string + name: + description: The name of an existing config map for mounting. + type: string + subPath: + default: "" + description: Config map subpath for mounting, defaults to configmap + root. + type: string + required: + - mountPath + - name + - subPath + type: object + type: array networkAttachments: description: NetworkAttachments is a list of NetworkAttachment resource names to expose the services to the given network diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 3605bcf1..f2ce75a6 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -5,3 +5,4 @@ kind: Kustomization images: - name: controller newName: quay.io/openstack-k8s-operators/test-operator + newTag: latest diff --git a/config/manifests/bases/test-operator.clusterserviceversion.yaml b/config/manifests/bases/test-operator.clusterserviceversion.yaml index c158dcb0..148cfd2b 100644 --- a/config/manifests/bases/test-operator.clusterserviceversion.yaml +++ b/config/manifests/bases/test-operator.clusterserviceversion.yaml @@ -121,6 +121,18 @@ spec: This allows the user to debug any potential troubles with `oc rsh`. displayName: Debug path: debug + - description: Extra configmaps for mounting in the pod. + displayName: Extra Configmaps Mounts + path: extraConfigmapsMounts + - description: Path within the container at which the volume should be mounted. + displayName: Mount Path + path: extraConfigmapsMounts[0].mountPath + - description: The name of an existing config map for mounting. + displayName: Name + path: extraConfigmapsMounts[0].name + - description: Config map subpath for mounting, defaults to configmap root. + displayName: Sub Path + path: extraConfigmapsMounts[0].subPath - description: NetworkAttachments is a list of NetworkAttachment resource names to expose the services to the given network displayName: Network Attachments diff --git a/pkg/tempest/job.go b/pkg/tempest/job.go index 93980e09..bbea3639 100644 --- a/pkg/tempest/job.go +++ b/pkg/tempest/job.go @@ -58,7 +58,7 @@ func Job( Image: instance.Spec.ContainerImage, Args: []string{}, Env: env.MergeEnvs([]corev1.EnvVar{}, envVars), - VolumeMounts: GetVolumeMounts(mountCerts, mountSSHKey), + VolumeMounts: GetVolumeMounts(mountCerts, mountSSHKey, instance), SecurityContext: &corev1.SecurityContext{ Capabilities: &corev1.Capabilities{ Add: []corev1.Capability{"CAP_AUDIT_WRITE"}, diff --git a/pkg/tempest/volumes.go b/pkg/tempest/volumes.go index 083396ce..917c2c05 100644 --- a/pkg/tempest/volumes.go +++ b/pkg/tempest/volumes.go @@ -113,11 +113,27 @@ func GetVolumes( volumes = append(volumes, sshKeyVolume) } + for _, vol := range instance.Spec.ExtraConfigmapsMounts { + extraVol := corev1.Volume{ + Name: vol.Name, + VolumeSource: corev1.VolumeSource{ + ConfigMap: &corev1.ConfigMapVolumeSource{ + DefaultMode: &scriptsVolumeDefaultMode, + LocalObjectReference: corev1.LocalObjectReference{ + Name: vol.Name, + }, + }, + }, + } + + volumes = append(volumes, extraVol) + } + return volumes } // GetVolumeMounts - -func GetVolumeMounts(mountCerts bool, mountSSHKey bool) []corev1.VolumeMount { +func GetVolumeMounts(mountCerts bool, mountSSHKey bool, instance *testv1beta1.Tempest) []corev1.VolumeMount { volumeMounts := []corev1.VolumeMount{ { Name: "etc-machine-id", @@ -180,5 +196,17 @@ func GetVolumeMounts(mountCerts bool, mountSSHKey bool) []corev1.VolumeMount { volumeMounts = append(volumeMounts, sshKeyMount) } + for _, vol := range instance.Spec.ExtraConfigmapsMounts { + + extraMounts := corev1.VolumeMount{ + Name: vol.Name, + MountPath: vol.MountPath, + SubPath: vol.SubPath, + ReadOnly: true, + } + + volumeMounts = append(volumeMounts, extraMounts) + } + return volumeMounts }