Skip to content
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

Check if kubeconfig exists before dumping resources #16205

Merged
merged 1 commit into from
Jan 3, 2024
Merged
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
11 changes: 6 additions & 5 deletions cmd/kops/toolbox_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ func RunToolboxDump(ctx context.Context, f commandutils.Factory, out io.Writer,

var nodes corev1.NodeList

config, err := clientGetter.ToRESTConfig()
kubeConfig, err := clientGetter.ToRESTConfig()
if err != nil {
klog.Warningf("cannot load kubeconfig settings for %q: %v", contextName, err)
} else {
k8sClient, err := kubernetes.NewForConfig(config)
k8sClient, err := kubernetes.NewForConfig(kubeConfig)
if err != nil {
klog.Warningf("cannot build kube client for %q: %v", contextName, err)
} else {
Expand Down Expand Up @@ -227,16 +227,17 @@ func RunToolboxDump(ctx context.Context, f commandutils.Factory, out io.Writer,
if err := dumper.DumpAllNodes(ctx, nodes, additionalIPs, additionalPrivateIPs); err != nil {
return fmt.Errorf("error dumping nodes: %v", err)
}
if options.K8sResources {
dumper, err := dump.NewResourceDumper(config, options.Output, options.Dir)

if kubeConfig != nil && options.K8sResources {
dumper, err := dump.NewResourceDumper(kubeConfig, options.Output, options.Dir)
if err != nil {
return fmt.Errorf("error creating resource dumper: %w", err)
}
if err := dumper.DumpResources(ctx); err != nil {
return fmt.Errorf("error dumping resources: %w", err)
}

logDumper, err := dump.NewPodLogDumper(config, options.Dir)
logDumper, err := dump.NewPodLogDumper(kubeConfig, options.Dir)
if err != nil {
return fmt.Errorf("error creating pod log dumper: %w", err)
}
Expand Down
Loading