Skip to content

Commit

Permalink
Merge branch 'release-0.15' into automated-backport-of-#2785-origin-r…
Browse files Browse the repository at this point in the history
…elease-0.15
  • Loading branch information
skitt authored Sep 14, 2023
2 parents 9568c2c + 1ecb650 commit a8bf8ef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
9 changes: 5 additions & 4 deletions pkg/discovery/network/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,11 @@ func findPodIPRangeFromNodeSpec(ctx context.Context, client controllerClient.Cli
}

func parseToPodCidr(nodes []corev1.Node) (string, error) {
for i := range nodes {
if nodes[i].Spec.PodCIDR != "" {
return nodes[i].Spec.PodCIDR, nil
}
// In K8s, each node is typically assigned a unique PodCIDR range for the pods that run on that node.
// Each node's PodCIDR is used to allocate IP addresses to the pods scheduled on that node. Only if
// the cluster is a single node deployment, we should rely on the node.Spec.PodCIDR as podCIDR of the cluster.
if len(nodes) == 1 {
return nodes[0].Spec.PodCIDR, nil
}

return "", nil
Expand Down
20 changes: 17 additions & 3 deletions pkg/discovery/network/generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,12 @@ var _ = Describe("Generic Network", func() {
})
})

When("Pod CIDR information exists on a node", func() {
When("Pod CIDR information exists on a single node cluster", func() {
var clusterNet *network.ClusterNetwork

BeforeEach(func() {
clusterNet = testDiscoverGenericWith(
fakeNode("node1", ""),
fakeNode("node2", testPodCIDR),
fakeNode("node1", testPodCIDR),
)
})

Expand All @@ -245,6 +244,21 @@ var _ = Describe("Generic Network", func() {
})
})

When("Pod CIDR information exists on a multi node cluster", func() {
var clusterNet *network.ClusterNetwork

BeforeEach(func() {
clusterNet = testDiscoverGenericWith(
fakeNode("node1", testPodCIDR),
fakeNode("node2", testPodCIDR),
)
})

It("Should return an empty ClusterNetwork structure with the pod CIDR", func() {
Expect(clusterNet.PodCIDRs).To(BeEmpty())
})
})

When("Both pod and service CIDR information exists", func() {
var clusterNet *network.ClusterNetwork

Expand Down

0 comments on commit a8bf8ef

Please sign in to comment.