forked from openshift/installer
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For more background on IPI on Power VS, refer to the enhancement proposal here: openshift/enhancements#736 Older discussions on some of the code here can be found in openshift#5224 Signed-off-by: Christy Norman <christy@linux.vnet.ibm.com>
- Loading branch information
Showing
2 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Package powervs contains Power Virtual Servers-specific Terraform-variable logic. | ||
package powervs | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"math/rand" | ||
"time" | ||
|
||
"github.com/openshift/installer/pkg/types/powervs" | ||
"github.com/openshift/machine-api-provider-powervs/pkg/apis/powervsprovider/v1alpha1" | ||
) | ||
|
||
type config struct { | ||
ServiceInstanceID string `json:"powervs_cloud_instance_id"` | ||
APIKey string `json:"powervs_api_key"` | ||
SSHKey string `json:"powervs_ssh_key"` | ||
PowerVSRegion string `json:"powervs_region"` | ||
PowerVSZone string `json:"powervs_zone"` | ||
VPCRegion string `json:"powervs_vpc_region"` | ||
VPCZone string `json:"powervs_vpc_zone"` | ||
PowerVSResourceGroup string `json:"powervs_resource_group"` | ||
CISInstanceCRN string `json:"powervs_cis_crn"` | ||
ImageBucketFileName string `json:"powervs_image_bucket_file_name"` | ||
NetworkName string `json:"powervs_network_name"` | ||
VPCName string `json:"powervs_vpc_name"` | ||
VPCSubnetName string `json:"powervs_vpc_subnet_name"` | ||
BootstrapMemory string `json:"powervs_bootstrap_memory"` | ||
BootstrapProcessors string `json:"powervs_bootstrap_processors"` | ||
MasterMemory string `json:"powervs_master_memory"` | ||
MasterProcessors string `json:"powervs_master_processors"` | ||
ProcType string `json:"powervs_proc_type"` | ||
SysType string `json:"powervs_sys_type"` | ||
} | ||
|
||
// TFVarsSources contains the parameters to be converted into Terraform variables | ||
type TFVarsSources struct { | ||
MasterConfigs []*v1alpha1.PowerVSMachineProviderConfig | ||
APIKey string | ||
SSHKey string | ||
Region string | ||
Zone string | ||
ImageBucketFileName string | ||
NetworkName string | ||
PowerVSResourceGroup string | ||
VPCZone string | ||
CISInstanceCRN string | ||
VPCName string | ||
VPCSubnetName string | ||
} | ||
|
||
// TFVars generates Power VS-specific Terraform variables launching the cluster. | ||
func TFVars(sources TFVarsSources) ([]byte, error) { | ||
masterConfig := sources.MasterConfigs[0] | ||
vpcRegion := powervs.Regions[sources.Region].VPCRegion | ||
|
||
vpcZone := sources.VPCZone | ||
if vpcZone == "" { | ||
// Randomly select a zone in the VPC region. | ||
// @TODO: Align this with a region later. | ||
rand.Seed(time.Now().UnixNano()) | ||
// All supported Regions are MZRs and have Zones named "region-[1-3]" | ||
vpcZone = fmt.Sprintf("%s-%d", vpcRegion, rand.Intn(2)+1) | ||
} | ||
|
||
cfg := &config{ | ||
ServiceInstanceID: masterConfig.ServiceInstanceID, | ||
APIKey: sources.APIKey, | ||
SSHKey: sources.SSHKey, | ||
PowerVSRegion: sources.Region, | ||
PowerVSZone: sources.Zone, | ||
VPCRegion: vpcRegion, | ||
VPCZone: vpcZone, | ||
PowerVSResourceGroup: sources.PowerVSResourceGroup, | ||
CISInstanceCRN: sources.CISInstanceCRN, | ||
ImageBucketFileName: sources.ImageBucketFileName, | ||
NetworkName: *masterConfig.Network.Name, | ||
VPCName: sources.VPCName, | ||
VPCSubnetName: sources.VPCSubnetName, | ||
BootstrapMemory: masterConfig.Memory, | ||
BootstrapProcessors: masterConfig.Processors, | ||
MasterMemory: masterConfig.Memory, | ||
MasterProcessors: masterConfig.Processors, | ||
ProcType: masterConfig.ProcType, | ||
SysType: masterConfig.SysType, | ||
} | ||
|
||
return json.MarshalIndent(cfg, "", " ") | ||
} |