diff --git a/pkg/services/govmomi/ipam/parse.go b/pkg/services/govmomi/ipam/parse.go index 74d01f70aa..bef844c90d 100644 --- a/pkg/services/govmomi/ipam/parse.go +++ b/pkg/services/govmomi/ipam/parse.go @@ -51,10 +51,10 @@ func parseAddressWithPrefix(ipamAddress *ipamv1.IPAddress) (netip.Prefix, error) // does not conflict with the gateway addresses parsed from other // ipamv1.IPAddresses on the current device. Gateway addresses must be the same // family as the address on the ipamv1.IPAddress. Gateway addresses of one -// family must match the other addresses of the same family. IPv4 Gateways are -// required, but IPv6 gateways are not. +// family must match the other addresses of the same family. A gateway address +// is optional. If it is not set this function returns `nil, nil`. func parseGateway(ipamAddress *ipamv1.IPAddress, addressWithPrefix netip.Prefix, ipamDeviceConfig ipamDeviceConfig) (*netip.Addr, error) { - if ipamAddress.Spec.Gateway == "" && addressWithPrefix.Addr().Is6() { + if ipamAddress.Spec.Gateway == "" { return nil, nil } diff --git a/pkg/services/govmomi/ipam/status_test.go b/pkg/services/govmomi/ipam/status_test.go index a37d4c374f..ebac048356 100644 --- a/pkg/services/govmomi/ipam/status_test.go +++ b/pkg/services/govmomi/ipam/status_test.go @@ -723,8 +723,7 @@ func Test_BuildState(t *testing.T) { g.Expect(ctx.Client.Update(ctx, address1)).NotTo(gomega.HaveOccurred()) _, err := BuildState(ctx, networkStatus) - g.Expect(err).To(gomega.HaveOccurred()) - g.Expect(err).To(gomega.MatchError("IPAddress my-namespace/vsphereVM1-0-0 has invalid gateway: \"\"")) + g.Expect(err).NotTo(gomega.HaveOccurred()) }) t.Run("when a provider assigns an IPv6 IPAddress without a Gateway field", func(_ *testing.T) {