Skip to content

Commit

Permalink
Merge pull request #56 from Lyt99/preserve-collector-pod
Browse files Browse the repository at this point in the history
Add option to preserve collector pod
  • Loading branch information
BSWANG authored Jun 29, 2023
2 parents 171e50e + 2ab1921 commit fe3b5f3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
10 changes: 6 additions & 4 deletions pkg/skoop/collector/manager/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@ func init() {
}

type SimplePodCollectorConfig struct {
Image string
CollectorNamespace string
WaitInterval time.Duration
WaitTimeout time.Duration
Image string
CollectorNamespace string
WaitInterval time.Duration
WaitTimeout time.Duration
PreserveCollectorPod bool
}

func (cc *SimplePodCollectorConfig) BindFlags(fs *pflag.FlagSet) {
fs.StringVarP(&cc.Image, "collector-image", "", "kubeskoop/kubeskoop:v0.1.0", "Image used for collector.")
fs.StringVarP(&cc.CollectorNamespace, "collector-namespace", "", "skoop", "Namespace where collector pods in.")
fs.DurationVarP(&cc.WaitInterval, "collector-pod-wait-interval", "", 2*time.Second, "Collector pod running check interval.")
fs.DurationVarP(&cc.WaitTimeout, "collector-pod-wait-timeout", "", 120*time.Second, "Collector pod running check timeout.")
fs.BoolVarP(&cc.PreserveCollectorPod, "preserve-collector-pod", "", false, "Preserve collector pod after diagnosis complete.")
}

func (cc *SimplePodCollectorConfig) Validate() error {
Expand Down
45 changes: 25 additions & 20 deletions pkg/skoop/collector/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,17 @@ type SimplePodCollectorManagerOptions struct {
}

type simplePodCollectorManager struct {
image string
namespace string
client *kubernetes.Clientset
restConfig *rest.Config
ipCache *k8s.IPCache
cache map[string]*k8s.NodeNetworkStackDump
nodeCache map[string]*k8s.NodeInfo
podCache map[string]*k8s.Pod
waitInterval time.Duration
waitTimeout time.Duration
image string
namespace string
client *kubernetes.Clientset
restConfig *rest.Config
ipCache *k8s.IPCache
cache map[string]*k8s.NodeNetworkStackDump
nodeCache map[string]*k8s.NodeInfo
podCache map[string]*k8s.Pod
waitInterval time.Duration
waitTimeout time.Duration
preserveCollectorPod bool
}

func NewSimplePodCollectorManager(ctx *ctx.Context) (collector.Manager, error) {
Expand All @@ -74,16 +75,17 @@ func NewSimplePodCollectorManager(ctx *ctx.Context) (collector.Manager, error) {
}

return &simplePodCollectorManager{
image: Config.SimplePodCollectorConfig.Image,
namespace: Config.SimplePodCollectorConfig.CollectorNamespace,
client: ctx.KubernetesClient(),
restConfig: ctx.KubernetesRestClient(),
ipCache: ctx.ClusterConfig().IPCache,
cache: map[string]*k8s.NodeNetworkStackDump{},
nodeCache: map[string]*k8s.NodeInfo{},
podCache: map[string]*k8s.Pod{},
waitInterval: Config.SimplePodCollectorConfig.WaitInterval,
waitTimeout: Config.SimplePodCollectorConfig.WaitTimeout,
image: Config.SimplePodCollectorConfig.Image,
namespace: Config.SimplePodCollectorConfig.CollectorNamespace,
client: ctx.KubernetesClient(),
restConfig: ctx.KubernetesRestClient(),
ipCache: ctx.ClusterConfig().IPCache,
cache: map[string]*k8s.NodeNetworkStackDump{},
nodeCache: map[string]*k8s.NodeInfo{},
podCache: map[string]*k8s.Pod{},
waitInterval: Config.SimplePodCollectorConfig.WaitInterval,
waitTimeout: Config.SimplePodCollectorConfig.WaitTimeout,
preserveCollectorPod: Config.SimplePodCollectorConfig.PreserveCollectorPod,
}, nil
}

Expand Down Expand Up @@ -256,6 +258,9 @@ func (m *simplePodCollectorManager) collectNodeStackDump(nodeName string) (*k8s.
}

defer func() {
if m.preserveCollectorPod {
return
}
err := m.deleteCollectorPod(nodeName)
if err != nil {
klog.Errorf("failed delete collector pod: %s", err)
Expand Down

0 comments on commit fe3b5f3

Please sign in to comment.