Skip to content
11 changes: 11 additions & 0 deletions images/virtualization-artifact/pkg/builder/cvi/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ func WithDatasource(datasource v1alpha2.ClusterVirtualImageDataSource) func(cvi
}
}

func WithDataSourceHTTPWithOnlyURL(url string) Option {
return func(cvi *v1alpha2.ClusterVirtualImage) {
cvi.Spec.DataSource = v1alpha2.ClusterVirtualImageDataSource{
Type: v1alpha2.DataSourceTypeHTTP,
HTTP: &v1alpha2.DataSourceHTTP{
URL: url,
},
}
}
}

func WithPhase(phase v1alpha2.ImagePhase) func(cvi *v1alpha2.ClusterVirtualImage) {
return func(cvi *v1alpha2.ClusterVirtualImage) {
cvi.Status.Phase = phase
Expand Down
11 changes: 11 additions & 0 deletions images/virtualization-artifact/pkg/builder/vd/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ func WithDataSourceHTTP(url string, checksum *v1alpha2.Checksum, caBundle []byte
}
}

func WithDataSourceHTTPWithOnlyURL(url string) Option {
return func(vd *v1alpha2.VirtualDisk) {
vd.Spec.DataSource = &v1alpha2.VirtualDiskDataSource{
Type: v1alpha2.DataSourceTypeHTTP,
HTTP: &v1alpha2.DataSourceHTTP{
URL: url,
},
}
}
}

func WithDataSourceContainerImage(image, imagePullSecretName string, caBundle []byte) Option {
return func(vd *v1alpha2.VirtualDisk) {
vd.Spec.DataSource = &v1alpha2.VirtualDiskDataSource{
Expand Down
36 changes: 36 additions & 0 deletions images/virtualization-artifact/pkg/builder/vi/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,39 @@ func WithCDROM(cdrom bool) func(vi *v1alpha2.VirtualImage) {
vi.Status.CDROM = cdrom
}
}

func WithStorageType(storageType *v1alpha2.StorageType) func(vi *v1alpha2.VirtualImage) {
return func(vi *v1alpha2.VirtualImage) {
vi.Spec.Storage = *storageType
}
}

func WithDatasource(datasource v1alpha2.VirtualImageDataSource) func(vd *v1alpha2.VirtualImage) {
return func(vi *v1alpha2.VirtualImage) {
vi.Spec.DataSource = datasource
}
}

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

func WithDataSourceHTTPWithOnlyURL(url string) Option {
return func(vi *v1alpha2.VirtualImage) {
vi.Spec.DataSource = v1alpha2.VirtualImageDataSource{
Type: v1alpha2.DataSourceTypeHTTP,
HTTP: &v1alpha2.DataSourceHTTP{
URL: url,
},
}
}
}
6 changes: 6 additions & 0 deletions images/virtualization-artifact/pkg/builder/vm/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,9 @@ func WithVirtualMachineClass(class string) Option {
vm.Spec.VirtualMachineClassName = class
}
}

func WithProvisioning(provisioning *v1alpha2.Provisioning) Option {
return func(vm *v1alpha2.VirtualMachine) {
vm.Spec.Provisioning = provisioning
}
}
42 changes: 42 additions & 0 deletions images/virtualization-artifact/pkg/builder/vmbda/option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
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 vmbda

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

type Option func(vd *v1alpha2.VirtualMachineBlockDeviceAttachment)

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

func WithBlockDeviceRef(bdRef v1alpha2.VMBDAObjectRef) func(vmbda *v1alpha2.VirtualMachineBlockDeviceAttachment) {
return func(vmbda *v1alpha2.VirtualMachineBlockDeviceAttachment) {
vmbda.Spec.BlockDeviceRef = bdRef
}
}

func WithVMName(vmName string) func(vmbda *v1alpha2.VirtualMachineBlockDeviceAttachment) {
return func(vmbda *v1alpha2.VirtualMachineBlockDeviceAttachment) {
vmbda.Spec.VirtualMachineName = vmName
}
}
48 changes: 48 additions & 0 deletions images/virtualization-artifact/pkg/builder/vmbda/vmbda.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
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 vmbda

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

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

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

func ApplyOptions(vmbda *v1alpha2.VirtualMachineBlockDeviceAttachment, opts []Option) {
if vmbda == nil {
return
}
for _, opt := range opts {
opt(vmbda)
}
}

func NewEmpty(name, namespace string) *v1alpha2.VirtualMachineBlockDeviceAttachment {
return &v1alpha2.VirtualMachineBlockDeviceAttachment{
TypeMeta: metav1.TypeMeta{
APIVersion: v1alpha2.SchemeGroupVersion.String(),
Kind: v1alpha2.VirtualMachineBlockDeviceAttachmentKind,
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
}
}
6 changes: 6 additions & 0 deletions images/virtualization-artifact/pkg/builder/vmop/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,9 @@ func WithForce(force *bool) Option {
vmop.Spec.Force = force
}
}

func WithRestoreSpec(restoreSpec *v1alpha2.VirtualMachineOperationRestoreSpec) Option {
return func(vmop *v1alpha2.VirtualMachineOperation) {
vmop.Spec.Restore = restoreSpec
}
}
53 changes: 53 additions & 0 deletions images/virtualization-artifact/pkg/builder/vmsnapshot/option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
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 vmsnapshot

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

type Option func(vmop *v1alpha2.VirtualMachineSnapshot)

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

func WithRequiredConsistency(required bool) Option {
return func(vmop *v1alpha2.VirtualMachineSnapshot) {
vmop.Spec.RequiredConsistency = required
}
}

func WithVM(vmName string) Option {
return func(vmop *v1alpha2.VirtualMachineSnapshot) {
vmop.Spec.VirtualMachineName = vmName
}
}

func WithKeepIPAddress(keepIPAddress v1alpha2.KeepIPAddress) Option {
return func(vmop *v1alpha2.VirtualMachineSnapshot) {
vmop.Spec.KeepIPAddress = keepIPAddress
}
}
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 vmsnapshot

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

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

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

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

func NewEmpty(name, namespace string) *v1alpha2.VirtualMachineSnapshot {
return &v1alpha2.VirtualMachineSnapshot{
TypeMeta: metav1.TypeMeta{
APIVersion: v1alpha2.SchemeGroupVersion.String(),
Kind: v1alpha2.VirtualMachineSnapshotKind,
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
}
}
20 changes: 19 additions & 1 deletion tests/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import (
"github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/deckhouse/virtualization/tests/e2e/config"
)

const (
Expand All @@ -40,6 +43,7 @@ type Framework struct {

namespace *corev1.Namespace
namespacesToDelete []string
resourcesToDelete []client.Object
}

func NewFramework(namespacePrefix string) *Framework {
Expand Down Expand Up @@ -73,12 +77,22 @@ func (f *Framework) Before() {
gomega.Expect(err).NotTo(gomega.HaveOccurred())
ginkgo.By(fmt.Sprintf("Created namespace %s", ns.Name))
f.namespace = ns
f.AddNamespaceToDelete(ns.Name)
}
}

func (f *Framework) After() {
ginkgo.GinkgoHelper()

if !config.IsCleanUpNeeded() {
return
}

for _, resource := range f.resourcesToDelete {
ginkgo.By(fmt.Sprintf("Delete resource %s", resource.GetName()))
err := f.client.Delete(context.Background(), resource)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}

for _, ns := range f.namespacesToDelete {
ginkgo.By(fmt.Sprintf("Delete namespace %s", ns))
err := f.KubeClient().CoreV1().Namespaces().Delete(context.Background(), ns, metav1.DeleteOptions{})
Expand Down Expand Up @@ -118,3 +132,7 @@ func (f *Framework) Namespace() *corev1.Namespace {
func (f *Framework) AddNamespaceToDelete(name string) {
f.namespacesToDelete = append(f.namespacesToDelete, name)
}

func (f *Framework) AddResourceToDelete(obj client.Object) {
f.resourcesToDelete = append(f.resourcesToDelete, obj)
}
34 changes: 34 additions & 0 deletions tests/e2e/virtual_machine_restore_operation_test/cloud_init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
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 virtualmachinerestoreoperationtest

const cloudInit = `#cloud-config
users:
- name: cloud
passwd: $6$rounds=4096$vln/.aPHBOI7BMYR$bBMkqQvuGs5Gyd/1H5DP4m9HjQSy.kgrxpaGEHwkX7KEFV8BS.HZWPitAtZ2Vd8ZqIZRqmlykRCagTgPejt1i.
shell: /bin/bash
sudo: ALL=(ALL) NOPASSWD:ALL
chpasswd: { expire: False }
lock_passwd: false
ssh_authorized_keys:
- ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFxcXHmwaGnJ8scJaEN5RzklBPZpVSic4GdaAsKjQoeA [email protected]
runcmd:
- [bash, -c, "apt update"]
- [bash, -c, "apt install qemu-guest-agent -y"]
- [bash, -c, "systemctl enable qemu-guest-agent"]
- [bash, -c, "systemctl start qemu-guest-agent"]`
Loading
Loading