Skip to content

Commit

Permalink
Better logging/ux for external errors (#89)
Browse files Browse the repository at this point in the history
* better logging and not exiting early on external errors for a single helm release

* fix error handling issue for detect-files with changes to yamlToStub()

* force a non yaml.TypeError into the testing

* fixing another test case with invalid yaml
  • Loading branch information
Luke Reed authored Jun 22, 2020
1 parent ab44b4f commit b2c2f6f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
6 changes: 6 additions & 0 deletions pkg/api/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package api
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -140,13 +141,18 @@ func jsonToStub(data []byte) ([]*Stub, error) {
func yamlToStub(data []byte) ([]*Stub, error) {
decoder := yaml.NewDecoder(bytes.NewReader(data))
var stubs []*Stub
var tError *yaml.TypeError
for {
stub := &Stub{}
err := decoder.Decode(stub)
if err != nil {
if err == io.EOF {
break
}
if errors.As(err, &tError) {
klog.Infof("skipping for invalid yaml in manifest: %s", err)
continue
}
return stubs, err
}
stubs = append(stubs, stub)
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/versions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func Test_yamlToStub(t *testing.T) {
},
{
name: "not yaml",
data: []byte("some text\nthat is not yaml"),
data: []byte("*."),
want: nil,
wantErr: true,
},
Expand Down Expand Up @@ -148,7 +148,7 @@ func Test_containsStub(t *testing.T) {
},
{
name: "not yaml",
data: []byte("some text\nthat is not yaml"),
data: []byte("*."),
want: nil,
wantErr: true,
},
Expand Down
8 changes: 6 additions & 2 deletions pkg/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
driverv2 "helm.sh/helm/pkg/storage/driver"
helmstoragev3 "helm.sh/helm/v3/pkg/storage"
driverv3 "helm.sh/helm/v3/pkg/storage/driver"
"k8s.io/klog"

"github.com/fairwindsops/pluto/pkg/api"
)
Expand Down Expand Up @@ -107,7 +108,8 @@ func (h *Helm) getReleasesVersionTwo() error {
}
deployed, err := helmClient.Deployed(release.Name)
if err != nil {
return fmt.Errorf("error determining most recent deployed for '%s'\n %w", release.Name, err)
klog.Infof("cannot determine most recent deployed for %s - %s", release.Name, err)
continue
}
if release.Version != deployed.Version {
continue
Expand Down Expand Up @@ -138,7 +140,8 @@ func (h *Helm) getReleasesVersionThree() error {
for _, release := range list {
deployed, err := helmClient.Deployed(release.Name)
if err != nil {
return fmt.Errorf("error determining most recent deployed for '%s'\n %w", release.Name, err)
klog.Infof("cannot determine most recent deployed for %s - %s", release.Name, err)
continue
}
if release.Version != deployed.Version {
continue
Expand All @@ -157,6 +160,7 @@ func (h *Helm) getReleasesVersionThree() error {

func (h *Helm) findVersions() error {
for _, release := range h.Releases {
klog.V(2).Infof("parsing release %s", release.Name)
outList, err := h.checkForAPIVersion([]byte(release.Manifest))
if err != nil {
return fmt.Errorf("error parsing release '%s'\n %w", release.Name, err)
Expand Down

0 comments on commit b2c2f6f

Please sign in to comment.