Skip to content

Commit

Permalink
Merge pull request #1809 from dharaneeshvrd/powervs-custom-types
Browse files Browse the repository at this point in the history
Add custom types for enum fields in PowerVSNodePoolPlatform
  • Loading branch information
openshift-merge-robot authored Oct 20, 2022
2 parents e12d064 + 0319210 commit 4056441
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 17 deletions.
4 changes: 3 additions & 1 deletion api/fixtures/example_ibmcloud_powervs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -22,7 +24,7 @@ type ExamplePowerVSOptions struct {

// nodepool related options
SysType string
ProcType string
ProcType hyperv1.PowerVSNodePoolProcType
Processors string
Memory int32
}
Expand Down
45 changes: 42 additions & 3 deletions api/v1alpha1/nodepool_types.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
//
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion cmd/cluster/core/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ type PowerVSPlatformOptions struct {

// nodepool related options
SysType string
ProcType string
ProcType hyperv1.PowerVSNodePoolProcType
Processors string
Memory int32
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/cluster/powervs/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
}
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions cmd/nodepool/powervs/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

type PowerVSPlatformCreateOptions struct {
SysType string
ProcType string
ProcType hyperv1.PowerVSNodePoolProcType
Processors string
Memory int32
}
Expand All @@ -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")

Expand Down
60 changes: 57 additions & 3 deletions docs/content/reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6094,6 +6094,14 @@ This field is immutable. Once set, It can&rsquo;t be changed.</p>
</td>
</tr></tbody>
</table>
###PowerVSNodePoolImageDeletePolicy { #hypershift.openshift.io/v1alpha1.PowerVSNodePoolImageDeletePolicy }
<p>
(<em>Appears on:</em>
<a href="#hypershift.openshift.io/v1alpha1.PowerVSNodePoolPlatform">PowerVSNodePoolPlatform</a>)
</p>
<p>
<p>PowerVSNodePoolImageDeletePolicy defines image delete policy to be used for PowerVSNodePoolPlatform</p>
</p>
###PowerVSNodePoolPlatform { #hypershift.openshift.io/v1alpha1.PowerVSNodePoolPlatform }
<p>
(<em>Appears on:</em>
Expand Down Expand Up @@ -6133,7 +6141,9 @@ reasonable default. The current default is s922 which is generally available.</p
<td>
<code>processorType</code></br>
<em>
string
<a href="#hypershift.openshift.io/v1alpha1.PowerVSNodePoolProcType">
PowerVSNodePoolProcType
</a>
</em>
</td>
<td>
Expand All @@ -6146,6 +6156,12 @@ Capped: Shared, but resources do not expand beyond those that are requested, the
<p>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.</p>
<p>
Value must be one of:
&#34;capped&#34;,
&#34;dedicated&#34;,
&#34;shared&#34;
</p>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -6211,7 +6227,9 @@ is chosen based on the NodePool release payload image.</p>
<td>
<code>storageType</code></br>
<em>
string
<a href="#hypershift.openshift.io/v1alpha1.PowerVSNodePoolStorageType">
PowerVSNodePoolStorageType
</a>
</em>
</td>
<td>
Expand All @@ -6227,7 +6245,9 @@ Although, the exact numbers might change over time, the Tier 3 storage is curren
<td>
<code>imageDeletePolicy</code></br>
<em>
string
<a href="#hypershift.openshift.io/v1alpha1.PowerVSNodePoolImageDeletePolicy">
PowerVSNodePoolImageDeletePolicy
</a>
</em>
</td>
<td>
Expand All @@ -6240,6 +6260,40 @@ retain: delete the image from the openshift but retain in the infrastructure.</p
</tr>
</tbody>
</table>
###PowerVSNodePoolProcType { #hypershift.openshift.io/v1alpha1.PowerVSNodePoolProcType }
<p>
(<em>Appears on:</em>
<a href="#hypershift.openshift.io/v1alpha1.PowerVSNodePoolPlatform">PowerVSNodePoolPlatform</a>)
</p>
<p>
<p>PowerVSNodePoolProcType defines processor type to be used for PowerVSNodePoolPlatform</p>
</p>
<table>
<thead>
<tr>
<th>Value</th>
<th>Description</th>
</tr>
</thead>
<tbody><tr><td><p>&#34;capped&#34;</p></td>
<td><p>PowerVSNodePoolCappedProcType defines capped processor type</p>
</td>
</tr><tr><td><p>&#34;dedicated&#34;</p></td>
<td><p>PowerVSNodePoolDedicatedProcType defines dedicated processor type</p>
</td>
</tr><tr><td><p>&#34;shared&#34;</p></td>
<td><p>PowerVSNodePoolSharedProcType defines shared processor type</p>
</td>
</tr></tbody>
</table>
###PowerVSNodePoolStorageType { #hypershift.openshift.io/v1alpha1.PowerVSNodePoolStorageType }
<p>
(<em>Appears on:</em>
<a href="#hypershift.openshift.io/v1alpha1.PowerVSNodePoolPlatform">PowerVSNodePoolPlatform</a>)
</p>
<p>
<p>PowerVSNodePoolStorageType defines storage type to be used for PowerVSNodePoolPlatform</p>
</p>
###PowerVSPlatformSpec { #hypershift.openshift.io/v1alpha1.PowerVSPlatformSpec }
<p>
(<em>Appears on:</em>
Expand Down
6 changes: 3 additions & 3 deletions hypershift-operator/controllers/nodepool/powervs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
},
Expand Down Expand Up @@ -111,8 +111,8 @@ func reconcileIBMPowerVSImage(ibmPowerVSImage *capipowervs.IBMPowerVSImage, hclu
Bucket: &img.Bucket,
Object: &img.Object,
Region: &region,
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
}
4 changes: 2 additions & 2 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -234,7 +234,7 @@ type configurableClusterOptions struct {
PowerVSZone string
PowerVSVpcRegion string
PowerVSSysType string
PowerVSProcType string
PowerVSProcType hyperv1.PowerVSNodePoolProcType
PowerVSProcessors string
PowerVSMemory int
}
Expand Down

0 comments on commit 4056441

Please sign in to comment.