Add template HW version detection during clone
Abort clone if HW version is not supported.
@@ -5,6 +5,7 @@ import (
"encoding/base64"
"errors"
"fmt"
+ "strconv"
"strings"
apimachineryutilerrors "k8s.io/apimachinery/pkg/util/errors"
@@ -546,6 +547,21 @@ func isRetrieveMONotFound(taskRef string, err error) bool {
return err.Error() == fmt.Sprintf("ServerFaultCode: The object 'vim.Task:%v' has already been deleted or has not been completely created", taskRef)
}
+func getHwVersion(ctx context.Context, vm *object.VirtualMachine) (int, error) {
+ var _vm mo.VirtualMachine
+ if err := vm.Properties(ctx, vm.Reference(), []string{"config.version"}, &_vm); err != nil {
+ return 0, fmt.Errorf("error getting hw version information for vm %s: %w", vm.Name(), err)
+ }
+
+ versionString := _vm.Config.Version
+ version := strings.TrimPrefix(versionString, "vmx-")
+ parsedVersion, err := strconv.Atoi(version)
+ if err != nil {
+ return 0, fmt.Errorf("can not extract hardware version from version string: %s, format unknown", versionString)
+ }
+ return parsedVersion, nil
+}
+
func clone(s *machineScope) (string, error) {
userData, err := s.GetUserData()
if err != nil {
@@ -560,6 +576,18 @@ func clone(s *machineScope) (string, error) {
return "", handleVSphereError(multipleFoundMsg, notFoundMsg, defaultError, err)
}
+ hwVersion, err := getHwVersion(s.Context, vmTemplate)
+ if err != nil {
+ // TODO throw an event also?
+ klog.Warningf("Unable to detect machine template HW version for machine %s: %v", s.machine.GetName(), err)
+ }
+ if hwVersion == 13 { // TODO figure out this condition more precisely
+ return "", machineapierros.InvalidMachineConfiguration(
+ "Hardware version 13 is not supported, clone stopped. " +
+ "Please update machine template: https://access.redhat.com/articles/6090681",
+ )
+ }
+
// Default clone type is FullClone, having snapshot on clonee template will cause incorrect disk sizing.
diskMoveType := fullCloneDiskMoveType
var snapshotRef *types.ManagedObjectReference
