github.com/openshift/installer@v1.4.17/pkg/terraform/stages/ignition.go (about) 1 package stages 2 3 import ( 4 "encoding/base64" 5 "fmt" 6 "strings" 7 8 igntypes "github.com/coreos/ignition/v2/config/v3_2/types" 9 "sigs.k8s.io/yaml" 10 11 configv1 "github.com/openshift/api/config/v1" 12 "github.com/openshift/installer/pkg/types/gcp" 13 ) 14 15 const ( 16 // replaceable is the string that precedes the encoded data in the ignition data. 17 // The data must be replaced before decoding the string, and the string must be 18 // prepended to the encoded data. 19 replaceable = "data:text/plain;charset=utf-8;base64," 20 ) 21 22 // AddLoadBalancersToInfra will load the public and private load balancer information into 23 // the infrastructure CR. This will occur after the data has already been inserted into the 24 // ignition file. 25 func AddLoadBalancersToInfra(platform string, config *igntypes.Config, publicLBs []string, privateLBs []string) error { 26 index := -1 27 for i, fileData := range config.Storage.Files { 28 // update the contents of this file 29 if fileData.Path == "/opt/openshift/manifests/cluster-infrastructure-02-config.yml" { 30 index = i 31 break 32 } 33 } 34 35 if index >= 0 { 36 contents := config.Storage.Files[index].Contents.Source 37 replaced := strings.Replace(*contents, replaceable, "", 1) 38 39 rawDecodedText, err := base64.StdEncoding.DecodeString(replaced) 40 if err != nil { 41 return err 42 } 43 44 infra := &configv1.Infrastructure{} 45 if err := yaml.Unmarshal(rawDecodedText, infra); err != nil { 46 return err 47 } 48 49 // convert the list of strings to a list of IPs 50 apiIntLbs := []configv1.IP{} 51 for _, ip := range privateLBs { 52 apiIntLbs = append(apiIntLbs, configv1.IP(ip)) 53 } 54 apiLbs := []configv1.IP{} 55 for _, ip := range publicLBs { 56 apiLbs = append(apiLbs, configv1.IP(ip)) 57 } 58 cloudLBInfo := configv1.CloudLoadBalancerIPs{ 59 APIIntLoadBalancerIPs: apiIntLbs, 60 APILoadBalancerIPs: apiLbs, 61 } 62 63 switch platform { 64 case gcp.Name: 65 if infra.Status.PlatformStatus.GCP.CloudLoadBalancerConfig.DNSType == configv1.ClusterHostedDNSType { 66 infra.Status.PlatformStatus.GCP.CloudLoadBalancerConfig.ClusterHosted = &cloudLBInfo 67 } 68 default: 69 return fmt.Errorf("failed to set load balancer info for platform %s", platform) 70 } 71 72 // convert the infrastructure back to an encoded string 73 infraContents, err := yaml.Marshal(infra) 74 if err != nil { 75 return err 76 } 77 78 encoded := fmt.Sprintf("%s%s", replaceable, base64.StdEncoding.EncodeToString(infraContents)) 79 config.Storage.Files[index].Contents.Source = &encoded 80 } 81 82 return nil 83 }