Skip to content

Commit

Permalink
Merge pull request #92 from calmkart/master
Browse files Browse the repository at this point in the history
MOD:delete the buildPath code and use k8s native. And add a configGetter struct.
  • Loading branch information
cjimti authored Nov 12, 2019
2 parents 8503882 + f1ff9d5 commit 58f1568
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 52 deletions.
19 changes: 15 additions & 4 deletions cmd/kubefwd/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth"
restclient "k8s.io/client-go/rest"
"k8s.io/apimachinery/pkg/api/errors"
)

var namespaces []string
Expand Down Expand Up @@ -125,8 +125,10 @@ Try:
cfgFilePath = flagCfgFilePath
}

// create a ConfigGetter
configGetter := fwdcfg.NewConfigGetter()
// build the ClientConfig
rawConfig, err := fwdcfg.GetClientConfig(cfgFilePath)
rawConfig, err := configGetter.GetClientConfig(cfgFilePath)
if err != nil {
log.Fatalf("Error in get rawConfig: %s\n", err.Error())
}
Expand Down Expand Up @@ -173,15 +175,21 @@ Try:

for i, ctx := range contexts {
// k8s REST config
restConfig, err := fwdcfg.GetRestConfig(cfgFilePath, ctx)
restConfig, err := configGetter.GetRestConfig(cfgFilePath, ctx)
if err != nil {
log.Fatalf("Error generating REST configuration: %s\n", err.Error())
}

// create the k8s REST client set
clientSet, err := kubernetes.NewForConfig(restConfig)
if err != nil {
log.Fatalf("Error creating k8s client: %s\n", err.Error())
log.Fatalf("Error creating k8s clientSet: %s\n", err.Error())
}

// create the k8s REST client
restClient, err := configGetter.GetRESTClient()
if err != nil {
log.Fatalf("Error creating k8s RestClient: %s\n", err.Error())
}

for ii, namespace := range namespaces {
Expand All @@ -193,6 +201,7 @@ Try:
ListOptions: listOptions,
Hostfile: hostFile,
ClientConfig: restConfig,
RESTClient: restClient,
// only use short name for the first namespace and context
ShortName: i < 1 && ii < 1,
Remote: i > 0,
Expand Down Expand Up @@ -239,6 +248,7 @@ type FwdServiceOpts struct {
ListOptions metav1.ListOptions
Hostfile *txeh.Hosts
ClientConfig *restclient.Config
RESTClient *restclient.RESTClient
ShortName bool
Remote bool
IpC byte
Expand Down Expand Up @@ -367,6 +377,7 @@ func fwdServices(opts FwdServiceOpts) error {
Out: publisher,
Config: opts.ClientConfig,
ClientSet: opts.ClientSet,
RESTClient: opts.RESTClient,
Context: opts.Context,
Namespace: pod.Namespace,
Service: svcName,
Expand Down
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ require (
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v0.0.5
github.com/txn2/txeh v1.2.1
k8s.io/api v0.0.0-20191031065753-b19d8caf39be
k8s.io/apimachinery v0.0.0-20191102025618-50aa20a7b23f
k8s.io/cli-runtime v0.0.0-20191102031428-d1199d98239f
k8s.io/client-go v0.0.0-20191101230044-e9766ae82012
k8s.io/api v0.0.0-20191108065827-59e77acf588f
k8s.io/apimachinery v0.0.0-20191108065633-c18f71bf2947
k8s.io/cli-runtime v0.0.0-20191108072024-9fe36560f3af
k8s.io/client-go v0.0.0-20191108070106-f8f007fd456c
k8s.io/kubectl v0.0.0-20191108073526-feacf2b3d48e
)
Loading

0 comments on commit 58f1568

Please sign in to comment.