@@ -20,6 +20,7 @@ import (
2020 "github.com/openshift/installer/pkg/asset/lbconfig"
2121 "github.com/openshift/installer/pkg/asset/machines"
2222 "github.com/openshift/installer/pkg/asset/tls"
23+ "github.com/openshift/installer/pkg/types"
2324 awstypes "github.com/openshift/installer/pkg/types/aws"
2425 azuretypes "github.com/openshift/installer/pkg/types/azure"
2526 gcptypes "github.com/openshift/installer/pkg/types/gcp"
@@ -32,20 +33,24 @@ const (
3233 mcsCertFile = "/opt/openshift/tls/machine-config-server.crt"
3334 masterUserDataFile = "/opt/openshift/openshift/99_openshift-cluster-api_master-user-data-secret.yaml"
3435 workerUserDataFile = "/opt/openshift/openshift/99_openshift-cluster-api_worker-user-data-secret.yaml"
36+ clusterConfigDataFile = "/opt/openshift/manifests/cluster-config.yaml"
3537
3638 // header is the string that precedes the encoded data in the ignition data.
3739 // The data must be replaced before decoding the string, and the string must be
3840 // prepended to the encoded data.
3941 header = "data:text/plain;charset=utf-8;base64,"
4042
43+ // The key in the cluster-config-v1 ConfigMap to extract the install-config.
44+ clusterConfigCMKey = "install-config"
45+
4146 masterRole = "master"
4247 workerRole = "worker"
4348)
4449
45- // EditIgnition attempts to edit the contents of the bootstrap ignition when the user has selected
50+ // EditIgnitionForCustomDNS attempts to edit the contents of the bootstrap ignition when the user has selected
4651// a custom DNS configuration. Find the public and private load balancer addresses and fill in the
4752// infrastructure file within the ignition struct.
48- func EditIgnition (in IgnitionInput , platform string , publicIPAddresses , privateIPAddresses []string ) (* IgnitionOutput , error ) {
53+ func EditIgnitionForCustomDNS (in IgnitionInput , platform string , publicIPAddresses , privateIPAddresses []string ) (* IgnitionOutput , error ) {
4954 ignData := & igntypes.Config {}
5055 err := json .Unmarshal (in .BootstrapIgnData , ignData )
5156 if err != nil {
@@ -292,3 +297,77 @@ func updateUserDataSecret(in IgnitionInput, role string, config *igntypes.Config
292297 }
293298 return nil
294299}
300+
301+ // EditIgnitionForDualStack attempts to edit the contents of the bootstrap ignition when the cluster is in dualstack.
302+ func EditIgnitionForDualStack (in IgnitionInput , platform string , machineNetworks []types.MachineNetworkEntry ) (* IgnitionOutput , error ) {
303+ ignData := & igntypes.Config {}
304+ err := json .Unmarshal (in .BootstrapIgnData , ignData )
305+ if err != nil {
306+ return nil , fmt .Errorf ("failed to unmarshal bootstrap ignition: %w" , err )
307+ }
308+
309+ err = updateMachineNetworks (in , ignData , machineNetworks )
310+ if err != nil {
311+ return nil , fmt .Errorf ("failed to update machine networks in ignition config: %w" , err )
312+ }
313+ logrus .Debugf ("Successfully updated the install-config machine networks" )
314+
315+ editedIgnBytes , err := json .Marshal (ignData )
316+ if err != nil {
317+ return nil , fmt .Errorf ("failed to convert ignition data to json: %w" , err )
318+ }
319+ logrus .Debugf ("Successfully updated bootstrap ignition with updated manifests for dualstack networking" )
320+
321+ return & IgnitionOutput {
322+ UpdatedBootstrapIgn : editedIgnBytes ,
323+ UpdatedMasterIgn : in .MasterIgnData ,
324+ UpdatedWorkerIgn : in .WorkerIgnData ,
325+ }, nil
326+ }
327+
328+ func updateMachineNetworks (in IgnitionInput , config * igntypes.Config , machineNetworks []types.MachineNetworkEntry ) error {
329+ for i , fileData := range config .Storage .Files {
330+ if fileData .Path != clusterConfigDataFile {
331+ continue
332+ }
333+
334+ contents := strings .Split (* config .Storage .Files [i ].Contents .Source , "," )
335+ rawDecodedText , err := base64 .StdEncoding .DecodeString (contents [1 ])
336+ if err != nil {
337+ return fmt .Errorf ("failed to decode contents of ignition file: %w" , err )
338+ }
339+
340+ configCM := & corev1.ConfigMap {}
341+ if err := yaml .Unmarshal (rawDecodedText , configCM ); err != nil {
342+ return fmt .Errorf ("failed to unmarshal cluster-config ConfigMap: %w" , err )
343+ }
344+
345+ installConfig := & types.InstallConfig {}
346+ if err := yaml .Unmarshal ([]byte (configCM .Data [clusterConfigCMKey ]), installConfig ); err != nil {
347+ return fmt .Errorf ("failed to unmarshal install-config content: %w" , err )
348+ }
349+
350+ // Update the machine network field
351+ installConfig .MachineNetwork = machineNetworks
352+
353+ // Convert the installconfig back to string and save it to the configmap
354+ icContents , err := yaml .Marshal (installConfig )
355+ if err != nil {
356+ return fmt .Errorf ("failed to marshal install-config: %w" , err )
357+ }
358+ configCM .Data [clusterConfigCMKey ] = string (icContents )
359+
360+ // convert the infrastructure back to an encoded string
361+ configCMContents , err := yaml .Marshal (configCM )
362+ if err != nil {
363+ return fmt .Errorf ("failed to marshal cluster-config ConfigMap: %w" , err )
364+ }
365+
366+ encoded := fmt .Sprintf ("%s%s" , header , base64 .StdEncoding .EncodeToString (configCMContents ))
367+ // replace the contents with the edited information
368+ config .Storage .Files [i ].Contents .Source = & encoded
369+
370+ break
371+ }
372+ return nil
373+ }
0 commit comments