Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions changelog/v0.43.3/helm-minify-json-schems.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
changelog:
- type: FIX
issueLink: https://github.com/solo-io/gloo-mesh-enterprise/issues/20411
description: >
With this change, the `values.schema.json` file generated as part of the Helm chart generation is no longer
prettified. This drastically reduces the size of the file and minimizes the changes of the new maximum file size
limit [introduced by Helm](https://github.com/helm/helm/commit/e4da49785aa6e6ee2b86efd5dd9e43400318262b) in `v3.17.3`.
There are no functional changes. Human users can still prettify the file using external tools (e.g. `jq`) if necessary.
resolvesIssue: false
50 changes: 3 additions & 47 deletions codegen/render/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

"github.com/BurntSushi/toml"
"github.com/Masterminds/sprig/v3"
"github.com/golang/protobuf/protoc-gen-go/descriptor"
"github.com/iancoleman/orderedmap"
"github.com/iancoleman/strcase"
"github.com/solo-io/skv2/codegen/model"
Expand Down Expand Up @@ -208,42 +207,6 @@ func opVar(op model.Operator) string {
return opVar
}

/*
Find the proto messages for a given set of descriptors which need proto_deepcopoy funcs and whose types are not in
the API root package

return true if the descriptor corresponds to the Spec or the Status field
*/
func shouldDeepCopyExternalMessage(resources []model.Resource, desc *descriptor.DescriptorProto) bool {
for _, resource := range resources {
if resource.Spec.Type.Name == desc.GetName() ||
(resource.Status != nil && resource.Status.Type.Name == desc.GetName()) {
return true
}
}
return false
}

/*
Find the proto messages for a given set of descriptors which need proto_deepcopoy funcs.
The two cases are as follows:

1. One of the subfields has an external type
2. There is a oneof present
*/
func shouldDeepCopyInternalMessage(packageName string, desc *descriptor.DescriptorProto) bool {
var shouldGenerate bool
// case 1 above
for _, v := range desc.GetField() {
if v.TypeName != nil && !strings.Contains(v.GetTypeName(), packageName) {
shouldGenerate = true
break
}
}
// case 2 above
return len(desc.GetOneofDecl()) > 0 || shouldGenerate
}

// toYAML takes an interface, marshals it to yaml, and returns a string. It will
// always return a string, even on marshal error (empty string).
//
Expand Down Expand Up @@ -406,6 +369,8 @@ func (yc *yamlCommenter) addYamlComments(

nextValue = value.MapIndex(mapKeysByName[keyNode.Value])
}
default:
// nothing to do
}

// continue traversing the object
Expand Down Expand Up @@ -693,7 +658,7 @@ func toJSONSchema(values values.UserHelmValues) string {
panic(err)
}

return indentJson(string(jsonSchema))
return string(jsonSchema)
Copy link
Copy Markdown
Contributor Author

@marcogschmidt marcogschmidt Apr 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only actual change.

}

type customTypeMapper func(reflect.Type, *jsonschema.Schema) *jsonschema.Schema
Expand Down Expand Up @@ -1039,15 +1004,6 @@ func nestSchemaAtPath(schema *jsonschema.Schema, path ...string) *jsonschema.Sch
return schema
}

func indentJson(src string) string {
var buf bytes.Buffer
err := json.Indent(&buf, []byte(src), "", " ")
if err != nil {
panic(err)
}
return buf.String()
}

