Skip to content

Commit 3955cf8

Browse files
committed
feat(vmsop): e2e add builders
Signed-off-by: Daniil Antoshin <[email protected]>
1 parent edd8c2c commit 3955cf8

File tree

4 files changed

+221
-0
lines changed

4 files changed

+221
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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(vdsnapshot *v1alpha2.VirtualMachineSnapshot)
25+
26+
var (
27+
WithName = meta.WithName[*v1alpha2.VirtualMachineSnapshot]
28+
WithNamespace = meta.WithNamespace[*v1alpha2.VirtualMachineSnapshot]
29+
WithGenerateName = meta.WithGenerateName[*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 WithVirtualMachineName(vmName string) Option {
38+
return func(vmsnapshot *v1alpha2.VirtualMachineSnapshot) {
39+
vmsnapshot.Spec.VirtualMachineName = vmName
40+
}
41+
}
42+
43+
func WithKeepIPAddress(keepIP v1alpha2.KeepIPAddress) Option {
44+
return func(vmsnapshot *v1alpha2.VirtualMachineSnapshot) {
45+
vmsnapshot.Spec.KeepIPAddress = keepIP
46+
}
47+
}
48+
49+
func WithRequiredConsistency(requiredConsistency bool) Option {
50+
return func(vmsnapshot *v1alpha2.VirtualMachineSnapshot) {
51+
vmsnapshot.Spec.RequiredConsistency = requiredConsistency
52+
}
53+
}
54+
55+
func WithVirtualMachineSnapshotSecretName(secretName string) Option {
56+
return func(vmsnapshot *v1alpha2.VirtualMachineSnapshot) {
57+
vmsnapshot.Status.VirtualMachineSnapshotSecretName = secretName
58+
}
59+
}
60+
61+
func WithVirtualMachineSnapshotPhase(phase v1alpha2.VirtualMachineSnapshotPhase) Option {
62+
return func(vmsnapshot *v1alpha2.VirtualMachineSnapshot) {
63+
vmsnapshot.Status.Phase = phase
64+
}
65+
}
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+
vdsnapshot := NewEmpty("", "")
27+
ApplyOptions(vdsnapshot, options...)
28+
return vdsnapshot
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.VirtualMachineSnapshotKind,
45+
},
46+
ObjectMeta: metav1.ObjectMeta{
47+
Name: name,
48+
Namespace: namespace,
49+
},
50+
}
51+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 vmsop
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(vmsop *v1alpha2.VirtualMachineSnapshotOperation)
25+
26+
var (
27+
WithName = meta.WithName[*v1alpha2.VirtualMachineSnapshotOperation]
28+
WithGenerateName = meta.WithGenerateName[*v1alpha2.VirtualMachineSnapshotOperation]
29+
WithNamespace = meta.WithNamespace[*v1alpha2.VirtualMachineSnapshotOperation]
30+
WithLabel = meta.WithLabel[*v1alpha2.VirtualMachineSnapshotOperation]
31+
WithLabels = meta.WithLabels[*v1alpha2.VirtualMachineSnapshotOperation]
32+
WithAnnotation = meta.WithAnnotation[*v1alpha2.VirtualMachineSnapshotOperation]
33+
WithAnnotations = meta.WithAnnotations[*v1alpha2.VirtualMachineSnapshotOperation]
34+
WithFinalizer = meta.WithFinalizer[*v1alpha2.VirtualMachineSnapshotOperation]
35+
)
36+
37+
func WithType(t v1alpha2.VMSOPType) Option {
38+
return func(vmsop *v1alpha2.VirtualMachineSnapshotOperation) {
39+
vmsop.Spec.Type = t
40+
}
41+
}
42+
43+
func WithVirtualMachineSnapshotName(name string) Option {
44+
return func(vmsop *v1alpha2.VirtualMachineSnapshotOperation) {
45+
vmsop.Spec.VirtualMachineSnapshotName = name
46+
}
47+
}
48+
49+
func WithCreateVirtualMachine(create *v1alpha2.VMSOPCreateVirtualMachineSpec) Option {
50+
return func(vmsop *v1alpha2.VirtualMachineSnapshotOperation) {
51+
vmsop.Spec.Type = v1alpha2.VMSOPTypeCreateVirtualMachine
52+
vmsop.Spec.CreateVirtualMachine = create
53+
}
54+
}
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 vmsop
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.VirtualMachineSnapshotOperation {
26+
vmsop := NewEmpty("", "")
27+
ApplyOptions(vmsop, options...)
28+
return vmsop
29+
}
30+
31+
func ApplyOptions(vmsop *v1alpha2.VirtualMachineSnapshotOperation, opts ...Option) {
32+
if vmsop == nil {
33+
return
34+
}
35+
for _, opt := range opts {
36+
opt(vmsop)
37+
}
38+
}
39+
40+
func NewEmpty(name, namespace string) *v1alpha2.VirtualMachineSnapshotOperation {
41+
return &v1alpha2.VirtualMachineSnapshotOperation{
42+
TypeMeta: metav1.TypeMeta{
43+
APIVersion: v1alpha2.SchemeGroupVersion.String(),
44+
Kind: v1alpha2.VirtualMachineSnapshotOperationKind,
45+
},
46+
ObjectMeta: metav1.ObjectMeta{
47+
Name: name,
48+
Namespace: namespace,
49+
},
50+
}
51+
}

0 commit comments

Comments
 (0)