Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
cli/cmd: use NewClientset to construct Kubernetes clientset
Browse files Browse the repository at this point in the history
NewClientsetFromFile is now deprecated, as we want to gradually switch
to loading kubeconfig file from the file content rather than from the
file path.

This commit preserves existing functionality, but uses new function,
which should simplify the change later for loading from the file
content.

Signed-off-by: Mateusz Gozdek <mateusz@kinvolk.io>
  • Loading branch information
invidian committed Jun 30, 2020
1 parent bdfac34 commit f74c7f7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
8 changes: 7 additions & 1 deletion cli/cmd/cluster-apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package cmd

import (
"fmt"
"io/ioutil"

"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -125,7 +126,12 @@ func runClusterApply(cmd *cobra.Command, args []string) {
}

func verifyCluster(kubeconfigPath string, expectedNodes int) error {
cs, err := k8sutil.NewClientsetFromFile(kubeconfigPath)
kubeconfig, err := ioutil.ReadFile(kubeconfigPath) // #nosec G304
if err != nil {
return errors.Wrapf(err, "failed to read kubeconfig file")
}

cs, err := k8sutil.NewClientset(kubeconfig)
if err != nil {
return errors.Wrapf(err, "failed to set up clientset")
}
Expand Down
8 changes: 7 additions & 1 deletion cli/cmd/component-delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package cmd
import (
"context"
"fmt"
"io/ioutil"
"strings"

log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -167,7 +168,12 @@ func deleteHelmRelease(c components.Component, kubeconfig string, deleteNSBool b
}

func deleteNS(ns string, kubeconfig string) error {
cs, err := k8sutil.NewClientsetFromFile(kubeconfig)
kubeconfigContent, err := ioutil.ReadFile(kubeconfig) // #nosec G304
if err != nil {
return fmt.Errorf("failed to read kubeconfig file: %v", err)
}

cs, err := k8sutil.NewClientset(kubeconfigContent)
if err != nil {
return err
}
Expand Down
9 changes: 8 additions & 1 deletion cli/cmd/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package cmd

import (
"fmt"
"io/ioutil"
"os"
"text/tabwriter"

Expand Down Expand Up @@ -47,7 +48,13 @@ func runHealth(cmd *cobra.Command, args []string) {
if err != nil {
contextLogger.Fatalf("Error in finding kubeconfig file: %s", err)
}
cs, err := k8sutil.NewClientsetFromFile(kubeconfig)

kubeconfigContent, err := ioutil.ReadFile(kubeconfig) // #nosec G304
if err != nil {
contextLogger.Fatalf("Failed to read kubeconfig file: %v", err)
}

cs, err := k8sutil.NewClientset(kubeconfigContent)
if err != nil {
contextLogger.Fatalf("Error in creating setting up Kubernetes client: %q", err)
}
Expand Down

0 comments on commit f74c7f7

Please sign in to comment.