Skip to content

Commit

Permalink
Merge pull request #35 from caesarxuchao/parsing-kube-config-flag
Browse files Browse the repository at this point in the history
Allow passing in kubeconfig path
  • Loading branch information
k8s-ci-robot committed Aug 13, 2019
2 parents 508974b + 652f7fb commit 571636a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
23 changes: 19 additions & 4 deletions cmd/migrator/app/migrator.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package app

import (
"flag"
"fmt"
"log"
"net/http"
"os"

Expand All @@ -12,12 +14,17 @@ import (
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)

const (
migratorUserAgent = "storage-version-migration-migrator"
)

var (
kubeconfigPath = flag.String("kubeconfig", "", "absolute path to the kubeconfig file specifying the apiserver instance. If unspecified, fallback to in-cluster configuration")
)

func NewMigratorCommand() *cobra.Command {
return &cobra.Command{
Use: "kube-storage-migrator",
Expand All @@ -35,10 +42,18 @@ func Run(stopCh <-chan struct{}) error {
http.Handle("/metrics", promhttp.Handler())
go func() { http.ListenAndServe(":2112", nil) }()

// creates the in-cluster config
config, err := rest.InClusterConfig()
if err != nil {
return err
var err error
var config *rest.Config
if *kubeconfigPath != "" {
config, err = clientcmd.BuildConfigFromFlags("", *kubeconfigPath)
if err != nil {
log.Fatalf("Error initializing client config: %v for kubeconfig: %v", err.Error(), *kubeconfigPath)
}
} else {
config, err = rest.InClusterConfig()
if err != nil {
return err
}
}
dynamic, err := dynamic.NewForConfig(rest.AddUserAgent(config, migratorUserAgent))
if err != nil {
Expand Down
23 changes: 19 additions & 4 deletions cmd/trigger/app/trigger.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
package app

import (
"flag"
"fmt"
"log"
"os"

migrationclient "github.com/kubernetes-sigs/kube-storage-version-migrator/pkg/clients/clientset"
"github.com/kubernetes-sigs/kube-storage-version-migrator/pkg/trigger"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)

const (
triggerUserAgent = "storage-version-migration-trigger"
)

var (
kubeconfigPath = flag.String("kubeconfig", "", "absolute path to the kubeconfig file specifying the apiserver instance. If unspecified, fallback to in-cluster configuration")
)

func NewTriggerCommand() *cobra.Command {
return &cobra.Command{
Use: "kube-storage-migrator-trigger",
Expand All @@ -32,10 +39,18 @@ func NewTriggerCommand() *cobra.Command {
}

func Run(stopCh <-chan struct{}) error {
// creates the in-cluster config
config, err := rest.InClusterConfig()
if err != nil {
return err
var err error
var config *rest.Config
if *kubeconfigPath != "" {
config, err = clientcmd.BuildConfigFromFlags("", *kubeconfigPath)
if err != nil {
log.Fatalf("Error initializing client config: %v for kubeconfig: %v", err.Error(), *kubeconfigPath)
}
} else {
config, err = rest.InClusterConfig()
if err != nil {
return err
}
}
migration, err := migrationclient.NewForConfig(rest.AddUserAgent(config, triggerUserAgent))
if err != nil {
Expand Down

0 comments on commit 571636a

Please sign in to comment.