From 2eaf3820ef2631965f7e5ad2c67ed17e501a0fec Mon Sep 17 00:00:00 2001 From: "bingshen.wbs" Date: Tue, 3 Dec 2024 15:07:19 +0800 Subject: [PATCH] omit pod erdma resource when daemon not enable erdma Signed-off-by: bingshen.wbs --- pkg/k8s/k8s.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/k8s/k8s.go b/pkg/k8s/k8s.go index 2ddc78ca..0434defc 100644 --- a/pkg/k8s/k8s.go +++ b/pkg/k8s/k8s.go @@ -167,6 +167,7 @@ func NewK8S(daemonMode string, globalConfig *daemon.Config) (Kubernetes, error) broadcaster: broadcaster, recorder: recorder, Locker: &sync.RWMutex{}, + enableErdma: globalConfig.EnableERDMA, } svcCIDR := &types.IPNetSet{} @@ -204,6 +205,7 @@ type k8s struct { node *corev1.Node svcCIDR *types.IPNetSet statefulWorkloadKindSet sets.Set[string] + enableErdma bool sync.Locker } @@ -350,7 +352,7 @@ func (k *k8s) GetPod(ctx context.Context, namespace, name string, cache bool) (* } return nil, err } - podInfo := convertPod(k.mode, k.statefulWorkloadKindSet, pod) + podInfo := convertPod(k.mode, k.enableErdma, k.statefulWorkloadKindSet, pod) item := &storageItem{ Pod: podInfo, } @@ -393,7 +395,7 @@ func (k *k8s) GetLocalPods() ([]*daemon.PodInfo, error) { continue } - podInfo := convertPod(k.mode, k.statefulWorkloadKindSet, &pod) + podInfo := convertPod(k.mode, k.enableErdma, k.statefulWorkloadKindSet, &pod) ret = append(ret, podInfo) } @@ -534,7 +536,7 @@ func podNetworkType(daemonMode string, pod *corev1.Pod) string { panic(fmt.Errorf("unknown daemon mode %s", daemonMode)) } -func convertPod(daemonMode string, statefulWorkloadKindSet sets.Set[string], pod *corev1.Pod) *daemon.PodInfo { +func convertPod(daemonMode string, enableErdma bool, statefulWorkloadKindSet sets.Set[string], pod *corev1.Pod) *daemon.PodInfo { pi := &daemon.PodInfo{ Name: pod.Name, Namespace: pod.Namespace, @@ -588,7 +590,9 @@ func convertPod(daemonMode string, statefulWorkloadKindSet sets.Set[string], pod } } - pi.ERdma = isERDMA(pod) + if enableErdma { + pi.ERdma = isERDMA(pod) + } // determine whether pod's IP will stick 5 minutes for a reuse, priorities as below, // 1. pod has a positive pod-ip-reservation annotation