Skip to content

Commit

Permalink
stage
Browse files Browse the repository at this point in the history
  • Loading branch information
oldthreefeng committed Sep 3, 2020
1 parent c6a026a commit f63f9ef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
14 changes: 5 additions & 9 deletions install/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ type ExecFlag struct {
Src string
Cmd string
Label string
Nodes []string
// map["hostname"] -> ip
Nodes map[string]string
SealConfig
}

Expand Down Expand Up @@ -63,17 +64,12 @@ func (e *ExecFlag) execByNode() {
wg.Wait()
}

func (e *ExecFlag) getNodesByLabel() error {
func (e *ExecFlag) getNodesByLabel() ([]string, error) {
k8sClient, err := k8s.NewClient(k8s.KubeDefaultConfigPath, nil)
if err != nil {
return err
return nil, err
}
nodes, err := k8s.GetNodeByLabel(k8sClient, e.Label)
if err != nil {
return err
}
e.Nodes = nodes
return nil
return k8s.GetNodeByLabel(k8sClient, e.Label)
}

// execByNode is exec cmd in Node
Expand Down
17 changes: 13 additions & 4 deletions k8s/node.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package k8s


import (
"context"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/transport"
"k8s.io/client-go/util/homedir"
"path/filepath"
"strings"
"time"
)
Expand All @@ -25,10 +27,17 @@ const (

func NewClient(kubeConfigPath string, k8sWrapTransport transport.WrapperFunc) (*kubernetes.Clientset, error) {
// use the current admin kubeconfig
config, err := clientcmd.BuildConfigFromFlags("", kubeConfigPath)
if err != nil {
return nil, err
var config *rest.Config
var err error
if home := homedir.HomeDir(); home != "" && kubeConfigPath != "" {
kubeConfigPath = filepath.Join(home, ".kube", "config")
}
if config, err = rest.InClusterConfig(); err != nil {
if config, err = clientcmd.BuildConfigFromFlags("", kubeConfigPath); err != nil {
return nil, err
}
}

if k8sWrapTransport != nil {
config.WrapTransport = k8sWrapTransport
}
Expand Down

0 comments on commit f63f9ef

Please sign in to comment.