@@ -2,7 +2,9 @@ package powervs
22
33import (
44 "context"
5+ "crypto/rand"
56 "fmt"
7+ "math/big"
68
79 "github.com/sirupsen/logrus"
810 corev1 "k8s.io/api/core/v1"
@@ -22,6 +24,7 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
2224 var (
2325 manifests []* asset.RuntimeFile
2426 network string
27+ dhcpSubnet = "192.168.0.0/24"
2528 service capibm.IBMPowerVSResourceReference
2629 vpcName string
2730 vpcRegion string
@@ -53,6 +56,12 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
5356
5457 network = fmt .Sprintf ("%s-network" , clusterID .InfraID )
5558
59+ n , err := rand .Int (rand .Reader , big .NewInt (253 ))
60+ if err != nil {
61+ return nil , fmt .Errorf ("failed to generate random subnet: %w" , err )
62+ }
63+ dhcpSubnet = fmt .Sprintf ("192.168.%d.0/24" , n .Int64 ())
64+
5665 if installConfig .Config .PowerVS .ServiceInstanceGUID == "" {
5766 serviceName := fmt .Sprintf ("%s-power-iaas" , clusterID .InfraID )
5867
@@ -105,6 +114,9 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
105114 Network : capibm.IBMPowerVSResourceReference {
106115 Name : & network ,
107116 },
117+ DHCPServer : & capibm.DHCPServer {
118+ Cidr : & dhcpSubnet ,
119+ },
108120 ServiceInstance : & service ,
109121 Zone : & installConfig .Config .Platform .PowerVS .Zone ,
110122 ResourceGroup : & capibm.IBMPowerVSResourceReference {
@@ -163,9 +175,7 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
163175 return nil , fmt .Errorf ("unable to find a DNS server for specified VPC: %s %w" , installConfig .Config .PowerVS .VPCName , err )
164176 }
165177
166- powerVSCluster .Spec .DHCPServer = & capibm.DHCPServer {
167- DNSServer : & dnsServerIP ,
168- }
178+ powerVSCluster .Spec .DHCPServer .DNSServer = & dnsServerIP
169179 }
170180
171181 // If a VPC was specified, pass all subnets in it to cluster API
0 commit comments