github.com/openshift/installer@v1.4.17/pkg/asset/manifests/gcp/cloudproviderconfig.go (about) 1 package gcp 2 3 import ( 4 "bytes" 5 "fmt" 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 } 13 14 type global struct { 15 ProjectID string `gcfg:"project-id"` 16 17 Regional bool `gcfg:"regional"` 18 Multizone bool `gcfg:"multizone"` 19 20 NodeTags []string `gcfg:"node-tags"` 21 NodeInstancePrefix string `gcfg:"node-instance-prefix"` 22 ExternalInstanceGroupsPrefix string `gcfg:"external-instance-groups-prefix"` 23 24 SubnetworkName string `gcfg:"subnetwork-name"` 25 26 NetworkProjectID string `gcfg:"network-project-id"` 27 } 28 29 // CloudProviderConfig generates the cloud provider config for the GCP platform. 30 func CloudProviderConfig(infraID, projectID, subnet, networkProjectID string) (string, error) { 31 config := &config{ 32 Global: global{ 33 ProjectID: projectID, 34 35 // To make sure k8s cloud provider is looking for instances in all zones. 36 Regional: true, 37 Multizone: true, 38 39 // To make sure k8s cloud provider has tags for firewall for load balancer. 40 // The CAPI gcp provider uses the node tag "control-plane" for master nodes. 41 NodeTags: []string{fmt.Sprintf("%s-master", infraID), fmt.Sprintf("%s-control-plane", infraID), fmt.Sprintf("%s-worker", infraID)}, 42 NodeInstancePrefix: infraID, 43 ExternalInstanceGroupsPrefix: infraID, 44 45 // Used for internal load balancers 46 SubnetworkName: subnet, 47 48 // Used for shared vpc installations, 49 NetworkProjectID: networkProjectID, 50 }, 51 } 52 53 buf := &bytes.Buffer{} 54 template := template.Must(template.New("gce cloudproviderconfig").Parse(configTmpl)) 55 if err := template.Execute(buf, config); err != nil { 56 return "", err 57 } 58 return buf.String(), nil 59 } 60 61 var configTmpl = `[global] 62 project-id = {{.Global.ProjectID}} 63 regional = {{.Global.Regional}} 64 multizone = {{.Global.Multizone}} 65 {{range $idx, $tag := .Global.NodeTags -}} 66 node-tags = {{$tag}} 67 {{end -}} 68 node-instance-prefix = {{.Global.NodeInstancePrefix}} 69 external-instance-groups-prefix = {{.Global.ExternalInstanceGroupsPrefix}} 70 subnetwork-name = {{.Global.SubnetworkName}} 71 {{ if ne .Global.NetworkProjectID "" }}network-project-id = {{.Global.NetworkProjectID}}{{end}} 72 73 `