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

Commit

Permalink
Make (un)register -a work with garden kubeconfig paths with "~".
Browse files Browse the repository at this point in the history
  • Loading branch information
i344628 authored and DockToFuture committed Nov 7, 2018
1 parent 4d2ab01 commit de05fe5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion cmd/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package cmd
import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/badoux/checkmail"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -85,7 +87,11 @@ var registerCmd = &cobra.Command{
var gardenConfig GardenConfig
GetGardenConfig(pathGardenConfig, &gardenConfig)
for _, cluster := range gardenConfig.GardenClusters {
config, err := clientcmd.BuildConfigFromFlags("", cluster.KubeConfig)
gardenKubeConfig := cluster.KubeConfig
if strings.Contains(gardenKubeConfig, "~") {
gardenKubeConfig = filepath.Clean(filepath.Join(HomeDir(), strings.Replace(gardenKubeConfig, "~", "", 1)))
}
config, err := clientcmd.BuildConfigFromFlags("", gardenKubeConfig)
checkError(err)
clientset, err := k8s.NewForConfig(config)
clusterRoleBinding, err := clientset.RbacV1().ClusterRoleBindings().Get("garden-administrators", metav1.GetOptions{})
Expand Down
8 changes: 7 additions & 1 deletion cmd/unregister.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package cmd
import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/badoux/checkmail"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -77,7 +79,11 @@ var unregisterCmd = &cobra.Command{
var gardenConfig GardenConfig
GetGardenConfig(pathGardenConfig, &gardenConfig)
for _, cluster := range gardenConfig.GardenClusters {
config, err := clientcmd.BuildConfigFromFlags("", cluster.KubeConfig)
gardenKubeConfig := cluster.KubeConfig
if strings.Contains(gardenKubeConfig, "~") {
gardenKubeConfig = filepath.Clean(filepath.Join(HomeDir(), strings.Replace(gardenKubeConfig, "~", "", 1)))
}
config, err := clientcmd.BuildConfigFromFlags("", gardenKubeConfig)
checkError(err)
clientset, err := k8s.NewForConfig(config)
checkError(err)
Expand Down

0 comments on commit de05fe5

Please sign in to comment.