github.com/openshift/installer@v1.4.17/pkg/types/nutanix/validation/machinepool.go (about)

     1  package validation
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"k8s.io/apimachinery/pkg/util/validation/field"
     7  
     8  	"github.com/openshift/installer/pkg/types/nutanix"
     9  )
    10  
    11  // ValidateMachinePool checks that the specified machine pool is valid.
    12  func ValidateMachinePool(p *nutanix.MachinePool, fldPath *field.Path, role string) field.ErrorList {
    13  	allErrs := field.ErrorList{}
    14  	if p.DiskSizeGiB < 0 {
    15  		allErrs = append(allErrs, field.Invalid(fldPath.Child("diskSizeGiB"), p.DiskSizeGiB, "storage disk size must be positive"))
    16  	}
    17  	if p.MemoryMiB < 0 {
    18  		allErrs = append(allErrs, field.Invalid(fldPath.Child("memoryMiB"), p.MemoryMiB, "memory size must be positive"))
    19  	}
    20  	if p.NumCPUs < 0 {
    21  		allErrs = append(allErrs, field.Invalid(fldPath.Child("cpus"), p.NumCPUs, "number of CPUs must be positive"))
    22  	}
    23  	if p.NumCoresPerSocket < 0 {
    24  		allErrs = append(allErrs, field.Invalid(fldPath.Child("coresPerSocket"), p.NumCoresPerSocket, "cores per socket must be positive"))
    25  	}
    26  	if p.NumCoresPerSocket >= 0 && p.NumCPUs >= 0 && p.NumCoresPerSocket > p.NumCPUs {
    27  		allErrs = append(allErrs, field.Invalid(fldPath.Child("coresPerSocket"), p.NumCoresPerSocket, "cores per socket must be less than number of CPUs"))
    28  	}
    29  
    30  	ntxPlatform := &nutanix.Platform{
    31  		PrismCentral: nutanix.PrismCentral{
    32  			Endpoint: nutanix.PrismEndpoint{Address: "test-pc", Port: 8080},
    33  			Username: "test-username-pc",
    34  			Password: "test-password-pc",
    35  		},
    36  		PrismElements: []nutanix.PrismElement{{
    37  			UUID:     "test-pe-uuid",
    38  			Endpoint: nutanix.PrismEndpoint{Address: "test-pe", Port: 8081},
    39  		}},
    40  		SubnetUUIDs: []string{"b06179c8-dea3-4f8e-818a-b2e88fbc2201"},
    41  	}
    42  
    43  	err := p.ValidateConfig(ntxPlatform, role)
    44  	if err != nil {
    45  		allErrs = append(allErrs, field.Invalid(fldPath, "", fmt.Sprintf("invalid configuration: %v", err)))
    46  	}
    47  
    48  	return allErrs
    49  }