Skip to content

Commit

Permalink
delete infinite recursion in helm docs (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
EItanya authored Dec 3, 2020
1 parent e5c7f8e commit b9d9ae4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
github.com/go-openapi/spec v0.19.4 // indirect
github.com/gogo/protobuf v1.3.1
github.com/golang/mock v1.4.3
github.com/golang/protobuf v1.4.2
github.com/google/go-github/v32 v32.0.0
github.com/google/uuid v1.1.1
github.com/goph/emperror v0.17.1
Expand Down Expand Up @@ -55,6 +56,7 @@ require (
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
google.golang.org/api v0.29.0
google.golang.org/grpc v1.30.0
google.golang.org/protobuf v1.25.0
gopkg.in/AlecAivazis/survey.v1 v1.8.2
gopkg.in/square/go-jose.v1 v1.1.2 // indirect
gopkg.in/src-d/go-git.v4 v4.10.0
Expand Down
13 changes: 13 additions & 0 deletions installutils/helmchart/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"fmt"
"reflect"
"strings"
"unicode"

"google.golang.org/protobuf/reflect/protoreflect"
)

type HelmValue struct {
Expand Down Expand Up @@ -71,6 +74,16 @@ func docReflect(addValue addValue, path []string, desc string, typ reflect.Type,
for i := 0; i < typ.NumField(); i++ {
field := typ.Field(i)
jsonTag := field.Tag.Get("json")
// golang/proto v4 creates infinite reflect loops, need to s
// kip the private fields
message := reflect.TypeOf((*interface{ ProtoReflect() protoreflect.Message })(nil)).Elem()
if reflect.PtrTo(typ).Implements(message) {
// Check if field is private
firstChar := field.Name[0]
if !unicode.IsUpper(rune(firstChar)) {
continue
}
}
parts := strings.Split(jsonTag, ",")
jsonName := parts[0]
desc := field.Tag.Get("desc")
Expand Down
11 changes: 7 additions & 4 deletions installutils/helmchart/docs_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package helmchart_test

import (
"github.com/golang/protobuf/ptypes/wrappers"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

. "github.com/solo-io/k8s-utils/installutils/helmchart"
)

type Config struct {
Namespace *Namespace `json:"namespace,omitempty" desc:"create namespace"`
Array []Array `json:"array,omitempty"`
Bool bool `json:"booleanValue,omitempty"`
Complex Complex `json:"complex,omitempty"`
Namespace *Namespace `json:"namespace,omitempty" desc:"create namespace"`
Array []Array `json:"array,omitempty"`
Bool bool `json:"booleanValue,omitempty"`
Complex Complex `json:"complex,omitempty"`
Proto *wrappers.BoolValue `json:"proto,omitempty"`
}

type Complex struct {
Expand Down Expand Up @@ -61,6 +63,7 @@ var _ = Describe("Docs", func() {
DefaultValue: "yes",
Description: "",
},
{Key: "proto.value", Type: "bool", DefaultValue: "", Description: ""},
}

Expect(expectedDocs).To(Equal(docDesc))
Expand Down

0 comments on commit b9d9ae4

Please sign in to comment.