Skip to content

Commit

Permalink
execute tests with tls (#64)
Browse files Browse the repository at this point in the history
* execute tests with tls
  • Loading branch information
a-thaler authored Apr 27, 2019
1 parent 3e1a912 commit d719497
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 21 deletions.
17 changes: 14 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 48 additions & 3 deletions internal/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import (
"fmt"
"net/http"
"net/url"
"os"
"os/exec"
"strings"

"github.com/helm/helm/pkg/tlsutil"
"github.com/kyma-incubator/kyma-cli/internal/net"
"github.com/pkg/errors"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -28,7 +32,33 @@ func New(settings *environment.EnvSettings, config *rest.Config) (*Client, error
if err != nil {
return nil, err
}
helmClient := helm.NewClient(helm.Host(settings.TillerHost), helm.ConnectTimeout(settings.TillerConnectionTimeout))
settings.TLSServerName = settings.TillerHost
settings.TLSCaCertFile = settings.Home.TLSCaCert()
settings.TLSCertFile = settings.Home.TLSCert()
settings.TLSKeyFile = settings.Home.TLSKey()

options := []helm.Option{helm.Host(settings.TillerHost), helm.ConnectTimeout(settings.TillerConnectionTimeout)}

if settings.TLSVerify || settings.TLSEnable {
tlsopts := tlsutil.Options{
ServerName: settings.TLSServerName,
KeyFile: settings.TLSKeyFile,
CertFile: settings.TLSCertFile,
InsecureSkipVerify: true,
}
if settings.TLSVerify {
tlsopts.CaCertFile = settings.TLSCaCertFile
tlsopts.InsecureSkipVerify = false
}
tlscfg, err := tlsutil.ClientConfig(tlsopts)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(2)
}
options = append(options, helm.WithTLS(tlscfg))
}
helmClient := helm.NewClient(options...)

return &Client{
Interface: helmClient,
forwarder: forwarder,
Expand All @@ -39,7 +69,6 @@ func setupTillerConnection(settings *environment.EnvSettings, config *rest.Confi
if settings.TillerHost != "" {
return nil, nil
}

roundTripper, upgrader, err := spdy.RoundTripperFor(config)
if err != nil {
return nil, err
Expand Down Expand Up @@ -70,7 +99,6 @@ func setupTillerConnection(settings *environment.EnvSettings, config *rest.Confi

stopChan, readyChan := make(chan struct{}, 1), make(chan struct{}, 1)
out, errOut := new(bytes.Buffer), new(bytes.Buffer)

port, err := net.GetAvailablePort()
if err != nil {
return nil, err
Expand Down Expand Up @@ -100,3 +128,20 @@ func (c *Client) Close() {
close(c.forwarder)
}
}

func GetHelmHome() (string, error) {
helmCmd := exec.Command("helm", "home")
helmHomeRaw, err := helmCmd.CombinedOutput()
if err != nil {
return "", nil
}

helmHome := strings.Replace(string(helmHomeRaw), "\n", "", -1)
if _, err := os.Stat(helmHome); os.IsNotExist(err) {
err = os.MkdirAll(helmHome, 0700)
if err != nil {
return "", err
}
}
return helmHome, nil
}
20 changes: 6 additions & 14 deletions pkg/kyma/cmd/install/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
"time"

"github.com/kyma-incubator/kyma-cli/pkg/kyma/core"

docker "github.com/fsouza/go-dockerclient"
"github.com/kyma-incubator/kyma-cli/internal/helm"
"github.com/kyma-incubator/kyma-cli/internal/minikube"
"github.com/pkg/errors"
yaml "gopkg.in/yaml.v2"
Expand Down Expand Up @@ -207,22 +207,14 @@ func (cmd *command) installTiller() error {
}

func (cmd *command) configureHelm() error {
helmCmd := exec.Command("helm", "home")
helmHomeRaw, err := helmCmd.CombinedOutput()
helmHome, err := helm.GetHelmHome()
if err != nil {
cmd.CurrentStep.LogError("Helm is not installed, will not configure it")
return nil
return err
}

helmHome := strings.Replace(string(helmHomeRaw), "\n", "", -1)
if _, err := os.Stat(helmHome); os.IsNotExist(err) {
err = os.MkdirAll(helmHome, 0700)
if err != nil {
cmd.CurrentStep.LogError("Unable to create helm home directory")
return err
}
if helmHome != "" {
cmd.CurrentStep.LogInfof("Helm not installed")
return nil
}

secret, err := cmd.Kubectl().RunCmd("-n", "kyma-installer", "--ignore-not-found=false", "get", "secret", "helm-secret", "-o", "yaml")
if err != nil {
return err
Expand Down
8 changes: 7 additions & 1 deletion pkg/kyma/cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/spf13/cobra"
"k8s.io/helm/pkg/helm"
"k8s.io/helm/pkg/helm/environment"
"k8s.io/helm/pkg/helm/helmpath"
helm_release "k8s.io/helm/pkg/proto/hapi/release"
)

Expand Down Expand Up @@ -46,7 +47,12 @@ func NewTestCmd(o *TestOptions) *cobra.Command {
}

func (o *TestOptions) Run() error {
helmConfig := &environment.EnvSettings{TillerConnectionTimeout: 300}
helmHome, err := kyma_helm.GetHelmHome()
if err != nil {
return err
}

helmConfig := &environment.EnvSettings{Debug: true, TillerConnectionTimeout: 300, TLSEnable: true, TLSVerify: false, Home: helmpath.Home(helmHome)}
kubeConfig, err := o.GetKubeconfig()
if err != nil {
return err
Expand Down

0 comments on commit d719497

Please sign in to comment.