Skip to content

Commit 1607b71

Browse files
author
Valeriy Khorunzhin
committed
tmp
Signed-off-by: Valeriy Khorunzhin <[email protected]>
1 parent fb289ee commit 1607b71

File tree

11 files changed

+837
-4
lines changed

11 files changed

+837
-4
lines changed

images/virtualization-artifact/pkg/builder/cvi/option.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ func WithDatasource(datasource v1alpha2.ClusterVirtualImageDataSource) func(cvi
8080
}
8181
}
8282

83+
func WithDataSourceHTTPWithOnlyURL(url string) Option {
84+
return func(cvi *v1alpha2.ClusterVirtualImage) {
85+
cvi.Spec.DataSource = v1alpha2.ClusterVirtualImageDataSource{
86+
Type: v1alpha2.DataSourceTypeHTTP,
87+
HTTP: &v1alpha2.DataSourceHTTP{
88+
URL: url,
89+
},
90+
}
91+
}
92+
}
93+
8394
func WithPhase(phase v1alpha2.ImagePhase) func(cvi *v1alpha2.ClusterVirtualImage) {
8495
return func(cvi *v1alpha2.ClusterVirtualImage) {
8596
cvi.Status.Phase = phase

images/virtualization-artifact/pkg/builder/vd/option.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ func WithDataSourceHTTP(url string, checksum *v1alpha2.Checksum, caBundle []byte
5656
}
5757
}
5858

59+
func WithDataSourceHTTPWithOnlyURL(url string) Option {
60+
return func(vd *v1alpha2.VirtualDisk) {
61+
vd.Spec.DataSource = &v1alpha2.VirtualDiskDataSource{
62+
Type: v1alpha2.DataSourceTypeHTTP,
63+
HTTP: &v1alpha2.DataSourceHTTP{
64+
URL: url,
65+
},
66+
}
67+
}
68+
}
69+
5970
func WithDataSourceContainerImage(image, imagePullSecretName string, caBundle []byte) Option {
6071
return func(vd *v1alpha2.VirtualDisk) {
6172
vd.Spec.DataSource = &v1alpha2.VirtualDiskDataSource{
@@ -70,7 +81,6 @@ func WithDataSourceContainerImage(image, imagePullSecretName string, caBundle []
7081
}
7182
}
7283
}
73-
7484
func WithDataSourceObjectRef(kind v1alpha2.VirtualDiskObjectRefKind, name string) Option {
7585
return func(vd *v1alpha2.VirtualDisk) {
7686
vd.Spec.DataSource = &v1alpha2.VirtualDiskDataSource{

images/virtualization-artifact/pkg/builder/vi/option.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,39 @@ func WithCDROM(cdrom bool) func(vi *v1alpha2.VirtualImage) {
4040
vi.Status.CDROM = cdrom
4141
}
4242
}
43+
44+
func WithStorageType(storageType *v1alpha2.StorageType) func(vi *v1alpha2.VirtualImage) {
45+
return func(vi *v1alpha2.VirtualImage) {
46+
vi.Spec.Storage = *storageType
47+
}
48+
}
49+
50+
func WithDatasource(datasource v1alpha2.VirtualImageDataSource) func(vd *v1alpha2.VirtualImage) {
51+
return func(vi *v1alpha2.VirtualImage) {
52+
vi.Spec.DataSource = datasource
53+
}
54+
}
55+
56+
func WithDataSourceHTTP(url string, checksum *v1alpha2.Checksum, caBundle []byte) Option {
57+
return func(vi *v1alpha2.VirtualImage) {
58+
vi.Spec.DataSource = v1alpha2.VirtualImageDataSource{
59+
Type: v1alpha2.DataSourceTypeHTTP,
60+
HTTP: &v1alpha2.DataSourceHTTP{
61+
URL: url,
62+
Checksum: checksum,
63+
CABundle: caBundle,
64+
},
65+
}
66+
}
67+
}
68+
69+
func WithDataSourceHTTPWithOnlyURL(url string) Option {
70+
return func(vi *v1alpha2.VirtualImage) {
71+
vi.Spec.DataSource = v1alpha2.VirtualImageDataSource{
72+
Type: v1alpha2.DataSourceTypeHTTP,
73+
HTTP: &v1alpha2.DataSourceHTTP{
74+
URL: url,
75+
},
76+
}
77+
}
78+
}

images/virtualization-artifact/pkg/builder/vm/option.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,9 @@ func WithVirtualMachineClass(class string) Option {
8686
vm.Spec.VirtualMachineClassName = class
8787
}
8888
}
89+
90+
func WithProvisioning(provisiong *v1alpha2.Provisioning) Option {
91+
return func(vm *v1alpha2.VirtualMachine) {
92+
vm.Spec.Provisioning = provisiong
93+
}
94+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
Copyright 2025 Flant JSC
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package vmbda
15+
16+
import (
17+
"github.com/deckhouse/virtualization-controller/pkg/builder/meta"
18+
"github.com/deckhouse/virtualization/api/core/v1alpha2"
19+
)
20+
21+
type Option func(vd *v1alpha2.VirtualMachineBlockDeviceAttachment)
22+
23+
var (
24+
WithName = meta.WithName[*v1alpha2.VirtualMachineBlockDeviceAttachment]
25+
WithNamespace = meta.WithNamespace[*v1alpha2.VirtualMachineBlockDeviceAttachment]
26+
WithLabel = meta.WithLabel[*v1alpha2.VirtualMachineBlockDeviceAttachment]
27+
WithLabels = meta.WithLabels[*v1alpha2.VirtualMachineBlockDeviceAttachment]
28+
WithAnnotation = meta.WithAnnotation[*v1alpha2.VirtualMachineBlockDeviceAttachment]
29+
WithAnnotations = meta.WithAnnotations[*v1alpha2.VirtualMachineBlockDeviceAttachment]
30+
)
31+
32+
func WithBlockDeviceRef(bdRef v1alpha2.VMBDAObjectRef) func(vmbda *v1alpha2.VirtualMachineBlockDeviceAttachment) {
33+
return func(vmbda *v1alpha2.VirtualMachineBlockDeviceAttachment) {
34+
vmbda.Spec.BlockDeviceRef = bdRef
35+
}
36+
}
37+
38+
func WithVMName(vmName string) func(vmbda *v1alpha2.VirtualMachineBlockDeviceAttachment) {
39+
return func(vmbda *v1alpha2.VirtualMachineBlockDeviceAttachment) {
40+
vmbda.Spec.VirtualMachineName = vmName
41+
}
42+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Copyright 2025 Flant JSC
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package vmbda
15+
16+
import (
17+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
18+
19+
"github.com/deckhouse/virtualization/api/core/v1alpha2"
20+
)
21+
22+
func New(options ...Option) *v1alpha2.VirtualMachineBlockDeviceAttachment {
23+
vmbda := NewEmpty("", "")
24+
ApplyOptions(vmbda, options)
25+
return vmbda
26+
}
27+
28+
func ApplyOptions(vmbda *v1alpha2.VirtualMachineBlockDeviceAttachment, opts []Option) {
29+
if vmbda == nil {
30+
return
31+
}
32+
for _, opt := range opts {
33+
opt(vmbda)
34+
}
35+
}
36+
37+
func NewEmpty(name, namespace string) *v1alpha2.VirtualMachineBlockDeviceAttachment {
38+
return &v1alpha2.VirtualMachineBlockDeviceAttachment{
39+
TypeMeta: metav1.TypeMeta{
40+
APIVersion: v1alpha2.SchemeGroupVersion.String(),
41+
Kind: v1alpha2.VirtualMachineBlockDeviceAttachmentKind,
42+
},
43+
ObjectMeta: metav1.ObjectMeta{
44+
Name: name,
45+
Namespace: namespace,
46+
},
47+
}
48+
}

images/virtualization-artifact/pkg/builder/vmop/option.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,9 @@ func WithForce(force *bool) Option {
5151
vmop.Spec.Force = force
5252
}
5353
}
54+
55+
func WithRestoreSpec(restoreSpec *v1alpha2.VirtualMachineOperationRestoreSpec) Option {
56+
return func(vmop *v1alpha2.VirtualMachineOperation) {
57+
vmop.Spec.Restore = restoreSpec
58+
}
59+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
Copyright 2025 Flant JSC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package vmsnapshot
18+
19+
import (
20+
"github.com/deckhouse/virtualization-controller/pkg/builder/meta"
21+
"github.com/deckhouse/virtualization/api/core/v1alpha2"
22+
)
23+
24+
type Option func(vmop *v1alpha2.VirtualMachineSnapshot)
25+
26+
var (
27+
WithName = meta.WithName[*v1alpha2.VirtualMachineSnapshot]
28+
WithGenerateName = meta.WithGenerateName[*v1alpha2.VirtualMachineSnapshot]
29+
WithNamespace = meta.WithNamespace[*v1alpha2.VirtualMachineSnapshot]
30+
WithLabel = meta.WithLabel[*v1alpha2.VirtualMachineSnapshot]
31+
WithLabels = meta.WithLabels[*v1alpha2.VirtualMachineSnapshot]
32+
WithAnnotation = meta.WithAnnotation[*v1alpha2.VirtualMachineSnapshot]
33+
WithAnnotations = meta.WithAnnotations[*v1alpha2.VirtualMachineSnapshot]
34+
WithFinalizer = meta.WithFinalizer[*v1alpha2.VirtualMachineSnapshot]
35+
)
36+
37+
func WithRequiredConsistency(required bool) Option {
38+
return func(vmop *v1alpha2.VirtualMachineSnapshot) {
39+
vmop.Spec.RequiredConsistency = required
40+
}
41+
}
42+
43+
func WithVm(vmName string) Option {
44+
return func(vmop *v1alpha2.VirtualMachineSnapshot) {
45+
vmop.Spec.VirtualMachineName = vmName
46+
}
47+
}
48+
49+
func WithKeepIpAddress(keepIpAddress v1alpha2.KeepIPAddress) Option {
50+
return func(vmop *v1alpha2.VirtualMachineSnapshot) {
51+
vmop.Spec.KeepIPAddress = keepIpAddress
52+
}
53+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Copyright 2025 Flant JSC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package vmsnapshot
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
22+
"github.com/deckhouse/virtualization/api/core/v1alpha2"
23+
)
24+
25+
func New(options ...Option) *v1alpha2.VirtualMachineSnapshot {
26+
vmSnapshot := NewEmpty("", "")
27+
ApplyOptions(vmSnapshot, options...)
28+
return vmSnapshot
29+
}
30+
31+
func ApplyOptions(vmSnapshot *v1alpha2.VirtualMachineSnapshot, opts ...Option) {
32+
if vmSnapshot == nil {
33+
return
34+
}
35+
for _, opt := range opts {
36+
opt(vmSnapshot)
37+
}
38+
}
39+
40+
func NewEmpty(name, namespace string) *v1alpha2.VirtualMachineSnapshot {
41+
return &v1alpha2.VirtualMachineSnapshot{
42+
TypeMeta: metav1.TypeMeta{
43+
APIVersion: v1alpha2.SchemeGroupVersion.String(),
44+
Kind: v1alpha2.VirtualMachineOperationKind,
45+
},
46+
ObjectMeta: metav1.ObjectMeta{
47+
Name: name,
48+
Namespace: namespace,
49+
},
50+
}
51+
}

tests/e2e/framework/framework.go

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ import (
2020
"context"
2121
"fmt"
2222
"maps"
23+
"os/exec"
24+
"strings"
2325

2426
"github.com/onsi/ginkgo/v2"
2527
"github.com/onsi/gomega"
2628
corev1 "k8s.io/api/core/v1"
2729
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
30+
"sigs.k8s.io/controller-runtime/pkg/client"
2831
)
2932

3033
const (
@@ -40,6 +43,7 @@ type Framework struct {
4043

4144
namespace *corev1.Namespace
4245
namespacesToDelete []string
46+
resourcesToDelete []client.Object
4347
}
4448

4549
func NewFramework(namespacePrefix string) *Framework {
@@ -73,12 +77,18 @@ func (f *Framework) Before() {
7377
gomega.Expect(err).NotTo(gomega.HaveOccurred())
7478
ginkgo.By(fmt.Sprintf("Created namespace %s", ns.Name))
7579
f.namespace = ns
76-
f.AddNamespaceToDelete(ns.Name)
7780
}
7881
}
7982

8083
func (f *Framework) After() {
8184
ginkgo.GinkgoHelper()
85+
86+
for _, resource := range f.resourcesToDelete {
87+
ginkgo.By(fmt.Sprintf("Delete resource %s", resource.GetName()))
88+
err := f.client.Delete(context.Background(), resource)
89+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
90+
}
91+
8292
for _, ns := range f.namespacesToDelete {
8393
ginkgo.By(fmt.Sprintf("Delete namespace %s", ns))
8494
err := f.KubeClient().CoreV1().Namespaces().Delete(context.Background(), ns, metav1.DeleteOptions{})
@@ -98,8 +108,8 @@ func (f *Framework) CreateNamespace(prefix string, labels map[string]string) (*c
98108
APIVersion: corev1.SchemeGroupVersion.String(),
99109
},
100110
ObjectMeta: metav1.ObjectMeta{
101-
GenerateName: fmt.Sprintf("%s-%s-", NamespaceBasePrefix, prefix),
102-
Labels: nsLabels,
111+
Name: fmt.Sprintf("%s-%s-%s", NamespaceBasePrefix, prefix, GetCommitHash()),
112+
Labels: nsLabels,
103113
},
104114
}
105115

@@ -118,3 +128,24 @@ func (f *Framework) Namespace() *corev1.Namespace {
118128
func (f *Framework) AddNamespaceToDelete(name string) {
119129
f.namespacesToDelete = append(f.namespacesToDelete, name)
120130
}
131+
132+
func (f *Framework) AddResourceToDelete(obj client.Object) {
133+
f.resourcesToDelete = append(f.resourcesToDelete, obj)
134+
}
135+
136+
// func (f *Framework) GetRunHash() string {
137+
// parts := strings.Split(f.Namespace().Name, "-")
138+
// if len(parts) == 0 {
139+
// return ""
140+
// }
141+
// return parts[len(parts)-1]
142+
// }
143+
144+
func GetCommitHash() string {
145+
ginkgo.GinkgoHelper()
146+
147+
cmd := exec.Command("git", "rev-parse", "--short", "HEAD")
148+
stdout, err := cmd.Output()
149+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
150+
return strings.TrimSpace(string(stdout))
151+
}

0 commit comments

Comments
 (0)