8000 Add option to preserve collector pod by Lyt99 · Pull Request #56 · alibaba/kubeskoop · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add option to preserve collector pod #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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