From 3b5aef391d0a77e65382baa422197c89bd03df0a Mon Sep 17 00:00:00 2001 From: Mykhailo Bobrovskyi Date: Tue, 25 Jun 2024 07:58:54 +0300 Subject: [PATCH] [kjobctl] Install CRDs on integration tests. --- .../kjobctl/apis/v1alpha1/volumebundle_types.go | 7 +++++-- .../crd/bases/kjobctl.x-k8s.io_volumebundles.yaml | 13 ++++++++----- .../kjobctl/test/framework/framework.go | 6 +++++- .../kjobctl/test/integration/kjobctl/suite_test.go | 4 +++- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/cmd/experimental/kjobctl/apis/v1alpha1/volumebundle_types.go b/cmd/experimental/kjobctl/apis/v1alpha1/volumebundle_types.go index 98db600011..4301fa36c1 100644 --- a/cmd/experimental/kjobctl/apis/v1alpha1/volumebundle_types.go +++ b/cmd/experimental/kjobctl/apis/v1alpha1/volumebundle_types.go @@ -22,24 +22,27 @@ 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" + // +listType=map + // +listMapKey=name EnvVars []corev1.EnvVar `json:"envVars,omitempty"` } diff --git a/cmd/experimental/kjobctl/config/crd/bases/kjobctl.x-k8s.io_volumebundles.yaml b/cmd/experimental/kjobctl/config/crd/bases/kjobctl.x-k8s.io_volumebundles.yaml index 9b3fd16506..44949b5274 100644 --- a/cmd/experimental/kjobctl/config/crd/bases/kjobctl.x-k8s.io_volumebundles.yaml +++ b/cmd/experimental/kjobctl/config/crd/bases/kjobctl.x-k8s.io_volumebundles.yaml @@ -107,6 +107,7 @@ spec: - mountPath - name type: object + maxItems: 100 minItems: 1 type: array x-kubernetes-list-map-keys: @@ -236,9 +237,9 @@ 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_]*$') ) + x-kubernetes-list-map-keys: + - name + x-kubernetes-list-type: map volumes: description: volumes is a set of volumes that will be added to all pods of the job. @@ -1995,6 +1996,7 @@ spec: required: - name type: object + maxItems: 100 minItems: 1 type: array x-kubernetes-list-map-keys: @@ -2005,8 +2007,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 diff --git a/cmd/experimental/kjobctl/test/framework/framework.go b/cmd/experimental/kjobctl/test/framework/framework.go index 4d96ad1a20..39314f00d6 100644 --- a/cmd/experimental/kjobctl/test/framework/framework.go +++ b/cmd/experimental/kjobctl/test/framework/framework.go @@ -28,6 +28,7 @@ import ( ) type Framework struct { + CRDPath string testEnv *envtest.Environment cancel context.CancelFunc } @@ -35,7 +36,10 @@ type Framework struct { 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()) diff --git a/cmd/experimental/kjobctl/test/integration/kjobctl/suite_test.go b/cmd/experimental/kjobctl/test/integration/kjobctl/suite_test.go index 3aafe854a6..540a46b0b9 100644 --- a/cmd/experimental/kjobctl/test/integration/kjobctl/suite_test.go +++ b/cmd/experimental/kjobctl/test/integration/kjobctl/suite_test.go @@ -18,6 +18,7 @@ package kjobctl import ( "context" + "path/filepath" "testing" "github.com/onsi/ginkgo/v2" @@ -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) { @@ -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) })