Skip to content

Commit

Permalink
change the way of getting the restConfig
Browse files Browse the repository at this point in the history
Signed-off-by: Yannis Zarkadas <yanniszark@arrikto.com>
  • Loading branch information
yanniszark committed Sep 19, 2019
1 parent 9d15c2b commit ea977a8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
13 changes: 4 additions & 9 deletions bootstrap/pkg/apis/apps/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"io"
"io/ioutil"
"k8s.io/cli-runtime/pkg/genericclioptions"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -281,15 +282,9 @@ func KubeConfigPath() string {
}

// GetConfig returns rest.Config using $HOME/.kube/config
func GetConfig() *rest.Config {
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
loadingRules.ExplicitPath = KubeConfigPath()
overrides := &clientcmd.ConfigOverrides{}
config, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, overrides).ClientConfig()
if err != nil {
log.Warnf("could not open %v Error %v", loadingRules.ExplicitPath, err)
}
return config
func GetConfig() (*rest.Config, error) {
config, err := genericclioptions.NewConfigFlags().ToRESTConfig()
return config, err
}

// GetServerVersion returns the verison of the k8 api server
Expand Down
23 changes: 19 additions & 4 deletions bootstrap/pkg/kfapp/existing_arrikto/existing.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ func (existing *Existing) Generate(resources kftypesv3.ResourceEnum) error {

func (existing *Existing) Apply(resources kftypesv3.ResourceEnum) error {
// Apply extra components
config := kftypesv3.GetConfig()
config, err := kftypesv3.GetConfig()
if err != nil {
return internalError(errors.WithStack(err))
}

// Create namespace
// Get a K8s client
Expand Down Expand Up @@ -204,7 +207,11 @@ func (existing *Existing) Apply(resources kftypesv3.ResourceEnum) error {

func (existing *Existing) Delete(resources kftypesv3.ResourceEnum) error {

config := kftypesv3.GetConfig()
config, err := kftypesv3.GetConfig()
if err != nil {
return internalError(errors.WithStack(err))
}

kubeclient, err := client.New(config, client.Options{})
if err != nil {
return internalError(errors.WithStack(err))
Expand Down Expand Up @@ -445,7 +452,11 @@ func getLBAddress(kubeclient client.Client) (string, error) {
}

func applyManifests(manifests []manifest) error {
config := kftypesv3.GetConfig()
config, err := kftypesv3.GetConfig()
if err != nil {
return err
}

for _, m := range manifests {
log.Infof("Installing %s...", m.name)
err := utils.CreateResourceFromFile(
Expand All @@ -461,7 +472,11 @@ func applyManifests(manifests []manifest) error {
}

func deleteManifests(manifests []manifest) error {
config := kftypesv3.GetConfig()
config, err := kftypesv3.GetConfig()
if err != nil {
return err
}

for _, m := range manifests {
log.Infof("Deleting %s...", m.name)
if _, err := os.Stat(m.path); os.IsNotExist(err) {
Expand Down

0 comments on commit ea977a8

Please sign in to comment.