Skip to content

Commit

Permalink
Make failed manifest parse be shown less breaking
Browse files Browse the repository at this point in the history
Relates to #328
  • Loading branch information
undera committed Apr 11, 2023
1 parent a0bf59e commit b1294cb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
16 changes: 14 additions & 2 deletions pkg/dashboard/handlers/helmHandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/testapigroup/v1"
"net/http"
"sort"
Expand Down Expand Up @@ -133,8 +134,19 @@ func (h *HelmHandler) Resources(c *gin.Context) {

res, err := objects.ParseManifests(rel.Orig.Manifest)
if err != nil {
_ = c.AbortWithError(http.StatusInternalServerError, err)
return
res = append(res, &v1.Carp{
TypeMeta: metav1.TypeMeta{Kind: "ManifestParseError"},
ObjectMeta: metav1.ObjectMeta{
Name: err.Error(),
},
Spec: v1.CarpSpec{},
Status: v1.CarpStatus{
Phase: "BrokenManifest",
Message: err.Error(),
},
})
//_ = c.AbortWithError(http.StatusInternalServerError, err)
//return
}

if c.Query("health") != "" { // we need to query k8s for health status
Expand Down
7 changes: 4 additions & 3 deletions pkg/dashboard/objects/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"helm.sh/helm/v3/pkg/release"
v1 "k8s.io/apimachinery/pkg/apis/testapigroup/v1"
"k8s.io/client-go/tools/clientcmd"
//"sigs.k8s.io/yaml"
)

type DataLayer struct {
Expand Down Expand Up @@ -113,20 +114,20 @@ func ParseManifests(out string) ([]*v1.Carp, error) {
}

if err != nil {
return nil, errorx.Decorate(err, "failed to parse manifest document #%d", len(res)+1)
return res, errorx.Decorate(err, "failed to parse manifest document #%d", len(res)+1)
}

// k8s libs uses only JSON tags defined, say hello to https://github.com/go-yaml/yaml/issues/424
// we can juggle it
jsoned, err := json.Marshal(tmp)
if err != nil {
return nil, err
return res, err
}

var doc v1.Carp
err = json.Unmarshal(jsoned, &doc)
if err != nil {
return nil, err
return res, err
}

if doc.Kind == "" {
Expand Down

0 comments on commit b1294cb

Please sign in to comment.