Skip to content

Commit

Permalink
pkg/types: add Set to *MachinePoolPlatform
Browse files Browse the repository at this point in the history
This allows combining values for machine configuration from various
sources like,
1. Defaults decided by installer
2. Platform level defaults in InstallConfig
3. Per pool options.
  • Loading branch information
abhinavdahiya committed Oct 15, 2018
1 parent 89e130e commit 55c9cb0
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions pkg/types/machinepools.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,30 @@ type AWSMachinePoolPlatform struct {
EC2RootVolume `json:"rootVolume"`
}

// Set sets the values from `required` to `a`.
func (a *AWSMachinePoolPlatform) Set(required *AWSMachinePoolPlatform) {
if required == nil || a == nil {
return
}

if required.InstanceType != "" {
a.InstanceType = required.InstanceType
}
if required.IAMRoleName != "" {
a.IAMRoleName = required.IAMRoleName
}

if required.EC2RootVolume.IOPS != 0 {
a.EC2RootVolume.IOPS = required.EC2RootVolume.IOPS
}
if required.EC2RootVolume.Size != 0 {
a.EC2RootVolume.Size = required.EC2RootVolume.Size
}
if required.EC2RootVolume.Type != "" {
a.EC2RootVolume.Type = required.EC2RootVolume.Type
}
}

// EC2RootVolume defines the storage for an ec2 instance.
type EC2RootVolume struct {
// IOPS defines the iops for the instance.
Expand All @@ -62,6 +86,27 @@ type OpenStackMachinePoolPlatform struct {
OpenStackRootVolume `json:"rootVolume"`
}

// Set sets the values from `required` to `a`.
func (o *OpenStackMachinePoolPlatform) Set(required *OpenStackMachinePoolPlatform) {
if required == nil || o == nil {
return
}

if required.FlavorName != "" {
o.FlavorName = required.FlavorName
}

if required.OpenStackRootVolume.IOPS != 0 {
o.OpenStackRootVolume.IOPS = required.OpenStackRootVolume.IOPS
}
if required.OpenStackRootVolume.Size != 0 {
o.OpenStackRootVolume.Size = required.OpenStackRootVolume.Size
}
if required.OpenStackRootVolume.Type != "" {
o.OpenStackRootVolume.Type = required.OpenStackRootVolume.Type
}
}

// OpenStackRootVolume defines the storage for a Nova instance.
type OpenStackRootVolume struct {
// IOPS defines the iops for the instance.
Expand All @@ -86,3 +131,20 @@ type LibvirtMachinePoolPlatform struct {
// E.g. "http://aos-ostree.rhev-ci-vms.eng.rdu2.redhat.com/rhcos/images/cloud/latest/rhcos-qemu.qcow2.gz"
Image string `json:"image"`
}

// Set sets the values from `required` to `a`.
func (l *LibvirtMachinePoolPlatform) Set(required *LibvirtMachinePoolPlatform) {
if required == nil || l == nil {
return
}

if required.ImagePool != "" {
l.ImagePool = required.ImagePool
}
if required.ImageVolume != "" {
l.ImageVolume = required.ImageVolume
}
if required.Image != "" {
l.Image = required.Image
}
}

0 comments on commit 55c9cb0

Please sign in to comment.