Skip to content

Commit cc03b22

Browse files
committed
feat(api): add new controllers vmmac and vmmaclease
Signed-off-by: Dmitry Lopatin <[email protected]>
1 parent 4e69bd7 commit cc03b22

File tree

13 files changed

+51
-84
lines changed

13 files changed

+51
-84
lines changed

api/core/v1alpha2/finalizers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ const (
3232
FinalizerVICleanup = "virtualization.deckhouse.io/vi-cleanup"
3333
FinalizerVMCleanup = "virtualization.deckhouse.io/vm-cleanup"
3434
FinalizerIPAddressCleanup = "virtualization.deckhouse.io/vmip-cleanup"
35-
FinalizerMACAddressCleanup = "virtualization.deckhouse.io/vmmac-cleanup"
3635
FinalizerIPAddressLeaseCleanup = "virtualization.deckhouse.io/vmipl-cleanup"
37-
FinalizerMACAddressLeaseCleanup = "virtualization.deckhouse.io/vmmacl-cleanup"
3836
FinalizerVDSnapshotCleanup = "virtualization.deckhouse.io/vdsnapshot-cleanup"
3937
FinalizerVMOPCleanup = "virtualization.deckhouse.io/vmop-cleanup"
4038
FinalizerVMClassCleanup = "virtualization.deckhouse.io/vmclass-cleanup"
4139
FinalizerVMBDACleanup = "virtualization.deckhouse.io/vmbda-cleanup"
40+
FinalizerMACAddressCleanup = "virtualization.deckhouse.io/vmmac-cleanup"
41+
FinalizerMACAddressLeaseCleanup = "virtualization.deckhouse.io/vmmacl-cleanup"
4242
)

