Skip to content

tests: add descheduler e2e tests and new e2e tests framework #1175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions images/virtualization-artifact/pkg/builder/cvi/cvi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Copyright 2025 Flant JSC

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 cvi

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/deckhouse/virtualization/api/core/v1alpha2"
)

func New(options ...Option) *v1alpha2.ClusterVirtualImage {
cvi := NewEmpty("")
ApplyOptions(cvi, options...)
return cvi
}

func ApplyOptions(cvi *v1alpha2.ClusterVirtualImage, opts ...Option) {
if cvi == nil {
return
}
for _, opt := range opts {
opt(cvi)
}
}

func NewEmpty(name string) *v1alpha2.ClusterVirtualImage {
return &v1alpha2.ClusterVirtualImage{
TypeMeta: metav1.TypeMeta{
APIVersion: v1alpha2.SchemeGroupVersion.String(),
Kind: v1alpha2.ClusterVirtualImageKind,
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
}
}
93 changes: 93 additions & 0 deletions images/virtualization-artifact/pkg/builder/cvi/option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
Copyright 2025 Flant JSC

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 cvi

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/deckhouse/virtualization-controller/pkg/builder/meta"
"github.com/deckhouse/virtualization/api/core/v1alpha2"
)

type Option func(cvi *v1alpha2.ClusterVirtualImage)

var (
WithName = meta.WithName[*v1alpha2.ClusterVirtualImage]
WithGenerateName = meta.WithGenerateName[*v1alpha2.ClusterVirtualImage]
WithLabel = meta.WithLabel[*v1alpha2.ClusterVirtualImage]
WithLabels = meta.WithLabels[*v1alpha2.ClusterVirtualImage]
WithAnnotation = meta.WithAnnotation[*v1alpha2.ClusterVirtualImage]
WithAnnotations = meta.WithAnnotations[*v1alpha2.ClusterVirtualImage]
WithFinalizer = meta.WithFinalizer[*v1alpha2.ClusterVirtualImage]
)

func WithDataSourceHTTP(url string, checksum *v1alpha2.Checksum, caBundle []byte) Option {
return func(cvi *v1alpha2.ClusterVirtualImage) {
cvi.Spec.DataSource = v1alpha2.ClusterVirtualImageDataSource{
Type: v1alpha2.DataSourceTypeHTTP,
HTTP: &v1alpha2.DataSourceHTTP{
URL: url,
Checksum: checksum,
CABundle: caBundle,
},
}
}
}

func WithDataSourceContainerImage(image string, imagePullSecret v1alpha2.ImagePullSecret, caBundle []byte) Option {
return func(cvi *v1alpha2.ClusterVirtualImage) {
cvi.Spec.DataSource = v1alpha2.ClusterVirtualImageDataSource{
Type: v1alpha2.DataSourceTypeContainerImage,
ContainerImage: &v1alpha2.ClusterVirtualImageContainerImage{
Image: image,
ImagePullSecret: imagePullSecret,
CABundle: caBundle,
},
}
}
}

func WithDataSourceObjectRef(kind v1alpha2.ClusterVirtualImageObjectRefKind, name, namespace string) Option {
return func(cvi *v1alpha2.ClusterVirtualImage) {
cvi.Spec.DataSource = v1alpha2.ClusterVirtualImageDataSource{
Type: v1alpha2.DataSourceTypeObjectRef,
ObjectRef: &v1alpha2.ClusterVirtualImageObjectRef{
Kind: kind,
Name: name,
Namespace: namespace,
},
}
}
}

func WithDatasource(datasource v1alpha2.ClusterVirtualImageDataSource) func(cvi *v1alpha2.ClusterVirtualImage) {
return func(cvi *v1alpha2.ClusterVirtualImage) {
cvi.Spec.DataSource = datasource
}
}

func WithPhase(phase v1alpha2.ImagePhase) func(cvi *v1alpha2.ClusterVirtualImage) {
return func(cvi *v1alpha2.ClusterVirtualImage) {
cvi.Status.Phase = phase
}
}

