@@ -19,6 +19,7 @@ import (
1919 "github.com/openshift/installer/pkg/asset/installconfig/vsphere"
2020 "github.com/openshift/installer/pkg/asset/manifests/capiutils"
2121 "github.com/openshift/installer/pkg/types"
22+ "github.com/openshift/installer/pkg/utils"
2223)
2324
2425const (
@@ -69,8 +70,9 @@ func GenerateMachines(ctx context.Context, clusterID string, config *types.Insta
6970
7071 capvMachines := make ([]* capv.VSphereMachine , 0 , len (machines ))
7172 result := make ([]* asset.RuntimeFile , 0 , len (machines ))
73+ staticIP := false
7274
73- for _ , machine := range machines {
75+ for mIndex , machine := range machines {
7476 providerSpec , ok := machine .Spec .ProviderSpec .Value .Object .(* machinev1.VSphereMachineProviderSpec )
7577 if ! ok {
7678 return nil , errors .New ("unable to convert ProviderSpec to VSphereMachineProviderSpec" )
@@ -79,22 +81,33 @@ func GenerateMachines(ctx context.Context, clusterID string, config *types.Insta
7981 vcenterContext := metadata .VCenterContexts [providerSpec .Workspace .Server ]
8082 resourcePool := providerSpec .Workspace .ResourcePool
8183
84+ customVMXKeys := map [string ]string {
85+ "guestinfo.hostname" : machine .Name ,
86+ "guestinfo.domain" : strings .TrimSuffix (config .ClusterDomain (), "." ),
87+ "stealclock.enable" : "TRUE" ,
88+ }
89+
8290 capvNetworkDevices := []capv.NetworkDeviceSpec {}
8391 for _ , networkDevice := range providerSpec .Network .Devices {
8492 networkName , err := getNetworkInventoryPath (vcenterContext , networkDevice .NetworkName , providerSpec )
8593 if err != nil {
8694 return nil , fmt .Errorf ("unable to get network inventory path: %w" , err )
8795 }
88- capvNetworkDevices = append ( capvNetworkDevices , capv.NetworkDeviceSpec {
96+ deviceSpec := capv.NetworkDeviceSpec {
8997 NetworkName : networkName ,
9098 DHCP4 : true ,
91- })
92- }
99+ }
93100
94- customVMXKeys := map [string ]string {
95- "guestinfo.hostname" : machine .Name ,
96- "guestinfo.domain" : strings .TrimSuffix (config .ClusterDomain (), "." ),
97- "stealclock.enable" : "TRUE" ,
101+ // Static IP configured. Add kargs.
102+ if len (networkDevice .AddressesFromPools ) > 0 {
103+ staticIP = true
104+ kargs , err := utils .ConstructNetworkKargsFromMachine (data .IPClaims , data .IPAddresses , & machines [mIndex ], networkDevice )
105+ if err != nil {
106+ return nil , fmt .Errorf ("unable to get static ip config for machine %v: %w" , machine .Name , err )
107+ }
108+ customVMXKeys ["guestinfo.afterburn.initrd.network-kargs" ] = kargs
109+ }
110+ capvNetworkDevices = append (capvNetworkDevices , deviceSpec )
98111 }
99112
100113 vsphereMachine := & capv.VSphereMachine {
@@ -166,6 +179,15 @@ func GenerateMachines(ctx context.Context, clusterID string, config *types.Insta
166179 if role == masterRole {
167180 customVMXKeys := map [string ]string {}
168181
182+ // If we detected static IP for masters, lets apply to bootstrap as well.
183+ if staticIP {
184+ kargs , err := utils .ConstructKargsForBootstrap (config )
185+ if err != nil {
186+ return nil , fmt .Errorf ("unable to get static ip config for bootstrap: %w" , err )
187+ }
188+ customVMXKeys ["guestinfo.afterburn.initrd.network-kargs" ] = kargs
189+ }
190+
169191 bootstrapSpec := capvMachines [0 ].Spec
170192 bootstrapSpec .CustomVMXKeys = customVMXKeys
171193 bootstrapVSphereMachine := & capv.VSphereMachine {
0 commit comments