Skip to content

Commit 92a6804

Browse files
Merge pull request #9745 from openshift-cherrypick-robot/cherry-pick-9743-to-release-4.19
[release-4.19] MGMT-20702, OCPBUGS-56762: Avoid duplicate machine networks
2 parents 51dbc70 + 3e18f81 commit 92a6804

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

pkg/asset/manifests/vsphere/infrastructure.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package vsphere
22

33
import (
44
"fmt"
5+
"slices"
56

67
"github.com/sirupsen/logrus"
78
utilsnet "k8s.io/utils/net"
@@ -77,8 +78,13 @@ func GetInfraPlatformSpec(ic *installconfig.InstallConfig, clusterID string) *co
7778
platformSpec.APIServerInternalIPs = types.StringsToIPs(icPlatformSpec.APIVIPs)
7879
platformSpec.IngressIPs = types.StringsToIPs(icPlatformSpec.IngressVIPs)
7980
platformSpec.MachineNetworks = types.MachineNetworksToCIDRs(ic.Config.MachineNetwork)
80-
platformSpec.MachineNetworks = append(platformSpec.MachineNetworks, vipsToCIDRs(ic.Config.VSphere.APIVIPs)...)
81-
platformSpec.MachineNetworks = append(platformSpec.MachineNetworks, vipsToCIDRs(ic.Config.VSphere.IngressVIPs)...)
81+
82+
vips := getInstallConfigVIPs(ic)
83+
for _, vipCIDR := range vipsToCIDRs(vips) {
84+
if !slices.Contains(platformSpec.MachineNetworks, vipCIDR) {
85+
platformSpec.MachineNetworks = append(platformSpec.MachineNetworks, vipCIDR)
86+
}
87+
}
8288

8389
if ic.Config.EnabledFeatureGates().Enabled(features.FeatureGateVSphereMultiNetworks) {
8490
logrus.Debug("Multi-networks feature gate enabled")
@@ -115,3 +121,11 @@ func vipsToCIDRs(vips []string) []configv1.CIDR {
115121
}
116122
return cidrs
117123
}
124+
125+
func getInstallConfigVIPs(ic *installconfig.InstallConfig) []string {
126+
vips := make([]string, 0, len(ic.Config.VSphere.APIVIPs)+len(ic.Config.VSphere.IngressVIPs))
127+
vips = append(vips, ic.Config.VSphere.APIVIPs...)
128+
vips = append(vips, ic.Config.VSphere.IngressVIPs...)
129+
130+
return vips
131+
}

0 commit comments

Comments
 (0)