github.com/verrazzano/verrazzano@v1.7.0/pkg/vzchecks/requirement.go (about) 1 // Copyright (c) 2022, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package vzchecks 5 6 import ( 7 k8score "k8s.io/api/core/v1" 8 "k8s.io/apimachinery/pkg/api/resource" 9 ) 10 11 // ProfileType is the type of installation profile. 12 type ProfileType string 13 14 type ResourceType string 15 16 type VZRequirement struct { 17 nodeCount int 18 cpu *resourceInfo 19 memory *resourceInfo 20 ephemeralStorage *resourceInfo 21 } 22 23 type resourceInfo struct { 24 resourceType ResourceType 25 allocatable resource.Quantity 26 } 27 28 const ( 29 // Dev identifies the development install profile 30 Dev ProfileType = "dev" 31 // Prod identifies the production install profile 32 Prod ProfileType = "prod" 33 // ManagedCluster identifies the production managed-cluster install profile 34 ManagedCluster ProfileType = "managed-cluster" 35 ) 36 37 const ( 38 CPU = ResourceType(k8score.ResourceCPU) 39 Memory = ResourceType(k8score.ResourceMemory) 40 EphemeralStorage = ResourceType(k8score.ResourceEphemeralStorage) 41 ) 42 43 const ( 44 nodeCountReqMsg = "minimum required number of worker nodes is %d but the available number of worker nodes is %d" 45 cpuReqMsg = "minimum required CPUs is %v but the CPUs on node %s is %v" 46 memoryReqMsg = "minimum required memory is %sG but the memory on node %s is %sG" 47 storageReqMsg = "minimum required ephemeral storage is %sG but the ephemeral storage on node %s is %sG" 48 ) 49 50 var ( 51 DevReq = VZRequirement{ 52 nodeCount: 1, 53 cpu: &resourceInfo{resourceType: CPU, allocatable: resource.MustParse("2")}, 54 memory: &resourceInfo{resourceType: Memory, allocatable: resource.MustParse("16G")}, 55 ephemeralStorage: &resourceInfo{resourceType: EphemeralStorage, allocatable: resource.MustParse("100G")}, 56 } 57 ProdReq = VZRequirement{ 58 nodeCount: 3, 59 cpu: &resourceInfo{resourceType: CPU, allocatable: resource.MustParse("4")}, 60 memory: &resourceInfo{resourceType: Memory, allocatable: resource.MustParse("32G")}, 61 ephemeralStorage: &resourceInfo{resourceType: EphemeralStorage, allocatable: resource.MustParse("100G")}, 62 } 63 ManagedReq = VZRequirement{ 64 nodeCount: 1, 65 cpu: &resourceInfo{resourceType: CPU, allocatable: resource.MustParse("4")}, 66 memory: &resourceInfo{resourceType: Memory, allocatable: resource.MustParse("32G")}, 67 ephemeralStorage: &resourceInfo{resourceType: EphemeralStorage, allocatable: resource.MustParse("100G")}, 68 } 69 profileMap = map[ProfileType]VZRequirement{ 70 Dev: DevReq, 71 Prod: ProdReq, 72 ManagedCluster: ManagedReq, 73 } 74 ) 75 76 // getVZRequirement gets the VZRequirement based on the profile passed 77 func getVZRequirement(requestedProfile ProfileType) VZRequirement { 78 if len(requestedProfile) == 0 { 79 // Default profile is Prod 80 requestedProfile = Prod 81 } 82 if val, ok := profileMap[requestedProfile]; ok { 83 return val 84 } 85 return VZRequirement{} 86 }