func WithCondition(condition metav1.Condition) func(cvi *v1alpha2.ClusterVirtualImage) {
return func(cvi *v1alpha2.ClusterVirtualImage) {
cvi.Status.Conditions = append(cvi.Status.Conditions, condition)
}
}
112 changes: 112 additions & 0 deletions images/virtualization-artifact/pkg/builder/vd/option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
Copyright 2025 Flant JSC

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 vd

import (
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/utils/ptr"

"github.com/deckhouse/virtualization-controller/pkg/builder/meta"
"github.com/deckhouse/virtualization/api/core/v1alpha2"
)

type Option func(vmop *v1alpha2.VirtualDisk)

var (
WithName = meta.WithName[*v1alpha2.VirtualDisk]
WithNamespace = meta.WithNamespace[*v1alpha2.VirtualDisk]
WithGenerateName = meta.WithGenerateName[*v1alpha2.VirtualDisk]
WithLabel = meta.WithLabel[*v1alpha2.VirtualDisk]
WithLabels = meta.WithLabels[*v1alpha2.VirtualDisk]
WithAnnotation = meta.WithAnnotation[*v1alpha2.VirtualDisk]
WithAnnotations = meta.WithAnnotations[*v1alpha2.VirtualDisk]
WithFinalizer = meta.WithFinalizer[*v1alpha2.VirtualDisk]
)

func WithDatasource(datasource *v1alpha2.VirtualDiskDataSource) func(vd *v1alpha2.VirtualDisk) {
return func(vd *v1alpha2.VirtualDisk) {
vd.Spec.DataSource = datasource
}
}
func WithDataSourceHTTP(url string, checksum *v1alpha2.Checksum, caBundle []byte) Option {
return func(vd *v1alpha2.VirtualDisk) {
vd.Spec.DataSource = &v1alpha2.VirtualDiskDataSource{
Type: v1alpha2.DataSourceTypeHTTP,
HTTP: &v1alpha2.DataSourceHTTP{
URL: url,
Checksum: checksum,
CABundle: caBundle,
},
}
}
}

func WithDataSourceContainerImage(image, imagePullSecretName string, caBundle []byte) Option {
return func(vd *v1alpha2.VirtualDisk) {
vd.Spec.DataSource = &v1alpha2.VirtualDiskDataSource{
Type: v1alpha2.DataSourceTypeContainerImage,
ContainerImage: &v1alpha2.VirtualDiskContainerImage{
Image: image,
ImagePullSecret: v1alpha2.ImagePullSecretName{
Name: imagePullSecretName,
},
CABundle: caBundle,
},
}
}
}

func WithDataSourceObjectRef(kind v1alpha2.VirtualDiskObjectRefKind, name string) Option {
return func(vd *v1alpha2.VirtualDisk) {
vd.Spec.DataSource = &v1alpha2.VirtualDiskDataSource{
Type: v1alpha2.DataSourceTypeObjectRef,
ObjectRef: &v1alpha2.VirtualDiskObjectRef{
Kind: kind,
Name: name,
},
}
}
}

func WithDataSourceObjectRefFromCVI(cvi *v1alpha2.ClusterVirtualImage) Option {
return WithDataSourceObjectRef(v1alpha2.VirtualDiskObjectRefKindClusterVirtualImage, cvi.Name)
}

func WithDataSourceObjectRefFromVI(vi *v1alpha2.VirtualImage) Option {
return WithDataSourceObjectRef(v1alpha2.VirtualDiskObjectRefKindVirtualImage, vi.Name)
}

func WithPersistentVolumeClaim(storageClass *string, size *resource.Quantity) Option {
return func(vd *v1alpha2.VirtualDisk) {
vd.Spec.PersistentVolumeClaim = v1alpha2.VirtualDiskPersistentVolumeClaim{
StorageClass: storageClass,
Size: size,
}
}
}

func WithStorageClass(storageClass string) Option {
return func(vd *v1alpha2.VirtualDisk) {
vd.Spec.PersistentVolumeClaim.StorageClass = ptr.To(storageClass)
}
}

