Skip to content

Commit

Permalink
Handle kubeconfig correct for proxy mode
Browse files Browse the repository at this point in the history
  • Loading branch information
wonderix committed Jan 10, 2020
1 parent 210ab67 commit 93998b9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pkg/shalm/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"strings"
Expand Down Expand Up @@ -109,9 +110,17 @@ func (k *k8sImpl) IsNotExist(err error) bool {
return strings.Contains(err.Error(), "NotFound")
}

// IsNotExist -
// KubeConfigContent -
func (k *k8sImpl) KubeConfigContent() *string {
return k.kubeconfig
if k.kubeconfig == nil {
return nil
}
data, err := ioutil.ReadFile(*k.kubeconfig)
if err != nil {
return nil
}
content := string(data)
return &content
}

func run(cmd *exec.Cmd) error {
Expand Down
12 changes: 12 additions & 0 deletions pkg/shalm/k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"io"

. "github.com/kramerul/shalm/pkg/shalm/test"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
Expand Down Expand Up @@ -37,6 +38,17 @@ var _ = Describe("k8s", func() {
Expect(err).NotTo(HaveOccurred())
Expect(writer.String()).To(Equal("get kind name -o json\n"))
})
It("KubeConfigContent works", func() {
dir := NewTestDir()
defer dir.Remove()
dir.MkdirAll("chart2/templates", 0755)
dir.WriteFile("kubeconfig", []byte("hello"), 0644)
kubeconfig := dir.Join("kubeconfig")
k8s := k8sImpl{kubeconfig: &kubeconfig}
content := k8s.KubeConfigContent()
Expect(content).NotTo(BeNil())
Expect(*content).To(Equal("hello"))
})
// It("watch works", func() {
// reader, err := k8s.Watch("kind", "name", &K8sOptions{})
// Expect(err).NotTo(HaveOccurred())
Expand Down

0 comments on commit 93998b9

Please sign in to comment.