-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds minimum h/w version to VirtualMachine CRD
Introduces a new field on the VirtualMachine CRD which allows the user to define the minimum hardware version for the provisioned VM. The behavior of the field is as follows: - If the VMClassAsConfig FSS is enabled, it will override the hardware version derived from the VMClass's ConfigSpec if it is lower than the minimum version field. Otherwise, the value from the ConfigSpec is honored. - If the VMClassAsConfig FSS is disabled, it will reconfigure the VM post creation before the power on operation to ensure that the h/w version is atleast set to the minimum version. This means, it can override the hardware version of the OVA with a hardware version value lower than this field. Signed-off-by: Sagar Muchhal <[email protected]>
- Loading branch information
Showing
15 changed files
with
320 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) 2023 VMware, Inc. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package util | ||
|
||
import ( | ||
"regexp" | ||
"strconv" | ||
) | ||
|
||
var vmxRe = regexp.MustCompile(`vmx-(\d+)`) | ||
|
||
// ParseVirtualHardwareVersion parses the virtual hardware version | ||
// For eg. "vmx-15" returns 15. | ||
func ParseVirtualHardwareVersion(vmxVersion string) int32 { | ||
// obj matches the full string and the submatch (\d+) | ||
// and return a []string with values | ||
obj := vmxRe.FindStringSubmatch(vmxVersion) | ||
if len(obj) != 2 { | ||
return 0 | ||
} | ||
|
||
version, err := strconv.ParseInt(obj[1], 10, 32) | ||
if err != nil { | ||
return 0 | ||
} | ||
|
||
return int32(version) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) 2023 VMware, Inc. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package util_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/vmware-tanzu/vm-operator/pkg/util" | ||
) | ||
|
||
var _ = Describe("ParseVirtualHardwareVersion", func() { | ||
It("empty hardware string", func() { | ||
vmxHwVersionString := "" | ||
Expect(util.ParseVirtualHardwareVersion(vmxHwVersionString)).To(BeZero()) | ||
}) | ||
|
||
It("invalid hardware string", func() { | ||
vmxHwVersionString := "blah" | ||
Expect(util.ParseVirtualHardwareVersion(vmxHwVersionString)).To(BeZero()) | ||
}) | ||
|
||
It("valid hardware version string eg. vmx-15", func() { | ||
vmxHwVersionString := "vmx-15" | ||
Expect(util.ParseVirtualHardwareVersion(vmxHwVersionString)).To(Equal(int32(15))) | ||
}) | ||
}) |
Oops, something went wrong.