Skip to content

Commit 7c6e399

Browse files
committed
++ more strict comparison for paths, rename public consts to private.
Signed-off-by: Ivan Mikheykin <ivan.mikheykin@flant.com>
1 parent 3b2f5a3 commit 7c6e399

4 files changed

Lines changed: 9 additions & 8 deletions

File tree

images/virtualization-artifact/pkg/controller/vmchange/comparator_block_devices.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"github.com/deckhouse/virtualization/api/core/v1alpha2"
2424
)
2525

26-
const BlockDevicesPath = "blockDeviceRefs"
26+
const blockDevicesPath = "blockDeviceRefs"
2727

2828
// compareBlockDevices returns changes between current and desired blockDevices lists.
2929
func compareBlockDevices(current, desired *v1alpha2.VirtualMachineSpec) []FieldChange {
@@ -32,7 +32,7 @@ func compareBlockDevices(current, desired *v1alpha2.VirtualMachineSpec) []FieldC
3232
}
3333

3434
fullChanges := compareEmpty(
35-
BlockDevicesPath,
35+
blockDevicesPath,
3636
NewValue(current.BlockDeviceRefs, len(current.BlockDeviceRefs) == 0, false),
3737
NewValue(desired.BlockDeviceRefs, len(desired.BlockDeviceRefs) == 0, false),
3838
ActionApplyImmediate,
@@ -152,7 +152,7 @@ func vmdIndexedNames(vm *v1alpha2.VirtualMachineSpec) map[string]int {
152152
}
153153

154154
func blockDevicesItemPath(idx int) string {
155-
return fmt.Sprintf("%s.%d", BlockDevicesPath, idx)
155+
return fmt.Sprintf("%s.%d", blockDevicesPath, idx)
156156
}
157157

158158
func updateIndexesForAddedDevices(added map[int]struct{}, currentDevices, desiredDevices map[string]int) {

images/virtualization-artifact/pkg/controller/vmchange/comparator_cpu.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type comparatorCPU struct {
2828
featureGate featuregate.FeatureGate
2929
}
3030

31-
const CPUPath = "cpu"
31+
const cpuPath = "cpu"
3232

3333
func NewComparatorCPU(featureGate featuregate.FeatureGate) VMSpecFieldComparator {
3434
return &comparatorCPU{

images/virtualization-artifact/pkg/controller/vmchange/comparator_memory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/deckhouse/virtualization/api/core/v1alpha2"
2626
)
2727

28-
const MemoryPath = "memory"
28+
const memoryPath = "memory"
2929

3030
type comparatorMemory struct {
3131
featureGate featuregate.FeatureGate

images/virtualization-artifact/pkg/controller/vmchange/spec_changes.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,17 @@ func (s *SpecChanges) ConvertPendingChanges() ([]apiextensionsv1.JSON, error) {
244244

245245
func (s *SpecChanges) UpgradeBlockDeviceChangesToRestart() {
246246
for i := range s.changes {
247-
if strings.HasPrefix(s.changes[i].Path, BlockDevicesPath) && s.changes[i].ActionRequired == ActionApplyImmediate {
247+
isBlockDeviceChange := s.changes[i].Path == blockDevicesPath || strings.HasPrefix(s.changes[i].Path, blockDevicesPath+".")
248+
if isBlockDeviceChange && s.changes[i].ActionRequired == ActionApplyImmediate {
248249
s.changes[i].ActionRequired = ActionRestart
249250
}
250251
}
251252
}
252253

253254
func (s *SpecChanges) UpgradeHotplugComputeChangesToRestart() {
254255
for i := range s.changes {
255-
isCPUChange := strings.HasPrefix(s.changes[i].Path, CPUPath)
256-
isMemoryChange := strings.HasPrefix(s.changes[i].Path, MemoryPath)
256+
isCPUChange := s.changes[i].Path == cpuPath || strings.HasPrefix(s.changes[i].Path, cpuPath+".")
257+
isMemoryChange := s.changes[i].Path == memoryPath || strings.HasPrefix(s.changes[i].Path, memoryPath+".")
257258
if (isCPUChange || isMemoryChange) && s.changes[i].ActionRequired == ActionApplyImmediate {
258259
s.changes[i].ActionRequired = ActionRestart
259260
}

0 commit comments

Comments
 (0)