test
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package kubectl
|
||||
|
||||
import (
|
||||
// "fmt"
|
||||
"fmt"
|
||||
"strings"
|
||||
"errors"
|
||||
"os/exec"
|
||||
@@ -9,9 +9,9 @@ import (
|
||||
log "oc-deploy/log_wrapper"
|
||||
)
|
||||
|
||||
type KubeContext struct {
|
||||
Bin string // Chemin vers le binaire
|
||||
}
|
||||
// type KubeContext struct {
|
||||
// Bin string // Chemin vers le binaire
|
||||
// }
|
||||
|
||||
|
||||
type kubeConfig struct {
|
||||
@@ -40,9 +40,14 @@ type kubeConfigClusters struct {
|
||||
Cluster kubeConfigCluster `json:"cluster"`
|
||||
}
|
||||
|
||||
func (this KubeContext) GetCurrentContext() (string, error) {
|
||||
func (this KubectlCommand) GetCurrentContext() (string, error) {
|
||||
bin := this.Bin
|
||||
|
||||
cmd := exec.Command(this.Bin, "config", "current-context")
|
||||
msg := fmt.Sprintf("%s get config current-context", bin)
|
||||
log.Log().Debug().Msg(msg)
|
||||
|
||||
cmd_args := strings.Split(msg, " ")
|
||||
cmd := this.Exec(cmd_args[0], cmd_args[1:]...)
|
||||
stdout, err := cmd.CombinedOutput()
|
||||
|
||||
res := string(stdout)
|
||||
@@ -53,14 +58,23 @@ func (this KubeContext) GetCurrentContext() (string, error) {
|
||||
|
||||
// Current Context
|
||||
// namespace, server
|
||||
func (this KubeContext) GetContext() (string, string, string, error) {
|
||||
func (this KubectlCommand) GetContext() (string, string, string, error) {
|
||||
|
||||
cmd := exec.Command(this.Bin, "config", "view", "-o", "json")
|
||||
stdout, _ := cmd.CombinedOutput()
|
||||
bin := this.Bin
|
||||
|
||||
msg := fmt.Sprintf("%s config view -o json", bin)
|
||||
log.Log().Debug().Msg(msg)
|
||||
|
||||
cmd_args := strings.Split(msg, " ")
|
||||
cmd := this.Exec(cmd_args[0], cmd_args[1:]...)
|
||||
stdout, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return "", "", "", errors.New(string(stdout))
|
||||
}
|
||||
|
||||
var objmap kubeConfig
|
||||
|
||||
err := json.Unmarshal(stdout, &objmap)
|
||||
err = json.Unmarshal(stdout, &objmap)
|
||||
if err != nil {
|
||||
return "", "", "", err
|
||||
}
|
||||
@@ -85,7 +99,7 @@ func (this KubeContext) GetContext() (string, string, string, error) {
|
||||
return currentContext, currentNamespace, currentServer, nil
|
||||
}
|
||||
|
||||
func (this KubeContext) UseContext(newContext string) (error) {
|
||||
func (this KubectlCommand) UseContext(newContext string) (error) {
|
||||
|
||||
cmd := exec.Command(this.Bin, "config", "use-context", newContext)
|
||||
stdout, err := cmd.CombinedOutput()
|
||||
@@ -98,9 +112,14 @@ func (this KubeContext) UseContext(newContext string) (error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this KubeContext) Check() (error) {
|
||||
func (this KubectlCommand) Check() (error) {
|
||||
bin := this.Bin
|
||||
|
||||
cmd := exec.Command(this.Bin, "cluster-info")
|
||||
msg := fmt.Sprintf("%s cluster-info", bin)
|
||||
log.Log().Debug().Msg(msg)
|
||||
|
||||
cmd_args := strings.Split(msg, " ")
|
||||
cmd := this.Exec(cmd_args[0], cmd_args[1:]...)
|
||||
stdout, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
log.Log().Debug().Msg(string(stdout))
|
||||
|
||||
Reference in New Issue
Block a user