Skip to content

Commit

Permalink
Allow to pass a PV as storage
Browse files Browse the repository at this point in the history
This change allows to use an user managed pv to
use as results store.
We might use different strategies at the end.
  • Loading branch information
afazekas committed Oct 30, 2023
1 parent b18652f commit f70e467
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 5 deletions.
20 changes: 20 additions & 0 deletions api/bases/test.openstack.org_tempests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ spec:
spec:
description: TempestSpec defines the desired state of Tempest
properties:
PersistentVolumePath:
description: subdirectory on the volume to use
type: string
backoffLimit:
default: 0
description: BackoffLimimt allows to define the maximum number of
Expand Down Expand Up @@ -109,6 +112,23 @@ spec:
description: OpenStackConfigSecret is the name of the Secret containing
the secure.yaml
type: string
persistentVolumeClaim:
description: persistentVolumeClaimVolumeSource represents a reference
to a PersistentVolumeClaim in the same namespace. Usable for storing
test results.
properties:
claimName:
description: 'claimName is the name of a PersistentVolumeClaim
in the same namespace as the pod using this volume. More info:
https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims'
type: string
readOnly:
description: readOnly Will force the ReadOnly setting in VolumeMounts.
Default false.
type: boolean
required:
- claimName
type: object
tempestRun:
description: TempestSpec TempestRun parts
properties:
Expand Down
10 changes: 10 additions & 0 deletions api/v1beta1/tempest_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1beta1
import (
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
"github.com/openstack-k8s-operators/lib-common/modules/common/endpoint"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -62,6 +63,15 @@ type TempestSpec struct {
// Tempest Container Image URL (will be set to environmental default if empty)
ContainerImage string `json:"containerImage"`

// +kubebuilder:validation:Optional
// persistentVolumeClaimVolumeSource represents a reference to a
// PersistentVolumeClaim in the same namespace. Usable for storing test results.
PersistentVolumeClaim *corev1.PersistentVolumeClaimVolumeSource `json:"persistentVolumeClaim,omitempty"`

// +kubebuilder:validation:Optional
// subdirectory on the volume to use
PersistentVolumePath string `json:"PersistentVolumePath"`

// +kubebuilder:validation:Optional
// NodeSelector to target subset of worker nodes running this service
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
Expand Down
6 changes: 6 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.

20 changes: 20 additions & 0 deletions config/crd/bases/test.openstack.org_tempests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ spec:
spec:
description: TempestSpec defines the desired state of Tempest
properties:
PersistentVolumePath:
description: subdirectory on the volume to use
type: string
backoffLimit:
default: 0
description: BackoffLimimt allows to define the maximum number of
Expand Down Expand Up @@ -109,6 +112,23 @@ spec:
description: OpenStackConfigSecret is the name of the Secret containing
the secure.yaml
type: string
persistentVolumeClaim:
description: persistentVolumeClaimVolumeSource represents a reference
to a PersistentVolumeClaim in the same namespace. Usable for storing
test results.
properties:
claimName:
description: 'claimName is the name of a PersistentVolumeClaim
in the same namespace as the pod using this volume. More info:
https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims'
type: string
readOnly:
description: readOnly Will force the ReadOnly setting in VolumeMounts.
Default false.
type: boolean
required:
- claimName
type: object
tempestRun:
description: TempestSpec TempestRun parts
properties:
Expand Down
7 changes: 6 additions & 1 deletion pkg/tempest/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ func Job(
envVars["TEMPEST_CONCURRENCY"] = env.SetValue("0")
}

// NOTE: validate also having pv ?
// When having PV the path also should work when the home dir is different
if instance.Spec.PersistentVolumePath != "" {
envVars["TEMPEST_OUTPUTDIR"] = env.SetValue("/var/lib/tempest/output" + instance.Spec.PersistentVolumePath)
}
job := &batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Name: instance.Name,
Expand All @@ -51,7 +56,7 @@ func Job(
},
Args: []string{},
Env: env.MergeEnvs([]corev1.EnvVar{}, envVars),
VolumeMounts: GetVolumeMounts(),
VolumeMounts: GetVolumeMounts(instance),
},
},
Volumes: GetVolumes(instance),
Expand Down
27 changes: 24 additions & 3 deletions pkg/tempest/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ func GetVolumes(instance *testv1beta1.Tempest) []corev1.Volume {
var scriptsVolumeConfidentialMode int32 = 0420

//source_type := corev1.HostPathDirectoryOrCreate
return []corev1.Volume{
volumes := []corev1.Volume{
corev1.Volume{
Name: "results",
VolumeSource: corev1.VolumeSource{
PersistentVolumeClaim: instance.Spec.PersistentVolumeClaim,
},
},
{
Name: "etc-machine-id",
VolumeSource: corev1.VolumeSource{
Expand Down Expand Up @@ -72,12 +78,22 @@ func GetVolumes(instance *testv1beta1.Tempest) []corev1.Volume {
},
},
}
if instance.Spec.PersistentVolumeClaim != nil {
return volumes
} else {
return volumes[1:]
}

}

// GetVolumeMounts -
func GetVolumeMounts() []corev1.VolumeMount {
return []corev1.VolumeMount{
func GetVolumeMounts(instance *testv1beta1.Tempest) []corev1.VolumeMount {
volumes := []corev1.VolumeMount{
{
Name: "results",
MountPath: "/var/lib/tempest/output",
ReadOnly: false,
},
{
Name: "etc-machine-id",
MountPath: "/etc/machine-id",
Expand Down Expand Up @@ -111,4 +127,9 @@ func GetVolumeMounts() []corev1.VolumeMount {
SubPath: "secure.yaml",
},
}
if instance.Spec.PersistentVolumeClaim != nil {
return volumes
} else {
return volumes[1:]
}
}
2 changes: 1 addition & 1 deletion templates/tempest/bin/invoke_tempest
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -x
TEMPEST_DIR=$HOME/openshift
OPERATOR_ETC=/etc/test_operator
# NOTE: might be backed with a PV
OUTPUT_PATH=$HOME/output
OUTPUT_PATH=${TEMPEST_OUTPUTDIR:-$HOME/output}

cd "$HOME"

Expand Down

0 comments on commit f70e467

Please sign in to comment.