diff --git a/api/fixtures/example_ibmcloud_powervs.go b/api/fixtures/example_ibmcloud_powervs.go index a9cc354357..a40dc15af9 100644 --- a/api/fixtures/example_ibmcloud_powervs.go +++ b/api/fixtures/example_ibmcloud_powervs.go @@ -3,6 +3,8 @@ package fixtures import ( corev1 "k8s.io/api/core/v1" crclient "sigs.k8s.io/controller-runtime/pkg/client" + + hyperv1 "github.com/openshift/hypershift/api/v1alpha1" ) type ExamplePowerVSOptions struct { @@ -22,7 +24,7 @@ type ExamplePowerVSOptions struct { // nodepool related options SysType string - ProcType string + ProcType hyperv1.PowerVSNodePoolProcType Processors string Memory int32 } diff --git a/api/v1alpha1/nodepool_types.go b/api/v1alpha1/nodepool_types.go index c4a91ae622..e9caef44f8 100644 --- a/api/v1alpha1/nodepool_types.go +++ b/api/v1alpha1/nodepool_types.go @@ -1,6 +1,7 @@ package v1alpha1 import ( + "fmt" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -366,6 +367,44 @@ type NodePoolPlatform struct { PowerVS *PowerVSNodePoolPlatform `json:"powervs,omitempty"` } +// PowerVSNodePoolProcType defines processor type to be used for PowerVSNodePoolPlatform +type PowerVSNodePoolProcType string + +func (p *PowerVSNodePoolProcType) String() string { + return string(*p) +} + +func (p *PowerVSNodePoolProcType) Set(s string) error { + switch s { + case string(PowerVSNodePoolSharedProcType), string(PowerVSNodePoolCappedProcType), string(PowerVSNodePoolDedicatedProcType): + *p = PowerVSNodePoolProcType(s) + return nil + default: + return fmt.Errorf("unknown processor type used %s", s) + } +} + +func (p *PowerVSNodePoolProcType) Type() string { + return "PowerVSNodePoolProcType" +} + +const ( + // PowerVSNodePoolDedicatedProcType defines dedicated processor type + PowerVSNodePoolDedicatedProcType = PowerVSNodePoolProcType("dedicated") + + // PowerVSNodePoolSharedProcType defines shared processor type + PowerVSNodePoolSharedProcType = PowerVSNodePoolProcType("shared") + + // PowerVSNodePoolCappedProcType defines capped processor type + PowerVSNodePoolCappedProcType = PowerVSNodePoolProcType("capped") +) + +// PowerVSNodePoolStorageType defines storage type to be used for PowerVSNodePoolPlatform +type PowerVSNodePoolStorageType string + +// PowerVSNodePoolImageDeletePolicy defines image delete policy to be used for PowerVSNodePoolPlatform +type PowerVSNodePoolImageDeletePolicy string + // PowerVSNodePoolPlatform specifies the configuration of a NodePool when operating // on IBMCloud PowerVS platform. type PowerVSNodePoolPlatform struct { @@ -395,7 +434,7 @@ type PowerVSNodePoolPlatform struct { // +kubebuilder:default=shared // +kubebuilder:validation:Enum=dedicated;shared;capped // +optional - ProcessorType string `json:"processorType,omitempty"` + ProcessorType PowerVSNodePoolProcType `json:"processorType,omitempty"` // Processors is the number of virtual processors in a virtual machine. // when the processorType is selected as Dedicated the processors value cannot be fractional. @@ -444,7 +483,7 @@ type PowerVSNodePoolPlatform struct { // +kubebuilder:default=tier1 // +kubebuilder:validation:Enum=tier1;tier3 // +optional - StorageType string `json:"storageType,omitempty"` + StorageType PowerVSNodePoolStorageType `json:"storageType,omitempty"` // ImageDeletePolicy is policy for the image deletion. // @@ -456,7 +495,7 @@ type PowerVSNodePoolPlatform struct { // +kubebuilder:default=delete // +kubebuilder:validation:Enum=delete;retain // +optional - ImageDeletePolicy string `json:"imageDeletePolicy,omitempty"` + ImageDeletePolicy PowerVSNodePoolImageDeletePolicy `json:"imageDeletePolicy,omitempty"` } // KubevirtCompute contains values associated with the virtual compute hardware requested for the VM. diff --git a/cmd/cluster/core/create.go b/cmd/cluster/core/create.go index 56874fe4cc..9e1b954826 100644 --- a/cmd/cluster/core/create.go +++ b/cmd/cluster/core/create.go @@ -91,7 +91,7 @@ type PowerVSPlatformOptions struct { // nodepool related options SysType string - ProcType string + ProcType hyperv1.PowerVSNodePoolProcType Processors string Memory int32 } diff --git a/cmd/cluster/powervs/create.go b/cmd/cluster/powervs/create.go index b72c621a86..13ba2f4216 100644 --- a/cmd/cluster/powervs/create.go +++ b/cmd/cluster/powervs/create.go @@ -10,6 +10,7 @@ import ( "syscall" apifixtures "github.com/openshift/hypershift/api/fixtures" + hyperv1 "github.com/openshift/hypershift/api/v1alpha1" "github.com/openshift/hypershift/cmd/cluster/core" powervsinfra "github.com/openshift/hypershift/cmd/infra/powervs" "github.com/openshift/hypershift/support/infraid" @@ -32,7 +33,7 @@ func NewCreateCommand(opts *core.CreateOptions) *cobra.Command { Zone: "us-south", VPCRegion: "us-south", SysType: "s922", - ProcType: "shared", + ProcType: hyperv1.PowerVSNodePoolSharedProcType, Processors: "0.5", Memory: 32, } @@ -45,7 +46,7 @@ func NewCreateCommand(opts *core.CreateOptions) *cobra.Command { cmd.Flags().StringVar(&opts.PowerVSPlatform.VPCRegion, "vpc-region", opts.PowerVSPlatform.VPCRegion, "IBM Cloud VPC Region for VPC resources. Default is us-south") cmd.Flags().StringVar(&opts.PowerVSPlatform.VPC, "vpc", "", "IBM Cloud VPC Name") cmd.Flags().StringVar(&opts.PowerVSPlatform.SysType, "sys-type", opts.PowerVSPlatform.SysType, "System type used to host the instance(e.g: s922, e980, e880). Default is s922") - cmd.Flags().StringVar(&opts.PowerVSPlatform.ProcType, "proc-type", opts.PowerVSPlatform.ProcType, "Processor type (dedicated, shared, capped). Default is shared") + cmd.Flags().Var(&opts.PowerVSPlatform.ProcType, "proc-type", "Processor type (dedicated, shared, capped). Default is shared") cmd.Flags().StringVar(&opts.PowerVSPlatform.Processors, "processors", opts.PowerVSPlatform.Processors, "Number of processors allocated. Default is 0.5") cmd.Flags().Int32Var(&opts.PowerVSPlatform.Memory, "memory", opts.PowerVSPlatform.Memory, "Amount of memory allocated (in GB). Default is 32") cmd.Flags().BoolVar(&opts.PowerVSPlatform.Debug, "debug", opts.PowerVSPlatform.Debug, "Enabling this will print PowerVS API Request & Response logs") diff --git a/cmd/nodepool/powervs/create.go b/cmd/nodepool/powervs/create.go index a2783e7ecf..72acb6b933 100644 --- a/cmd/nodepool/powervs/create.go +++ b/cmd/nodepool/powervs/create.go @@ -18,7 +18,7 @@ import ( type PowerVSPlatformCreateOptions struct { SysType string - ProcType string + ProcType hyperv1.PowerVSNodePoolProcType Processors string Memory int32 } @@ -37,7 +37,7 @@ func NewCreateCommand(coreOpts *core.CreateNodePoolOptions) *cobra.Command { } cmd.Flags().StringVar(&opts.SysType, "sys-type", opts.SysType, "System type used to host the instance(e.g: s922, e980, e880). Default is s922") - cmd.Flags().StringVar(&opts.ProcType, "proc-type", opts.ProcType, "Processor type (dedicated, shared, capped). Default is shared") + cmd.Flags().Var(&opts.ProcType, "proc-type", "Processor type (dedicated, shared, capped). Default is shared") cmd.Flags().StringVar(&opts.Processors, "processors", opts.Processors, "Number of processors allocated. Default is 0.5") cmd.Flags().Int32Var(&opts.Memory, "memory", opts.Memory, "Amount of memory allocated (in GB). Default is 32") diff --git a/docs/content/reference/api.md b/docs/content/reference/api.md index bf5813265d..88979961e3 100644 --- a/docs/content/reference/api.md +++ b/docs/content/reference/api.md @@ -6094,6 +6094,14 @@ This field is immutable. Once set, It can’t be changed.

+###PowerVSNodePoolImageDeletePolicy { #hypershift.openshift.io/v1alpha1.PowerVSNodePoolImageDeletePolicy } +

+(Appears on: +PowerVSNodePoolPlatform) +

+

+

PowerVSNodePoolImageDeletePolicy defines image delete policy to be used for PowerVSNodePoolPlatform

+

###PowerVSNodePoolPlatform { #hypershift.openshift.io/v1alpha1.PowerVSNodePoolPlatform }

(Appears on: @@ -6133,7 +6141,9 @@ reasonable default. The current default is s922 which is generally available.

processorType
-string + +PowerVSNodePoolProcType + @@ -6146,6 +6156,12 @@ Capped: Shared, but resources do not expand beyond those that are requested, the

if the processorType is selected as Dedicated, then Processors value cannot be fractional. When omitted, this means that the user has no opinion and the platform is left to choose a reasonable default. The current default is Shared.

+

+Value must be one of: +"capped", +"dedicated", +"shared" +

@@ -6211,7 +6227,9 @@ is chosen based on the NodePool release payload image.

storageType
-string + +PowerVSNodePoolStorageType + @@ -6227,7 +6245,9 @@ Although, the exact numbers might change over time, the Tier 3 storage is curren imageDeletePolicy
-string + +PowerVSNodePoolImageDeletePolicy + @@ -6240,6 +6260,40 @@ retain: delete the image from the openshift but retain in the infrastructure.

+###PowerVSNodePoolProcType { #hypershift.openshift.io/v1alpha1.PowerVSNodePoolProcType } +

+(Appears on: +PowerVSNodePoolPlatform) +

+

+

PowerVSNodePoolProcType defines processor type to be used for PowerVSNodePoolPlatform

+

+ + + + + + + + + + + + + + +
ValueDescription

"capped"

PowerVSNodePoolCappedProcType defines capped processor type

+

"dedicated"

PowerVSNodePoolDedicatedProcType defines dedicated processor type

+

"shared"

PowerVSNodePoolSharedProcType defines shared processor type

+
+###PowerVSNodePoolStorageType { #hypershift.openshift.io/v1alpha1.PowerVSNodePoolStorageType } +

+(Appears on: +PowerVSNodePoolPlatform) +

+

+

PowerVSNodePoolStorageType defines storage type to be used for PowerVSNodePoolPlatform

+

###PowerVSPlatformSpec { #hypershift.openshift.io/v1alpha1.PowerVSPlatformSpec }

(Appears on: diff --git a/hypershift-operator/controllers/nodepool/powervs.go b/hypershift-operator/controllers/nodepool/powervs.go index dc73f5e929..a9b44dd4a6 100644 --- a/hypershift-operator/controllers/nodepool/powervs.go +++ b/hypershift-operator/controllers/nodepool/powervs.go @@ -67,7 +67,7 @@ func ibmPowerVSMachineTemplateSpec(hcluster *hyperv1.HostedCluster, nodePool *hy ImageRef: imageRef, Network: subnet, SysType: nodePool.Spec.Platform.PowerVS.SystemType, - ProcType: nodePool.Spec.Platform.PowerVS.ProcessorType, + ProcType: string(nodePool.Spec.Platform.PowerVS.ProcessorType), Processors: nodePool.Spec.Platform.PowerVS.Processors.String(), Memory: strconv.Itoa(int(nodePool.Spec.Platform.PowerVS.MemoryGiB)), }, @@ -111,8 +111,8 @@ func reconcileIBMPowerVSImage(ibmPowerVSImage *capipowervs.IBMPowerVSImage, hclu Bucket: &img.Bucket, Object: &img.Object, Region: ®ion, - StorageType: nodePool.Spec.Platform.PowerVS.StorageType, - DeletePolicy: nodePool.Spec.Platform.PowerVS.ImageDeletePolicy, + StorageType: string(nodePool.Spec.Platform.PowerVS.StorageType), + DeletePolicy: string(nodePool.Spec.Platform.PowerVS.ImageDeletePolicy), } return nil } diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index b0bc989542..22af04cd0e 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -81,7 +81,7 @@ func TestMain(m *testing.M) { flag.StringVar(&globalOpts.configurableClusterOptions.PowerVSZone, "e2e.powervs-zone", "us-south", "IBM Cloud zone. Default is us-sout") flag.StringVar(&globalOpts.configurableClusterOptions.PowerVSVpcRegion, "e2e.powervs-vpc-region", "us-south", "IBM Cloud VPC Region for VPC resources. Default is us-south") flag.StringVar(&globalOpts.configurableClusterOptions.PowerVSSysType, "e2e.powervs-sys-type", "s922", "System type used to host the instance(e.g: s922, e980, e880). Default is s922") - flag.StringVar(&globalOpts.configurableClusterOptions.PowerVSProcType, "e2e.powervs-proc-type", "shared", "Processor type (dedicated, shared, capped). Default is shared") + flag.Var(&globalOpts.configurableClusterOptions.PowerVSProcType, "e2e.powervs-proc-type", "Processor type (dedicated, shared, capped). Default is shared") flag.StringVar(&globalOpts.configurableClusterOptions.PowerVSProcessors, "e2e.powervs-processors", "0.5", "Number of processors allocated. Default is 0.5") flag.IntVar(&globalOpts.configurableClusterOptions.PowerVSMemory, "e2e.powervs-memory", 32, "Amount of memory allocated (in GB). Default is 32") @@ -234,7 +234,7 @@ type configurableClusterOptions struct { PowerVSZone string PowerVSVpcRegion string PowerVSSysType string - PowerVSProcType string + PowerVSProcType hyperv1.PowerVSNodePoolProcType PowerVSProcessors string PowerVSMemory int }