-
Notifications
You must be signed in to change notification settings - Fork 8
Minify Helm chart values JSON schema #595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
baa3b14
f9725a4
1d17d00
95fa5c8
921c50e
7f4a613
14dfc5a
e29c41f
73bbb80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package render_test | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "encoding/json" | ||
| "fmt" | ||
| "reflect" | ||
|
|
@@ -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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. json.Compact might work here https://pkg.go.dev/encoding/json#Compact
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() { | ||
|
|
@@ -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": { | ||
|
|
@@ -470,6 +482,7 @@ var _ = Describe("toJSONSchema", func() { | |
| } | ||
| } | ||
| }`) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(result).To(Equal(expected)) | ||
| }) | ||
|
|
||
|
|
@@ -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": { | ||
|
|
@@ -516,6 +529,7 @@ var _ = Describe("toJSONSchema", func() { | |
| } | ||
| } | ||
| }`) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(result).To(Equal(expected)) | ||
| }) | ||
|
|
||
|
|
@@ -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": { | ||
|
|
@@ -556,6 +570,7 @@ var _ = Describe("toJSONSchema", func() { | |
| } | ||
| } | ||
| }`) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(expected).To(Equal(result)) | ||
| }) | ||
|
|
||
|
|
@@ -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": { | ||
|
|
@@ -592,6 +607,7 @@ var _ = Describe("toJSONSchema", func() { | |
| } | ||
| } | ||
| }`) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(result).To(Equal(expected)) | ||
| }) | ||
|
|
||
|
|
@@ -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": { | ||
|
|
@@ -617,6 +633,7 @@ var _ = Describe("toJSONSchema", func() { | |
| } | ||
| } | ||
| }`) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(result).To(Equal(expected)) | ||
| }) | ||
|
|
||
|
|
@@ -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": { | ||
|
|
@@ -641,6 +658,7 @@ var _ = Describe("toJSONSchema", func() { | |
| } | ||
| } | ||
| }`) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(result).To(Equal(expected)) | ||
| }) | ||
|
|
||
|
|
@@ -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": { | ||
|
|
@@ -665,6 +683,7 @@ var _ = Describe("toJSONSchema", func() { | |
| } | ||
| } | ||
| }`) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(result).To(Equal(expected)) | ||
| }) | ||
|
|
||
|
|
@@ -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": { | ||
|
|
@@ -712,6 +731,7 @@ var _ = Describe("toJSONSchema", func() { | |
| "Field1" | ||
| ] | ||
| }`) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(result).To(Equal(expected)) | ||
|
|
||
| }) | ||
|
|
@@ -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": { | ||
|
|
@@ -756,6 +776,7 @@ var _ = Describe("toJSONSchema", func() { | |
| } | ||
| } | ||
| }`) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(result).To(Equal(expected)) | ||
| }) | ||
|
|
||
|
|
@@ -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": { | ||
|
|
@@ -804,6 +825,7 @@ var _ = Describe("toJSONSchema", func() { | |
| } | ||
| } | ||
| }`) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(result).To(Equal(expected)) | ||
| }) | ||
|
|
||
|
|
@@ -833,7 +855,7 @@ var _ = Describe("toJSONSchema", func() { | |
| }, | ||
| }, | ||
| }) | ||
| expected := prepareExpected(` | ||
| expected, err := minifyJSON(` | ||
| { | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
| "properties": { | ||
|
|
@@ -842,6 +864,7 @@ var _ = Describe("toJSONSchema", func() { | |
| } | ||
| } | ||
| }`) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(result).To(Equal(expected)) | ||
| }) | ||
| }) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.