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

Commit

Permalink
add flags for kubeconfig path
Browse files Browse the repository at this point in the history
  • Loading branch information
pingles committed Jun 15, 2017
1 parent 867112d commit 9e35784
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
bin/
sqs-autoscaler-controller
27 changes: 23 additions & 4 deletions main.go
Expand Up @@ -9,25 +9,44 @@ import (
log "github.com/Sirupsen/logrus"
"github.com/uswitch/sqs-autoscaler-controller/pkg/scaler"
"github.com/uswitch/sqs-autoscaler-controller/pkg/tpr"
"gopkg.in/alecthomas/kingpin.v2"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)

const (
kubecfg = "/home/tom/.kube/config"
)

type options struct {
kubeconfig string
}

func createClient(opts *options) (*kubernetes.Clientset, *rest.Config, error) {
config, err := clientcmd.BuildConfigFromFlags("", kubecfg)
if err != nil {
return nil, nil, err
}
c, err := kubernetes.NewForConfig(config)
if err != nil {
return nil, nil, err
}
return c, config, nil
}

func main() {
// log.SetLevel(log.DebugLevel)
opts := &options{}
kingpin.Flag("kubeconfig", "Path to kubeconfig.").StringVar(&opts.kubeconfig)

stopChan := make(chan os.Signal)
signal.Notify(stopChan, os.Interrupt)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

config, err := clientcmd.BuildConfigFromFlags("", kubecfg)
c, err := kubernetes.NewForConfig(config)
c, config, err := createClient(opts)
if err != nil {
log.Fatalf("Error creating client: %s", err)
log.Fatalf("error creating client: %s", err)
}

err = tpr.EnsureResource(c)
Expand Down

0 comments on commit 9e35784

Please sign in to comment.