Skip to content

Commit

Permalink
Allow extra config maps mount in tempest
Browse files Browse the repository at this point in the history
Allow adding extra config maps for tempest runs similarly to ansible
controller.

Resolves: https://issues.redhat.com/browse/OSPRH-8170
  • Loading branch information
eshulman2 authored and lpiwowar committed Jul 17, 2024
1 parent c613952 commit 34b77df
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 39 deletions.
16 changes: 8 additions & 8 deletions api/bases/test.openstack.org_ansibletests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions api/bases/test.openstack.org_tempests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 2 additions & 20 deletions api/v1beta1/ansibletest_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions api/v1beta1/common.go
Original file line number Diff line number Diff line change
@@ -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"`
}
6 changes: 5 additions & 1 deletion api/v1beta1/tempest_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions config/crd/bases/test.openstack.org_ansibletests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions config/crd/bases/test.openstack.org_tempests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ kind: Kustomization
images:
- name: controller
newName: quay.io/openstack-k8s-operators/test-operator
newTag: latest
12 changes: 12 additions & 0 deletions config/manifests/bases/test-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/tempest/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
30 changes: 29 additions & 1 deletion pkg/tempest/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
}

0 comments on commit 34b77df

Please sign in to comment.