From dabd8f9c6863b93b1765c643a76f11b62a7998c1 Mon Sep 17 00:00:00 2001 From: weizhoublue <45163302+weizhoublue@users.noreply.github.com> Date: Thu, 31 Oct 2024 15:52:20 +0800 Subject: [PATCH] fix: scanAll typo Signed-off-by: tao.yang --- cmd/spiderpool-agent/cmd/daemon.go | 2 +- cmd/spiderpool-controller/cmd/crd_manager.go | 2 +- cmd/spiderpool-init/cmd/client.go | 22 +++++++++---------- docs/concepts/arch-zh_CN.md | 2 +- docs/concepts/coordinator-zh_CN.md | 2 +- docs/concepts/coordinator.md | 2 +- docs/usage/network-topology-zh_CN.md | 1 + docs/usage/network-topology.md | 1 + docs/usage/route-zh_CN.md | 2 +- .../coordinator_validate.go | 6 +---- pkg/gcmanager/scanAll_IPPool.go | 7 +++--- pkg/ip/cidr.go | 6 +++-- 12 files changed, 27 insertions(+), 28 deletions(-) diff --git a/cmd/spiderpool-agent/cmd/daemon.go b/cmd/spiderpool-agent/cmd/daemon.go index a46d5e9f53..770713079e 100644 --- a/cmd/spiderpool-agent/cmd/daemon.go +++ b/cmd/spiderpool-agent/cmd/daemon.go @@ -73,7 +73,7 @@ func DaemonMain() { // Load spiderpool's global Comfigmap. if err := agentContext.LoadConfigmap(); err != nil { - logger.Sugar().Fatal("Failed to load Configmap spiderpool-conf: %v", err) + logger.Sugar().Fatalf("Failed to load Configmap spiderpool-conf: %v", err) } logger.Sugar().Infof("Spiderpool-agent config: %+v", agentContext.Cfg) diff --git a/cmd/spiderpool-controller/cmd/crd_manager.go b/cmd/spiderpool-controller/cmd/crd_manager.go index 51bc286da7..8ed13e8e9d 100644 --- a/cmd/spiderpool-controller/cmd/crd_manager.go +++ b/cmd/spiderpool-controller/cmd/crd_manager.go @@ -93,8 +93,8 @@ type _webhookHealthCheck struct{} // ServeHTTP only serves for SpiderIPPool webhook health check, it will return http status code 200 for GET request func (*_webhookHealthCheck) ServeHTTP(writer http.ResponseWriter, request *http.Request) { if request.Method == http.MethodGet { - //logger.Debug("SpiderIPPool webhook health check ready") writer.WriteHeader(http.StatusOK) + logger.Info("Webhook health check successful") } } diff --git a/cmd/spiderpool-init/cmd/client.go b/cmd/spiderpool-init/cmd/client.go index f8ef23d3f3..2e57bcbe5b 100644 --- a/cmd/spiderpool-init/cmd/client.go +++ b/cmd/spiderpool-init/cmd/client.go @@ -91,21 +91,21 @@ func (c *CoreClient) WaitForIPPoolCreated(ctx context.Context, ipPool *spiderpoo logger := logutils.FromContext(ctx) for { - err := c.Create(ctx, ipPool) - if err == nil { - logger.Sugar().Infof("Succeed to create default IPv%d IPPool: %+v", *ipPool.Spec.IPVersion, *ipPool) - return nil - } - - if apierrors.IsAlreadyExists(err) { - logger.Sugar().Infof("Default IPv%d IPPool %s is already exists, ignore creating", *ipPool.Spec.IPVersion, ipPool.Name) - return nil - } - select { case <-ctx.Done(): return ctx.Err() default: + err := c.Create(ctx, ipPool) + if err == nil { + logger.Sugar().Infof("Succeed to create default IPv%d IPPool: %+v", *ipPool.Spec.IPVersion, *ipPool) + return nil + } + + if apierrors.IsAlreadyExists(err) { + logger.Sugar().Infof("Default IPv%d IPPool %s is already exists, ignore creating", *ipPool.Spec.IPVersion, ipPool.Name) + return nil + } + interval := retryIntervalSec * time.Second logger.Sugar().Infof("Failed to create default IPv%d IPPool %s, recreate in %s: %v", *ipPool.Spec.IPVersion, ipPool.Name, interval, err) time.Sleep(interval) diff --git a/docs/concepts/arch-zh_CN.md b/docs/concepts/arch-zh_CN.md index 06f7f46452..5dd8249f7b 100644 --- a/docs/concepts/arch-zh_CN.md +++ b/docs/concepts/arch-zh_CN.md @@ -44,7 +44,7 @@ Spiderpool 架构如上所示,包含了以下组件: [RDMA shared device plugin](https://github.com/Mellanox/k8s-rdma-shared-dev-plugin): 用于发现主机上的共享 RDMA 设备,并上报给 Kubelet, 以供 RDMA CNI 使用,参考 [RDMA使用](../usage/rdma-zh_CN.md) [RDMA CNI](https://github.com/k8snetworkplumbingwg/rdma-cni): 参考 [RDMA使用](../usage/rdma-zh_CN.md) - + ## 应用场景:Pod 接入一个 overlay CNI 和若干个 underlay CNI 网卡 ![arch_underlay](../images/spiderpool-overlay.jpg) diff --git a/docs/concepts/coordinator-zh_CN.md b/docs/concepts/coordinator-zh_CN.md index ca7bebca52..529b519c56 100644 --- a/docs/concepts/coordinator-zh_CN.md +++ b/docs/concepts/coordinator-zh_CN.md @@ -1,6 +1,6 @@ # Coordinator -[**English**](coordinator.md) | **简体中文** +**简体中文** | [**English**](coordinator.md) Spiderpool 内置一个叫 `coordinator` 的 CNI meta-plugin, 它在 Main CNI 被调用之后再工作,它主要提供以下几个主要功能: diff --git a/docs/concepts/coordinator.md b/docs/concepts/coordinator.md index 20f604cfc9..f80c504cd5 100644 --- a/docs/concepts/coordinator.md +++ b/docs/concepts/coordinator.md @@ -10,7 +10,7 @@ Spiderpool incorporates a CNI meta-plugin called `coordinator` that works after - Check the reachability of Pod gateways - Support fixed Mac address prefixes for Pods -Note: If your OS(such as Fedora, CentOS, etc.) uses NetworkManager, highly recommend configuring following configuration file at `/etc/NetworkManager/conf.d/spidernet.conf` to +Note: If your OS(such as Fedora, CentOS, etc.) uses NetworkManager, highly recommend configuring following configuration file at `/etc/NetworkManager/conf.d/spidernet.conf` to prevent interference from NetworkManager with veth interfaces created through `coordinator`: ```shell diff --git a/docs/usage/network-topology-zh_CN.md b/docs/usage/network-topology-zh_CN.md index af57ebd070..2e932b5394 100644 --- a/docs/usage/network-topology-zh_CN.md +++ b/docs/usage/network-topology-zh_CN.md @@ -166,6 +166,7 @@ spec: { "ipv4": ["test-ippool-6", "test-ippool-7"] } + v1.multus-cni.io/default-network: kube-system/macvlan-conf labels: app: test-app spec: diff --git a/docs/usage/network-topology.md b/docs/usage/network-topology.md index 3fa391ab58..fff9e33324 100644 --- a/docs/usage/network-topology.md +++ b/docs/usage/network-topology.md @@ -171,6 +171,7 @@ spec: { "ipv4": ["test-ippool-6", "test-ippool-7"] } + v1.multus-cni.io/default-network: kube-system/macvlan-conf labels: app: test-app spec: diff --git a/docs/usage/route-zh_CN.md b/docs/usage/route-zh_CN.md index 3a1806b6b8..291884c80b 100644 --- a/docs/usage/route-zh_CN.md +++ b/docs/usage/route-zh_CN.md @@ -26,7 +26,7 @@ spec: 我们也可为 SpiderIPPool 资源配置路由(`spec.routes`),创建 Pod 时会继承该路由: -> - 当 SpiderIPPool 资源配置了网关地址后,请勿为路由字段配置默认路由。 +> - 当 SpiderIPPool 资源配置了网关地址后,请勿为路由字段配置默认路由。 > - `dst` 和 `gw` 字段都为必填 ```yaml diff --git a/pkg/coordinatormanager/coordinator_validate.go b/pkg/coordinatormanager/coordinator_validate.go index 6f69859a36..f42e7beaaf 100644 --- a/pkg/coordinatormanager/coordinator_validate.go +++ b/pkg/coordinatormanager/coordinator_validate.go @@ -132,11 +132,7 @@ func validateCoordinatorExtraCIDR(cidrs []string) *field.Error { } func validateCoordinatorPodMACPrefix(prefix *string) *field.Error { - if prefix == nil { - return nil - } - - if *prefix == "" { + if prefix == nil || *prefix == "" { return nil } diff --git a/pkg/gcmanager/scanAll_IPPool.go b/pkg/gcmanager/scanAll_IPPool.go index cfddabcd49..82bab960e8 100644 --- a/pkg/gcmanager/scanAll_IPPool.go +++ b/pkg/gcmanager/scanAll_IPPool.go @@ -76,12 +76,11 @@ func (s *SpiderGC) monitorGCSignal(ctx context.Context) { // executeScanAll scans the whole pod and whole IPPoolList func (s *SpiderGC) executeScanAll(ctx context.Context) { poolList, err := s.ippoolMgr.ListIPPools(ctx, constant.UseCache) - if nil != err { + if err != nil { if apierrors.IsNotFound(err) { logger.Sugar().Warnf("scan all failed, ippoolList not found!") return } - logger.Sugar().Errorf("scan all failed: '%v'", err) return } @@ -137,7 +136,7 @@ func (s *SpiderGC) executeScanAll(ctx context.Context) { flagGCEndpoint = false goto GCIP } else { - scanAllLogger.Sugar().Errorf("pod %s/%s does not exist and failed to get endpoint %s/%s, ignore handle IP %s and endpoint, error: '%v'", podNS, podName, podNS, podName, poolIP, err) + scanAllLogger.Sugar().Errorf("pod %s/%s does not exist and failed to get endpoint %s/%s, ignore handle IP %s and endpoint, error: '%v'", podNS, podName, podNS, podName, poolIP, endpointErr) continue } } else { @@ -157,7 +156,7 @@ func (s *SpiderGC) executeScanAll(ctx context.Context) { } } } else { - scanAllLogger.Sugar().Errorf("failed to get pod from kubernetes, error '%v'", err) + scanAllLogger.Sugar().Errorf("failed to get pod from kubernetes, error '%v'", podErr) continue } } diff --git a/pkg/ip/cidr.go b/pkg/ip/cidr.go index 68c01bdb59..173a1a4bbb 100644 --- a/pkg/ip/cidr.go +++ b/pkg/ip/cidr.go @@ -17,8 +17,10 @@ func ParseCIDR(version types.IPVersion, subnet string) (*net.IPNet, error) { if err := IsCIDR(version, subnet); err != nil { return nil, err } - _, ipNet, _ := net.ParseCIDR(subnet) - + _, ipNet, err := net.ParseCIDR(subnet) + if err != nil { + return nil, fmt.Errorf("failed to parse CIDR '%s': %v", subnet, err) + } return ipNet, nil }