// reverse mutates a slice of strings to reverse the order.
func reverse(s []string) {
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
Expand Down
45 changes: 34 additions & 11 deletions codegen/render/funcs_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package render_test

import (
"bytes"
"encoding/json"
"fmt"
"reflect"
Expand All @@ -26,6 +27,17 @@ func prepareExpected(expected string) string {
return expected
}

// minifyJSON is a helper function for tests to remove whitespace from JSON strings
func minifyJSON(jsonStr string) (string, error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

json.Compact might work here https://pkg.go.dev/encoding/json#Compact

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pointer, I wasn't aware of that function! Just tested and it works like a charm 🎉

out := &bytes.Buffer{}
err := json.Compact(out, []byte(jsonStr))
if err != nil {
return "", err
}

return out.String(), nil
}

var _ = Describe("toYAMLWithComments", func() {

It("decodes yaml with the comments", func() {
Expand Down Expand Up @@ -454,7 +466,7 @@ var _ = Describe("toJSONSchema", func() {
Field1a string `json:"field1a" jsonschema:"title=field a,description=the field called a,example=aaa,example=bbb,default=a"`
}
result := render.ToJSONSchema(values.UserHelmValues{CustomValues: &Type1{}})
expected := prepareExpected(`
expected, err := minifyJSON(`
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
Expand All @@ -470,6 +482,7 @@ var _ = Describe("toJSONSchema", func() {
}
}
}`)
Expect(err).NotTo(HaveOccurred())
Expect(result).To(Equal(expected))
})

Expand All @@ -482,7 +495,7 @@ var _ = Describe("toJSONSchema", func() {
}

result := render.ToJSONSchema(values.UserHelmValues{CustomValues: &Type1{}})
expected := prepareExpected(`
expected, err := minifyJSON(`
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
Expand Down Expand Up @@ -516,6 +529,7 @@ var _ = Describe("toJSONSchema", func() {
}
}
}`)
Expect(err).NotTo(HaveOccurred())
Expect(result).To(Equal(expected))
})

Expand All @@ -528,7 +542,7 @@ var _ = Describe("toJSONSchema", func() {
}

result := render.ToJSONSchema(values.UserHelmValues{CustomValues: &Type2{}})
expected := prepareExpected(`
expected, err := minifyJSON(`
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
Expand Down Expand Up @@ -556,6 +570,7 @@ var _ = Describe("toJSONSchema", func() {
}
}
}`)
Expect(err).NotTo(HaveOccurred())
Expect(expected).To(Equal(result))
})

Expand All @@ -564,7 +579,7 @@ var _ = Describe("toJSONSchema", func() {
Field1 *structpb.Value
}
result := render.ToJSONSchema(values.UserHelmValues{CustomValues: &Type1{}})
expected := prepareExpected(`
expected, err := minifyJSON(`
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
Expand Down Expand Up @@ -592,6 +607,7 @@ var _ = Describe("toJSONSchema", func() {
}
}
}`)
Expect(err).NotTo(HaveOccurred())
Expect(result).To(Equal(expected))
})

Expand All @@ -600,7 +616,7 @@ var _ = Describe("toJSONSchema", func() {
Field1 metav1.Time `json:"metatime"`
}
result := render.ToJSONSchema(values.UserHelmValues{CustomValues: &Type1{}})
expected := prepareExpected(`
expected, err := minifyJSON(`
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
Expand All @@ -617,6 +633,7 @@ var _ = Describe("toJSONSchema", func() {
}
}
}`)
Expect(err).NotTo(HaveOccurred())
Expect(result).To(Equal(expected))
})

Expand All @@ -625,7 +642,7 @@ var _ = Describe("toJSONSchema", func() {
Field1 resource.Quantity
}
result := render.ToJSONSchema(values.UserHelmValues{CustomValues: &Type1{}})
expected := prepareExpected(`
expected, err := minifyJSON(`
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
Expand All @@ -641,6 +658,7 @@ var _ = Describe("toJSONSchema", func() {
}
}
}`)
Expect(err).NotTo(HaveOccurred())
Expect(result).To(Equal(expected))
})

Expand All @@ -649,7 +667,7 @@ var _ = Describe("toJSONSchema", func() {
Field1 intstr.IntOrString
}
result := render.ToJSONSchema(values.UserHelmValues{CustomValues: &Type1{}})
expected := prepareExpected(`
expected, err := minifyJSON(`
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
Expand All @@ -665,6 +683,7 @@ var _ = Describe("toJSONSchema", func() {
}
}
}`)
Expect(err).NotTo(HaveOccurred())
Expect(result).To(Equal(expected))
})

Expand Down Expand Up @@ -700,7 +719,7 @@ var _ = Describe("toJSONSchema", func() {
result := render.ToJSONSchema(values.UserHelmValues{
CustomValues: &Type1{},
})
expected := prepareExpected(`
expected, err := minifyJSON(`
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
Expand All @@ -712,6 +731,7 @@ var _ = Describe("toJSONSchema", func() {
"Field1"
]
}`)
Expect(err).NotTo(HaveOccurred())
Expect(result).To(Equal(expected))

})
Expand Down Expand Up @@ -747,7 +767,7 @@ var _ = Describe("toJSONSchema", func() {
CustomTypeMapper: typeMapper,
},
})
expected := prepareExpected(`
expected, err := minifyJSON(`
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
Expand All @@ -756,6 +776,7 @@ var _ = Describe("toJSONSchema", func() {
}
}
}`)
Expect(err).NotTo(HaveOccurred())
Expect(result).To(Equal(expected))
})

Expand Down Expand Up @@ -787,7 +808,7 @@ var _ = Describe("toJSONSchema", func() {
CustomTypeMapper: typeMapper,
},
})
expected := prepareExpected(`
expected, err := minifyJSON(`
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
Expand All @@ -804,6 +825,7 @@ var _ = Describe("toJSONSchema", func() {
}
}
}`)
Expect(err).NotTo(HaveOccurred())
Expect(result).To(Equal(expected))
})

Expand Down Expand Up @@ -833,7 +855,7 @@ var _ = Describe("toJSONSchema", func() {
},
},
})
expected := prepareExpected(`
expected, err := minifyJSON(`
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
Expand All @@ -842,6 +864,7 @@ var _ = Describe("toJSONSchema", func() {
}
}
}`)
Expect(err).NotTo(HaveOccurred())
Expect(result).To(Equal(expected))
})
})
Expand Down
Loading