Skip to content

Commit

Permalink
catch errors from helm client (#65)
Browse files Browse the repository at this point in the history
* not hiding errors sent from helm client

Signed-off-by: Luke Reed <luke@lreed.net>

* testing added for helm client receiving an error

Signed-off-by: Luke Reed <luke@lreed.net>
  • Loading branch information
Luke Reed authored Apr 22, 2020
1 parent 9753d9d commit b7e65c1
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ func (h *Helm) getManifestsVersionTwo() error {
}
hcm := driverv2.NewConfigMaps(h.Kube.Client.CoreV1().ConfigMaps(""))
helmClient := helmstoragev2.Init(hcm)
list, _ := helmClient.ListDeployed()
list, err := helmClient.ListDeployed()
if err != nil {
return err
}
for _, release := range list {
outList, err := checkForAPIVersion([]byte(release.Manifest))
if err != nil {
Expand All @@ -88,7 +91,10 @@ func (h *Helm) getManifestsVersionThree() error {
}
hs := driverv3.NewSecrets(h.Kube.Client.CoreV1().Secrets(""))
helmClient := helmstoragev3.Init(hs)
list, _ := helmClient.ListDeployed()
list, err := helmClient.ListDeployed()
if err != nil {
return err
}
for _, release := range list {
outList, err := checkForAPIVersion([]byte(release.Manifest))
if err != nil {
Expand Down
55 changes: 55 additions & 0 deletions pkg/helm/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"

"github.com/fairwindsops/pluto/pkg/api"
)
Expand Down Expand Up @@ -86,6 +88,14 @@ func newMockHelm(version string) *Helm {
}
}

func newBadKubeClient() (k *kube) {
conf := new(rest.Config)
conf.Host = "127.0.0.1:9999"
k = new(kube)
k.Client, _ = kubernetes.NewForConfig(conf)
return
}

func Test_checkForAPIVersion(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -205,6 +215,51 @@ func TestHelm_getManifestsVersionThree(t *testing.T) {
}
}

func TestHelm_getManifest_badClient(t *testing.T) {
tests := []struct {
name string
helmVersion string
wantErr bool
errMessage string
secret *v1.Secret
want []*api.Output
}{
{
name: "two - bad client",
helmVersion: "2",
wantErr: true,
errMessage: "helm 3 function called without helm 3 version set",
},
{
name: "three - bad client",
helmVersion: "3",
wantErr: true,
errMessage: "helm 3 function called without helm 3 version set",
},
}

for _, tt := range tests {
h := &Helm{
Version: tt.helmVersion,
Kube: newBadKubeClient(),
}
t.Run(tt.name, func(t *testing.T) {
var err error
switch tt.helmVersion {
case "2":
err = h.getManifestsVersionTwo()
case "3":
err = h.getManifestsVersionThree()
}
if tt.wantErr {
assert.Error(t, err)
assert.Contains(t, err.Error(), "connect: connection refused")
return
}
})
}
}

func TestHelm_FindVersions(t *testing.T) {
tests := []struct {
name string
Expand Down

0 comments on commit b7e65c1

Please sign in to comment.