-
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.
Merge pull request #205 from srm09/vm-api-change/add-min-hw-version
✨ Adds minimum hardware version to VirtualMachine CRD
- Loading branch information
Showing
22 changed files
with
414 additions
and
56 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.