github.com/openshift/installer@v1.4.17/pkg/asset/ignition/machine/node.go (about) 1 package machine 2 3 import ( 4 "fmt" 5 "net" 6 "net/url" 7 8 ignutil "github.com/coreos/ignition/v2/config/util" 9 igntypes "github.com/coreos/ignition/v2/config/v3_2/types" 10 "github.com/vincent-petithory/dataurl" 11 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 12 13 mcfgv1 "github.com/openshift/api/machineconfiguration/v1" 14 "github.com/openshift/installer/pkg/asset/ignition" 15 "github.com/openshift/installer/pkg/types" 16 baremetaltypes "github.com/openshift/installer/pkg/types/baremetal" 17 nutanixtypes "github.com/openshift/installer/pkg/types/nutanix" 18 openstacktypes "github.com/openshift/installer/pkg/types/openstack" 19 ovirttypes "github.com/openshift/installer/pkg/types/ovirt" 20 vspheretypes "github.com/openshift/installer/pkg/types/vsphere" 21 ) 22 23 const directory = "openshift" 24 25 // pointerIgnitionConfig generates a config which references the remote config 26 // served by the machine config server. 27 func pointerIgnitionConfig(installConfig *types.InstallConfig, rootCA []byte, role string) *igntypes.Config { 28 var ignitionHost string 29 // Default platform independent ignitionHost 30 ignitionHost = fmt.Sprintf("api-int.%s:22623", installConfig.ClusterDomain()) 31 // Update ignitionHost as necessary for platform 32 switch installConfig.Platform.Name() { 33 case baremetaltypes.Name: 34 // Baremetal needs to point directly at the VIP because we don't have a 35 // way to configure DNS before Ignition runs. 36 ignitionHost = net.JoinHostPort(installConfig.BareMetal.APIVIPs[0], "22623") 37 case nutanixtypes.Name: 38 if len(installConfig.Nutanix.APIVIPs) > 0 { 39 ignitionHost = net.JoinHostPort(installConfig.Nutanix.APIVIPs[0], "22623") 40 } 41 case openstacktypes.Name: 42 ignitionHost = net.JoinHostPort(installConfig.OpenStack.APIVIPs[0], "22623") 43 case ovirttypes.Name: 44 ignitionHost = net.JoinHostPort(installConfig.Ovirt.APIVIPs[0], "22623") 45 case vspheretypes.Name: 46 if len(installConfig.VSphere.APIVIPs) > 0 { 47 ignitionHost = net.JoinHostPort(installConfig.VSphere.APIVIPs[0], "22623") 48 } 49 } 50 return &igntypes.Config{ 51 Ignition: igntypes.Ignition{ 52 Version: igntypes.MaxVersion.String(), 53 Config: igntypes.IgnitionConfig{ 54 Merge: []igntypes.Resource{{ 55 Source: ignutil.StrToPtr(func() *url.URL { 56 return &url.URL{ 57 Scheme: "https", 58 Host: ignitionHost, 59 Path: fmt.Sprintf("/config/%s", role), 60 } 61 }().String()), 62 }}, 63 }, 64 Security: igntypes.Security{ 65 TLS: igntypes.TLS{ 66 CertificateAuthorities: []igntypes.Resource{{ 67 Source: ignutil.StrToPtr(dataurl.EncodeBytes(rootCA)), 68 }}, 69 }, 70 }, 71 }, 72 } 73 } 74 75 // generatePointerMachineConfig generates a machineconfig when a user customizes 76 // the pointer ignition file manually in an IPI deployment 77 func generatePointerMachineConfig(config igntypes.Config, role string) (*mcfgv1.MachineConfig, error) { 78 // Remove the merge section from the pointer config 79 config.Ignition.Config.Merge = nil 80 81 rawExt, err := ignition.ConvertToRawExtension(config) 82 if err != nil { 83 return nil, err 84 } 85 86 return &mcfgv1.MachineConfig{ 87 TypeMeta: metav1.TypeMeta{ 88 APIVersion: mcfgv1.SchemeGroupVersion.String(), 89 Kind: "MachineConfig", 90 }, 91 ObjectMeta: metav1.ObjectMeta{ 92 Name: fmt.Sprintf("99-installer-ignition-%s", role), 93 Labels: map[string]string{ 94 "machineconfiguration.openshift.io/role": role, 95 }, 96 }, 97 Spec: mcfgv1.MachineConfigSpec{ 98 Config: rawExt, 99 }, 100 }, nil 101 }