Skip to content

Commit c1cd483

Browse files
author
Valeriy Khorunzhin
committed
add webhook
Signed-off-by: Valeriy Khorunzhin <[email protected]>
1 parent dfdf130 commit c1cd483

File tree

10 files changed

+586
-0
lines changed

10 files changed

+586
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 cvi
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.ClusterVirtualImage {
23+
cvi := NewEmpty("")
24+
ApplyOptions(cvi, options)
25+
return cvi
26+
}
27+
28+
func ApplyOptions(cvi *v1alpha2.ClusterVirtualImage, opts []Option) {
29+
if cvi == nil {
30+
return
31+
}
32+
for _, opt := range opts {
33+
opt(cvi)
34+
}
35+
}
36+
37+
func NewEmpty(name string) *v1alpha2.ClusterVirtualImage {
38+
return &v1alpha2.ClusterVirtualImage{
39+
TypeMeta: metav1.TypeMeta{
40+
APIVersion: v1alpha2.SchemeGroupVersion.String(),
41+
Kind: v1alpha2.ClusterVirtualImageKind,
42+
},
43+
ObjectMeta: metav1.ObjectMeta{
44+
Name: name,
45+
},
46+
}
47+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 cvi
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(cvi *v1alpha2.ClusterVirtualImage)
22+
23+
var (
24+
WithName = meta.WithName[*v1alpha2.ClusterVirtualImage]
25+
WithLabel = meta.WithLabel[*v1alpha2.ClusterVirtualImage]
26+
WithLabels = meta.WithLabels[*v1alpha2.ClusterVirtualImage]
27+
WithAnnotation = meta.WithAnnotation[*v1alpha2.ClusterVirtualImage]
28+
WithAnnotations = meta.WithAnnotations[*v1alpha2.ClusterVirtualImage]
29+
)
30+
31+
func WithPhase(phase v1alpha2.ImagePhase) func(vi *v1alpha2.ClusterVirtualImage) {
32+
return func(vi *v1alpha2.ClusterVirtualImage) {
33+
vi.Status.Phase = phase
34+
}
35+
}
36+
37+
func WithCDROM(cdrom bool) func(vi *v1alpha2.ClusterVirtualImage) {
38+
return func(vi *v1alpha2.ClusterVirtualImage) {
39+
vi.Status.CDROM = cdrom
40+
}
41+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 vd
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.VirtualDisk)
22+
23+
var (
24+
WithName = meta.WithName[*v1alpha2.VirtualDisk]
25+
WithNamespace = meta.WithNamespace[*v1alpha2.VirtualDisk]
26+
WithLabel = meta.WithLabel[*v1alpha2.VirtualDisk]
27+
WithLabels = meta.WithLabels[*v1alpha2.VirtualDisk]
28+
WithAnnotation = meta.WithAnnotation[*v1alpha2.VirtualDisk]
29+
WithAnnotations = meta.WithAnnotations[*v1alpha2.VirtualDisk]
30+
)
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 vd
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.VirtualDisk {
23+
vd := NewEmpty("", "")
24+
ApplyOptions(vd, options)
25+
return vd
26+
}
27+
28+
func ApplyOptions(vd *v1alpha2.VirtualDisk, opts []Option) {
29+
if vd == nil {
30+
return
31+
}
32+
for _, opt := range opts {
33+
opt(vd)
34+
}
35+
}
36+
37+
func NewEmpty(name, namespace string) *v1alpha2.VirtualDisk {
38+
return &v1alpha2.VirtualDisk{
39+
TypeMeta: metav1.TypeMeta{
40+
APIVersion: v1alpha2.SchemeGroupVersion.String(),
41+
Kind: v1alpha2.VirtualDiskKind,
42+
},
43+
ObjectMeta: metav1.ObjectMeta{
44+
Name: name,
45+
Namespace: namespace,
46+
},
47+
}
48+
}
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 vi
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(vi *v1alpha2.VirtualImage)
22+
23+
var (
24+
WithName = meta.WithName[*v1alpha2.VirtualImage]
25+
WithNamespace = meta.WithNamespace[*v1alpha2.VirtualImage]
26+
WithLabel = meta.WithLabel[*v1alpha2.VirtualImage]
27+
WithLabels = meta.WithLabels[*v1alpha2.VirtualImage]
28+
WithAnnotation = meta.WithAnnotation[*v1alpha2.VirtualImage]
29+
WithAnnotations = meta.WithAnnotations[*v1alpha2.VirtualImage]
30+
)
31+
32+
func WithPhase(phase v1alpha2.ImagePhase) func(vi *v1alpha2.VirtualImage) {
33+
return func(vi *v1alpha2.VirtualImage) {
34+
vi.Status.Phase = phase
35+
}
36+
}
37+
38+
func WithCDROM(cdrom bool) func(vi *v1alpha2.VirtualImage) {
39+
return func(vi *v1alpha2.VirtualImage) {
40+
vi.Status.CDROM = cdrom
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 vi
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.VirtualImage {
23+
vi := NewEmpty("", "")
24+
ApplyOptions(vi, options)
25+
return vi
26+
}
27+
28+
func ApplyOptions(vi *v1alpha2.VirtualImage, opts []Option) {
29+
if vi == nil {
30+
return
31+
}
32+
for _, opt := range opts {
33+
opt(vi)
34+
}
35+
}
36+
37+
func NewEmpty(name, namespace string) *v1alpha2.VirtualImage {
38+
return &v1alpha2.VirtualImage{
39+
TypeMeta: metav1.TypeMeta{
40+
APIVersion: v1alpha2.SchemeGroupVersion.String(),
41+
Kind: v1alpha2.VirtualImageKind,
42+
},
43+
ObjectMeta: metav1.ObjectMeta{
44+
Name: name,
45+
Namespace: namespace,
46+
},
47+
}
48+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,10 @@ func WithMemory(size resource.Quantity) Option {
4949
vm.Spec.Memory.Size = size
5050
}
5151
}
52+
53+
func WithBlockDeviceRefs(bdRefs ...v1alpha2.BlockDeviceSpecRef) Option {
54+
return func(vm *v1alpha2.VirtualMachine) {
55+
vm.Spec.BlockDeviceRefs = []v1alpha2.BlockDeviceSpecRef{}
56+
vm.Spec.BlockDeviceRefs = append(vm.Spec.BlockDeviceRefs, bdRefs...)
57+
}
58+
}

0 commit comments

Comments
 (0)