From 120b4e58c394726d1e0c74d46e3b99b6b7da4a18 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 12 Apr 2024 13:41:58 +0200 Subject: [PATCH] `node.Obtain()`: Fix `panic: failed to parse CIDR : invalid CIDR address:` --- pkg/schema/v1/node.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/schema/v1/node.go b/pkg/schema/v1/node.go index 98cb3dd1..c2d33bf9 100644 --- a/pkg/schema/v1/node.go +++ b/pkg/schema/v1/node.go @@ -62,11 +62,13 @@ func (n *Node) Obtain(k8s kmetav1.Object) { n.Id = types.Checksum(n.Namespace + "/" + n.Name) n.PodCIDR = node.Spec.PodCIDR - _, cidr, err := net.ParseCIDR(n.PodCIDR) - if err != nil { - panic(errors.Wrapf(err, "failed to parse CIDR %s", n.PodCIDR)) + if n.PodCIDR != "" { + _, cidr, err := net.ParseCIDR(n.PodCIDR) + if err != nil { + panic(errors.Wrapf(err, "failed to parse CIDR %s", n.PodCIDR)) + } + n.NumIps = knet.RangeSize(cidr) - 2 } - n.NumIps = knet.RangeSize(cidr) - 2 n.Unschedulable = types.Bool{ Bool: node.Spec.Unschedulable, Valid: true,