Skip to content

Commit

Permalink
[kjobctl] Install CRDs on integration tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbobrovskyi committed Jun 26, 2024
1 parent b45e5d5 commit 3e78356
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
5 changes: 3 additions & 2 deletions cmd/experimental/kjobctl/apis/v1alpha1/volumebundle_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,25 @@ import (
)

// VolumeBundleSpec defines the desired state of VolumeBundle
// +kubebuilder:validation:XValidation:rule="self.mountPoints.map(x, x.name in self.volumes.map(y, y.name))", message="mountPoint name must match a volume name"
// +kubebuilder:validation:XValidation:rule="self.containerVolumeMounts.all(x, x.name in self.volumes.map(y, y.name))", message="containerVolumeMount name must match a volume name"
type VolumeBundleSpec struct {
// volumes is a set of volumes that will be added to all pods of the job.
// +listType=map
// +listMapKey=name
// +kubebuilder:validation:MinItems=1
// +kubebuilder:validation:MaxItems=100
Volumes []corev1.Volume `json:"volumes"`

// containerVolumeMounts is a list of locations in each container of a pod where the volumes will be mounted.
// +listType=map
// +listMapKey=mountPath
// +kubebuilder:validation:MinItems=1
// +kubebuilder:validation:MaxItems=100
ContainerVolumeMounts []corev1.VolumeMount `json:"containerVolumeMounts"`

// envVars are environment variables that refer to absolute paths in the container filesystem.
// These key/value pairs will be available in containers as environment variables.
// +optional
// +kubebuilder:validation:XValidation:rule="self.all(x, x.name.matches('^[A-Za-z_][A-Za-z0-9_]*$') )", message="invalid environment variable name"
EnvVars []corev1.EnvVar `json:"envVars,omitempty"`
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ spec:
- mountPath
- name
type: object
maxItems: 100
minItems: 1
type: array
x-kubernetes-list-map-keys:
Expand Down Expand Up @@ -236,9 +237,6 @@ spec:
- name
type: object
type: array
x-kubernetes-validations:
- message: invalid environment variable name
rule: self.all(x, x.name.matches('^[A-Za-z_][A-Za-z0-9_]*$') )
volumes:
description: volumes is a set of volumes that will be added to all
pods of the job.
Expand Down Expand Up @@ -1995,6 +1993,7 @@ spec:
required:
- name
type: object
maxItems: 100
minItems: 1
type: array
x-kubernetes-list-map-keys:
Expand All @@ -2005,8 +2004,9 @@ spec:
- volumes
type: object
x-kubernetes-validations:
- message: mountPoint name must match a volume name
rule: self.mountPoints.map(x, x.name in self.volumes.map(y, y.name))
- message: containerVolumeMount name must match a volume name
rule: self.containerVolumeMounts.all(x, x.name in self.volumes.map(y,
y.name))
type: object
served: true
storage: true
6 changes: 5 additions & 1 deletion cmd/experimental/kjobctl/test/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ import (
)

type Framework struct {
CRDPath string
testEnv *envtest.Environment
cancel context.CancelFunc
}

func (f *Framework) Init() *rest.Config {
ginkgo.By("bootstrapping test environment")

f.testEnv = &envtest.Environment{}
f.testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{f.CRDPath},
ErrorIfCRDPathMissing: true,
}
cfg, err := f.testEnv.Start()

gomega.ExpectWithOffset(1, err).NotTo(gomega.HaveOccurred())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package kjobctl

import (
"context"
"path/filepath"
"testing"

"github.com/onsi/ginkgo/v2"
Expand All @@ -33,6 +34,7 @@ var (
k8sClient client.Client
ctx context.Context
fwk *framework.Framework
crdPath = filepath.Join("..", "..", "..", "config", "crd", "bases")
)

func TestKjobctl(t *testing.T) {
Expand All @@ -41,7 +43,7 @@ func TestKjobctl(t *testing.T) {
}

var _ = ginkgo.BeforeSuite(func() {
fwk = &framework.Framework{}
fwk = &framework.Framework{CRDPath: crdPath}
cfg = fwk.Init()
ctx, k8sClient = fwk.SetupClient(cfg)
})
Expand Down

0 comments on commit 3e78356

Please sign in to comment.