From 9d4f23a42f5ecd51c4eaa3228ae7aa5ff79ae88f Mon Sep 17 00:00:00 2001 From: lmxia Date: Thu, 23 May 2024 15:24:28 +0800 Subject: [PATCH] fix cidr allocate error in hub Signed-off-by: lmxia --- README.md | 6 ++---- pkg/controller/peer_controller.go | 5 ++++- pkg/util/netutil_test.go | 9 +++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index aaf93055..27ae775a 100644 --- a/README.md +++ b/README.md @@ -91,8 +91,7 @@ or `Service` CIDR, it's `10.112.0.0/12` by default. And install nauti-agent in cluster by: helm install nauti-agent mcs/nauti-agent --namespace nauti-system --create-namespace \ ---set hub.hubURL=https://10.115.217.212:6443 --set tunnel.globalcidr=20.112.0.0/12 --set tunnel.cidr=20.114.0.0/16 \ - --set cluster.clusterID=cluster1 +--set hub.hubURL=https://10.115.217.212:6443 --set cluster.clusterID=cluster1 ``` @@ -132,8 +131,7 @@ helm install nauti-agent mcs/nauti-agent --namespace nauti-system --create-nam "mcs" has been added to your repositories $ helm install nauti-agent mcs/nauti-agent --namespace nauti-system --create-namespace \ - --set hub.hubURL=https://10.115.217.212:6443 --set tunnel.globalcidr=20.112.0.0/12 \ - --set tunnel.cidr=20.114.0.0/16 --set cluster.clusterID=cluster1 + --set hub.hubURL=https://10.115.217.212:6443 --set cluster.clusterID=cluster1 ``` Add cross cluster DNS config segment, in `coredns` configmap, and restart coredns pods. ```yaml diff --git a/pkg/controller/peer_controller.go b/pkg/controller/peer_controller.go index 0f461baf..1dd3bd98 100644 --- a/pkg/controller/peer_controller.go +++ b/pkg/controller/peer_controller.go @@ -130,12 +130,15 @@ func (p *PeerController) Handle(obj interface{}) (requeueAfter *time.Duration, e // prepare data... existingCIDR := make([]string, 0) noCIDR = true - if peerList, errListPeer := p.peerLister.Peers(namespace).List(labels.Everything()); errListPeer != nil { + if peerList, errListPeer := p.peerLister.Peers(namespace).List(labels.Everything()); errListPeer == nil { for _, item := range peerList { if item.Name != "hub" && len(item.Spec.PodCIDR) != 0 { existingCIDR = append(existingCIDR, item.Spec.PodCIDR[0]) } } + } else { + klog.Errorf("peers get with %v", err) + return &failedPeriod, err } // cidr allocation here. cachedPeer.Spec.PodCIDR = make([]string, 1) diff --git a/pkg/util/netutil_test.go b/pkg/util/netutil_test.go index 8acfc3d7..740a1183 100644 --- a/pkg/util/netutil_test.go +++ b/pkg/util/netutil_test.go @@ -123,6 +123,15 @@ func Test_findAvailableCIDR(t *testing.T) { want: "20.115.0.0/16", wantErr: false, }, + { + name: "namex", + args: args{ + networkCIDR: "20.112.0.0/12", + existingPeers: []string{"20.112.0.0/16"}, + }, + want: "20.113.0.0/16", + wantErr: false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {