Skip to content

Commit

Permalink
supplement IP GC ENV for various scenarios
Browse files Browse the repository at this point in the history
Signed-off-by: Icarus9913 <icaruswu66@qq.com>
  • Loading branch information
Icarus9913 committed Dec 25, 2023
1 parent 79870d7 commit 7a2c234
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 16 deletions.
8 changes: 5 additions & 3 deletions charts/spiderpool/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,12 @@ spec:
value: {{ .Values.spiderpoolController.httpPort | quote }}
- name: SPIDERPOOL_GC_IP_ENABLED
value: {{ .Values.ipam.gc.enabled | quote }}
- name: SPIDERPOOL_GC_TERMINATING_POD_IP_ENABLED
value: {{ .Values.ipam.gc.GcDeletingTimeOutPod.enabled | quote }}
- name: SPIDERPOOL_GC_TERMINATING_NODE_READY_POD_IP_ENABLED
value: {{ .Values.ipam.gc.enableGcDeletingTimeOutPodWithNodeReady | quote }}
- name: SPIDERPOOL_GC_TERMINATING_NODE_NOT_READY_POD_IP_ENABLED
value: {{ .Values.ipam.gc.enableGcDeletingTimeOutPodWithNodeNotReady | quote }}
- name: SPIDERPOOL_GC_ADDITIONAL_GRACE_DELAY
value: {{ .Values.ipam.gc.GcDeletingTimeOutPod.delay | quote }}
value: {{ .Values.ipam.gc.gcDeletingTimeOutPodDelay | quote }}
- name: SPIDERPOOL_GC_DEFAULT_INTERVAL_DURATION
value: {{ .Values.ipam.gc.gcAll.intervalInSecond | quote }}
- name: SPIDERPOOL_MULTUS_CONFIG_ENABLED
Expand Down
12 changes: 7 additions & 5 deletions charts/spiderpool/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ ipam:
## @param ipam.gc.gcAll.intervalInSecond the gc all interval duration
intervalInSecond: 600

GcDeletingTimeOutPod:
## @param ipam.gc.GcDeletingTimeOutPod.enabled enable retrieve IP for the pod who times out of deleting graceful period
enabled: true
## @param ipam.gc.enableGcDeletingTimeOutPodWithNodeReady enable reclaim IP for the pod who times out of deleting graceful period with its node ready
enableGcDeletingTimeOutPodWithNodeReady: true

## @param ipam.gc.GcDeletingTimeOutPod.delay the gc delay seconds after the pod times out of deleting graceful period
delay: 0
## @param ipam.gc.enableGcDeletingTimeOutPodWithNodeNotReady enable reclaim IP for the pod who times out of deleting graceful period with its node not ready
enableGcDeletingTimeOutPodWithNodeNotReady: true

## @param ipam.gc.gcDeletingTimeOutPodDelay the gc delay seconds after the pod times out of deleting graceful period
gcDeletingTimeOutPodDelay: 0

## @section grafanaDashboard parameters
##
Expand Down
6 changes: 5 additions & 1 deletion cmd/spiderpool-controller/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ var envInfo = []envConf{
{"SPIDERPOOL_PYROSCOPE_PUSH_SERVER_ADDRESS", "", false, &controllerContext.Cfg.PyroscopeAddress, nil, nil},

{"SPIDERPOOL_GC_IP_ENABLED", "true", true, nil, &gcIPConfig.EnableGCIP, nil},
{"SPIDERPOOL_GC_TERMINATING_POD_IP_ENABLED", "true", true, nil, &gcIPConfig.EnableGCForTerminatingPod, nil},
//{"SPIDERPOOL_GC_TERMINATING_POD_IP_ENABLED", "true", true, nil, &gcIPConfig.EnableGCForTerminatingPod, nil},

{"SPIDERPOOL_GC_TERMINATING_NODE_READY_POD_IP_ENABLED", "true", true, nil, &gcIPConfig.EnableGCForTerminatingPodWithNodeReady, nil},
{"SPIDERPOOL_GC_TERMINATING_NODE_NOT_READY_POD_IP_ENABLED", "true", true, nil, &gcIPConfig.EnableGCForTerminatingPodWithNodeNotReady, nil},

{"SPIDERPOOL_GC_IP_WORKER_NUM", "3", true, nil, nil, &gcIPConfig.ReleaseIPWorkerNum},
{"SPIDERPOOL_GC_CHANNEL_BUFFER", "5000", true, nil, nil, &gcIPConfig.GCIPChannelBuffer},
{"SPIDERPOOL_GC_MAX_PODENTRY_DB_CAP", "100000", true, nil, nil, &gcIPConfig.MaxPodEntryDatabaseCap},
Expand Down
1 change: 1 addition & 0 deletions cmd/spiderpool-controller/cmd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ func initGCManager(ctx context.Context) {
controllerContext.PodManager,
controllerContext.StsManager,
controllerContext.KubevirtManager,
controllerContext.NodeManager,
controllerContext.Leader,
)
if nil != err {
Expand Down
13 changes: 9 additions & 4 deletions pkg/gcmanager/gc_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ import (
"github.com/spidernet-io/spiderpool/pkg/kubevirtmanager"
"github.com/spidernet-io/spiderpool/pkg/limiter"
"github.com/spidernet-io/spiderpool/pkg/logutils"
"github.com/spidernet-io/spiderpool/pkg/nodemanager"
"github.com/spidernet-io/spiderpool/pkg/podmanager"
"github.com/spidernet-io/spiderpool/pkg/statefulsetmanager"
"github.com/spidernet-io/spiderpool/pkg/workloadendpointmanager"
)

type GarbageCollectionConfig struct {
EnableGCIP bool
EnableGCForTerminatingPod bool
EnableStatefulSet bool
EnableKubevirtStaticIP bool
EnableGCIP bool
EnableGCForTerminatingPodWithNodeReady bool
EnableGCForTerminatingPodWithNodeNotReady bool
EnableStatefulSet bool
EnableKubevirtStaticIP bool

ReleaseIPWorkerNum int
GCIPChannelBuffer int
Expand Down Expand Up @@ -69,6 +71,7 @@ type SpiderGC struct {
podMgr podmanager.PodManager
stsMgr statefulsetmanager.StatefulSetManager
kubevirtMgr kubevirtmanager.KubevirtManager
nodeMgr nodemanager.NodeManager
leader election.SpiderLeaseElector

informerFactory informers.SharedInformerFactory
Expand All @@ -81,6 +84,7 @@ func NewGCManager(clientSet *kubernetes.Clientset, config *GarbageCollectionConf
podManager podmanager.PodManager,
stsManager statefulsetmanager.StatefulSetManager,
kubevirtMgr kubevirtmanager.KubevirtManager,
nodeMgr nodemanager.NodeManager,
spiderControllerLeader election.SpiderLeaseElector) (GCManager, error) {
if clientSet == nil {
return nil, fmt.Errorf("k8s ClientSet must be specified")
Expand Down Expand Up @@ -121,6 +125,7 @@ func NewGCManager(clientSet *kubernetes.Clientset, config *GarbageCollectionConf
podMgr: podManager,
stsMgr: stsManager,
kubevirtMgr: kubevirtMgr,
nodeMgr: nodeMgr,

leader: spiderControllerLeader,
gcLimiter: limiter.NewLimiter(limiter.LimiterConfig{}),
Expand Down
17 changes: 14 additions & 3 deletions pkg/gcmanager/pod_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/spidernet-io/spiderpool/pkg/constant"
"github.com/spidernet-io/spiderpool/pkg/lock"
"github.com/spidernet-io/spiderpool/pkg/logutils"
"github.com/spidernet-io/spiderpool/pkg/nodemanager"
"github.com/spidernet-io/spiderpool/pkg/types"
)

Expand Down Expand Up @@ -224,9 +225,19 @@ func (s *SpiderGC) buildPodEntry(oldPod, currentPod *corev1.Pod, deleted bool) (
}

if isBuildTerminatingPodEntry {
// disable for gc terminating pod
if !s.gcConfig.EnableGCForTerminatingPod {
logger.Sugar().Debugf("IP gc already turn off 'EnableGCForTerminatingPod' configuration, disacrd tracing pod '%s/%s'", currentPod.Namespace, currentPod.Name)
// check terminating Pod corresponding Node status
node, err := s.nodeMgr.GetNodeByName(ctx, currentPod.Spec.NodeName, constant.UseCache)
if nil != err {
return nil, fmt.Errorf("failed to get terminating Pod '%s/%s' corredponing Node '%s', error: %v", currentPod.Namespace, currentPod.Name, currentPod.Spec.NodeName)

Check failure on line 231 in pkg/gcmanager/pod_cache.go

View workflow job for this annotation

GitHub Actions / lint-golang

fmt.Errorf format %v reads arg #4, but call has 3 args
}
// disable for gc terminating pod with Node Ready
if nodemanager.IsNodeReady(node) && !s.gcConfig.EnableGCForTerminatingPodWithNodeReady {
logger.Sugar().Debugf("IP GC already turn off 'EnableGCForTerminatingPodWithNodeReady' configuration, disacrd tracing pod '%s/%s'", currentPod.Namespace, currentPod.Name)
return nil, nil
}
// disable for gc terminating pod with Node NotReady
if !nodemanager.IsNodeReady(node) && !s.gcConfig.EnableGCForTerminatingPodWithNodeNotReady {
logger.Sugar().Debugf("IP GC already turn off 'EnableGCForTerminatingPodWithNodeNotReady' configuration, disacrd tracing pod '%s/%s'", currentPod.Namespace, currentPod.Name)
return nil, nil
}

Expand Down
18 changes: 18 additions & 0 deletions pkg/nodemanager/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2023 Authors of spidernet-io
// SPDX-License-Identifier: Apache-2.0

package nodemanager

import corev1 "k8s.io/api/core/v1"

func IsNodeReady(node *corev1.Node) bool {
var readyCondition corev1.NodeCondition
for _, tmpCondition := range node.Status.Conditions {
if tmpCondition.Type == corev1.NodeReady {
readyCondition = tmpCondition
break
}
}

return readyCondition.Status == corev1.ConditionTrue
}
48 changes: 48 additions & 0 deletions pkg/nodemanager/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2023 Authors of spidernet-io
// SPDX-License-Identifier: Apache-2.0

package nodemanager

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var _ = Describe("NodeManager utils", Label("node_manager_utils_test"), func() {
Describe("IsNodeReady", func() {
var node *corev1.Node
BeforeEach(func() {
node = &corev1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "master",
},
Spec: corev1.NodeSpec{},
Status: corev1.NodeStatus{
Conditions: []corev1.NodeCondition{
{
Type: corev1.NodeMemoryPressure,
Status: corev1.ConditionFalse,
},
{
Type: corev1.NodeReady,
Status: corev1.ConditionTrue,
},
},
},
}
})

It("Node is ready", func() {
isNodeReady := IsNodeReady(node)
Expect(isNodeReady).To(BeTrue())
})

It("Node is not ready", func() {
node.Status.Conditions[1].Status = corev1.ConditionUnknown
isNodeReady := IsNodeReady(node)
Expect(isNodeReady).To(BeFalse())
})
})
})

0 comments on commit 7a2c234

Please sign in to comment.