func WithSize(size *resource.Quantity) Option {
return func(vd *v1alpha2.VirtualDisk) {
vd.Spec.PersistentVolumeClaim.Size = size
}
}
51 changes: 51 additions & 0 deletions images/virtualization-artifact/pkg/builder/vd/vd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright 2025 Flant JSC

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 vd

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/deckhouse/virtualization/api/core/v1alpha2"
)

func New(options ...Option) *v1alpha2.VirtualDisk {
vd := NewEmpty("", "")
ApplyOptions(vd, options...)
return vd
}

func ApplyOptions(vd *v1alpha2.VirtualDisk, opts ...Option) {
if vd == nil {
return
}
for _, opt := range opts {
opt(vd)
}
}

func NewEmpty(name, namespace string) *v1alpha2.VirtualDisk {
return &v1alpha2.VirtualDisk{
TypeMeta: metav1.TypeMeta{
APIVersion: v1alpha2.SchemeGroupVersion.String(),
Kind: v1alpha2.VirtualDiskKind,
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
}
}
37 changes: 37 additions & 0 deletions images/virtualization-artifact/pkg/builder/vm/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,40 @@ func WithMemory(size resource.Quantity) Option {
vm.Spec.Memory.Size = size
}
}

func WithDisks(disks ...*v1alpha2.VirtualDisk) Option {
return func(vm *v1alpha2.VirtualMachine) {
blockDeviceRefs := make([]v1alpha2.BlockDeviceSpecRef, 0, len(disks))
for _, disk := range disks {
blockDeviceRefs = append(blockDeviceRefs, v1alpha2.BlockDeviceSpecRef{
Kind: v1alpha2.VirtualDiskKind,
Name: disk.Name,
})
}
vm.Spec.BlockDeviceRefs = append(vm.Spec.BlockDeviceRefs, blockDeviceRefs...)
}
}

func WithBlockDeviceRefs(refs ...v1alpha2.BlockDeviceSpecRef) Option {
return func(vm *v1alpha2.VirtualMachine) {
vm.Spec.BlockDeviceRefs = append(vm.Spec.BlockDeviceRefs, refs...)
}
}

func WithNodeSelector(nodeSelector map[string]string) Option {
return func(vm *v1alpha2.VirtualMachine) {
vm.Spec.NodeSelector = nodeSelector
}
}

func WithLiveMigrationPolicy(liveMigrationPolicy v1alpha2.LiveMigrationPolicy) Option {
return func(vm *v1alpha2.VirtualMachine) {
vm.Spec.LiveMigrationPolicy = liveMigrationPolicy
}
}

func WithVirtualMachineClass(class string) Option {
return func(vm *v1alpha2.VirtualMachine) {
vm.Spec.VirtualMachineClassName = class
}
}
22 changes: 22 additions & 0 deletions tests/e2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (

yamlv3 "gopkg.in/yaml.v3"
storagev1 "k8s.io/api/storage/v1"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/rest"

gt "github.com/deckhouse/virtualization/tests/e2e/git"
kc "github.com/deckhouse/virtualization/tests/e2e/kubectl"
Expand Down Expand Up @@ -170,6 +172,26 @@ type ClusterTransport struct {
InsecureTls bool `yaml:"insecureTls"`
}

func (c ClusterTransport) RestConfig() (*rest.Config, error) {
configFlags := genericclioptions.ConfigFlags{}
if c.KubeConfig != "" {
configFlags.KubeConfig = &c.KubeConfig
}
if c.Token != "" {
configFlags.BearerToken = &c.Token
}
if c.InsecureTls {
configFlags.Insecure = &c.InsecureTls
}
if c.CertificateAuthority != "" {
configFlags.CAFile = &c.CertificateAuthority
}
if c.Endpoint != "" {
configFlags.APIServer = &c.Endpoint
}
return configFlags.ToRESTConfig()
}

type DisksConf struct {
UploadHelperImage string `yaml:"uploadHelperImage"`
CviTestDataDir string `yaml:"cviTestDataDir"`
Expand Down
Loading
Loading