api/core/v1alpha2/virtual_machine.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ type VirtualMachineStatus struct {
281281
// Name of `virtualMachineIPAddressName` holding the ip address of the VirtualMachine.
282282
VirtualMachineIPAddress string `json:"virtualMachineIPAddressName"`
283283
// IP address of VM.
284-
IPAddress string `json:"ipAddress"`
284+
IPAddress string `json:"ipAddress"`
285+
// The list of attached block device attachments.
285286
BlockDeviceRefs []BlockDeviceStatusRef `json:"blockDeviceRefs,omitempty"`
286287
GuestOSInfo virtv1.VirtualMachineInstanceGuestOSInfo `json:"guestOSInfo,omitempty"`
287288
// Detailed state of the virtual machine lifecycle.

api/core/v1alpha2/virtual_machine_mac_address.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2024 Flant JSC
2+
Copyright 2025 Flant JSC
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

api/core/v1alpha2/virtual_machine_mac_address_lease.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2024 Flant JSC
2+
Copyright 2025 Flant JSC
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

api/core/v1alpha2/vmmaccondition/condition.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2024 Flant JSC
2+
Copyright 2025 Flant JSC
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -47,9 +47,6 @@ func (r AttachedReason) String() string {
4747
}
4848

4949
const (
50-
// VirtualMachineMACAddressIsOutOfTheValidRange is a BoundReason indicating when specified MAC address is out of the range in controller settings.
51-
VirtualMachineMACAddressIsOutOfTheValidRange BoundReason = "VirtualMachineMACAddressIsOutOfTheValidRange"
52-
5350
// VirtualMachineMACAddressLeaseAlreadyExists is a BoundReason indicating the MAC address lease already exists.
5451
VirtualMachineMACAddressLeaseAlreadyExists BoundReason = "VirtualMachineMACAddressLeaseAlreadyExists"
5552

api/core/v1alpha2/vmmaclcondition/condition.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2024 Flant JSC
2+
Copyright 2025 Flant JSC
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@ package vmmaclcondition
1919
type Type string
2020

2121
const (
22-
// BoundType represents the condition type when a Virtual Machine MAC is bound.
22+
// BoundType represents the condition type when a Virtual Machine MAC lease is bound.
2323
BoundType Type = "Bound"
2424
)
2525

@@ -37,7 +37,4 @@ func (r BoundReason) String() string {
3737
const (
3838
// Bound is a BoundReason indicating the MAC address lease is successfully bound.
3939
Bound BoundReason = "Bound"
40-
41-
// NotBound is a BoundReason indicating the MAC address lease is not bound.
42-
NotBound BoundReason = "NotBound"
4340
)

images/virtualization-artifact/pkg/common/network/network.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type InterfaceSpec struct {
3636
Type string `json:"type"`
3737
Name string `json:"name"`
3838
InterfaceName string `json:"ifName"`
39+
MAC string `json:"-"`
3940
}
4041

4142
type InterfaceStatus struct {
@@ -73,6 +74,7 @@ func CreateNetworkSpec(vmSpec virtv2.VirtualMachineSpec, vmmacs []*virtv2.Virtua
7374
Type: network.Type,
7475
Name: network.Name,
7576
InterfaceName: generateInterfaceName(macAddresses[macCounter], network.Type),
77+
MAC: macAddresses[macCounter],
7678
})
7779

7880
macCounter++

images/virtualization-artifact/pkg/controller/indexer/vmmac_indexer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2024 Flant JSC
2+
Copyright 2025 Flant JSC
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

images/virtualization-artifact/pkg/controller/indexer/vmmaclease_indexer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2024 Flant JSC
2+
Copyright 2025 Flant JSC
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

images/virtualization-artifact/pkg/controller/kvbuilder/kvvm_utils.go

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"crypto/md5"
2121
"encoding/hex"
2222
"fmt"
23-
"sort"
2423
"strings"
2524

2625
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -92,7 +91,6 @@ func ApplyVirtualMachineSpec(
9291
class *virtv2.VirtualMachineClass,
9392
ipAddress string,
9493
networkSpec network.InterfaceSpecList,
95-
vmmacs []*virtv2.VirtualMachineMACAddress,
9694
) error {
9795
if err := kvvm.SetRunPolicy(vm.Spec.RunPolicy); err != nil {
9896
return err
@@ -108,7 +106,7 @@ func ApplyVirtualMachineSpec(
108106
}
109107

110108
kvvm.SetMetadata(vm.ObjectMeta)
111-
setNetwork(kvvm, networkSpec, vmmacs)
109+
setNetwork(kvvm, networkSpec)
112110
kvvm.SetTablet("default-0")
113111
kvvm.SetNodeSelector(vm.Spec.NodeSelector, class.Spec.NodeSelector.MatchLabels)
114112
kvvm.SetTolerations(vm.Spec.Tolerations, class.Spec.Tolerations)
@@ -254,23 +252,12 @@ func ApplyVirtualMachineSpec(
254252
return nil
255253
}
256254

257-
func setNetwork(kvvm *KVVM, networkSpec network.InterfaceSpecList, vmmacs []*virtv2.VirtualMachineMACAddress) {
255+
func setNetwork(kvvm *KVVM, networkSpec network.InterfaceSpecList) {
258256
kvvm.ClearNetworkInterfaces()
259257
kvvm.SetNetworkInterface(network.NameDefaultInterface, "")
260258

261-
sort.Slice(vmmacs, func(i, j int) bool {
262-
return vmmacs[i].CreationTimestamp.Before(&vmmacs[j].CreationTimestamp)
263-
})
264-
265-
var macAddresses []string
266-
for _, vmmac := range vmmacs {
267-
if vmmac != nil && vmmac.Status.Address != "" {
268-
macAddresses = append(macAddresses, vmmac.Status.Address)
269-
}
270-
}
271-
272-
for i, n := range networkSpec {
273-
kvvm.SetNetworkInterface(n.InterfaceName, macAddresses[i])
259+
for _, n := range networkSpec {
260+
kvvm.SetNetworkInterface(n.InterfaceName, n.MAC)
274261
}
275262
}
276263

0 commit comments

Comments
 (0)