github.com/openshift/installer@v1.4.17/pkg/asset/manifests/powervs/cloudproviderconfig.go (about)

     1  package powervs
     2  
     3  import (
     4  	"bytes"
     5  	"strings"
     6  	"text/template"
     7  )
     8  
     9  // https://github.com/kubernetes/kubernetes/blob/368ee4bb8ee7a0c18431cd87ee49f0c890aa53e5/staging/src/k8s.io/legacy-cloud-providers/gce/gce.go#L188
    10  type config struct {
    11  	Global     global     `gcfg:"global"`
    12  	Kubernetes kubernetes `gcfg:"kubernetes"`
    13  	Provider   provider   `gcfg:"provider"`
    14  }
    15  
    16  type global struct {
    17  	Version string `gcfg:"version"`
    18  }
    19  
    20  type kubernetes struct {
    21  	ConfigFile string `gcfg:"config-file"`
    22  }
    23  
    24  type provider struct {
    25  	AccountID                string `gcfg:"accountID"`
    26  	ClusterID                string `gcfg:"clusterID"`
    27  	ClusterDefaultProvider   string `gcfg:"cluster-default-provider"`
    28  	Region                   string `gcfg:"region"`
    29  	G2CredentialsFilePath    string `gcfg:"g2Credentials"`
    30  	G2ResourceGroupName      string `gcfg:"g2ResourceGroupName"`
    31  	G2VPCName                string `gcfg:"g2VpcName"`
    32  	G2WorkerServiceAccountID string `gcfg:"g2workerServiceAccountID"`
    33  	G2VPCSubnetNames         string `gcfg:"g2VpcSubnetNames"`
    34  	PowerVSCloudInstanceID   string `gcfg:"powerVSCloudInstanceID"`
    35  	PowerVSCloudInstanceName string `gcfg:"powerVSCloudInstanceName"`
    36  	PowerVSRegion            string `gcfg:"powerVSRegion"`
    37  	PowerVSZone              string `gcfg:"powerVSZone"`
    38  }
    39  
    40  // CloudProviderConfig generates the cloud provider config for the IBM Power VS platform.
    41  func CloudProviderConfig(infraID string, accountID string, vpcName string, region string, resourceGroupName string, subnets []string, cloudInstGUID string, cloudInstName string, pvsRegion string, pvsZone string) (string, error) {
    42  	config := &config{
    43  		Global: global{
    44  			Version: "1.1.0",
    45  		},
    46  		Kubernetes: kubernetes{
    47  			ConfigFile: "",
    48  		},
    49  		Provider: provider{
    50  			AccountID:                accountID,
    51  			ClusterID:                infraID,
    52  			ClusterDefaultProvider:   "g2",
    53  			Region:                   region,
    54  			G2CredentialsFilePath:    "/etc/vpc/ibmcloud_api_key",
    55  			G2ResourceGroupName:      resourceGroupName,
    56  			G2VPCName:                vpcName,
    57  			G2WorkerServiceAccountID: accountID,
    58  			G2VPCSubnetNames:         strings.Join(subnets, ","),
    59  			PowerVSCloudInstanceID:   cloudInstGUID,
    60  			PowerVSCloudInstanceName: cloudInstName,
    61  			PowerVSRegion:            pvsRegion,
    62  			PowerVSZone:              pvsZone,
    63  		},
    64  	}
    65  	buf := &bytes.Buffer{}
    66  	template := template.Must(template.New("powervs cloudproviderconfig").Parse(configTmpl))
    67  	if err := template.Execute(buf, config); err != nil {
    68  		return "", err
    69  	}
    70  	return buf.String(), nil
    71  }
    72  
    73  var configTmpl = `[global]
    74  version = {{.Global.Version}}
    75  [kubernetes]
    76  config-file = {{ if ne .Kubernetes.ConfigFile "" }}{{ .Kubernetes.ConfigFile }}{{ else }}""{{ end }}
    77  [provider]
    78  accountID = {{.Provider.AccountID}}
    79  clusterID = {{.Provider.ClusterID}}
    80  cluster-default-provider = {{.Provider.ClusterDefaultProvider}}
    81  region = {{.Provider.Region}}
    82  g2Credentials = {{.Provider.G2CredentialsFilePath}}
    83  g2ResourceGroupName = {{.Provider.G2ResourceGroupName}}
    84  g2VpcName = {{.Provider.G2VPCName}}
    85  g2workerServiceAccountID = {{.Provider.G2WorkerServiceAccountID}}
    86  g2VpcSubnetNames = {{.Provider.G2VPCSubnetNames}}
    87  powerVSCloudInstanceID = {{.Provider.PowerVSCloudInstanceID}}
    88  powerVSCloudInstanceName = {{.Provider.PowerVSCloudInstanceName}}
    89  powerVSRegion = {{.Provider.PowerVSRegion}}
    90  powerVSZone = {{.Provider.PowerVSZone}}
    91  `