Skip to content

Commit

Permalink
redpanda: generate values.schema.json from go structs
Browse files Browse the repository at this point in the history
This commit introduces a set of go structs that are now used to generate
the values.schema.json files for the redpanda chart.

This is being done to:
- Ensure that values.schema.json is always up to date.
- Allow correct and ergonomic go code to be written in place of helm
  templates.
- Provide a more tenable way of defining, updating, and shaping the
  input values of the redpanda chart.

Efforts were taken to minimize the diff between the original and now
generated jsonschema but there is still a non-trivial diff due to many
invalid entries within the original jsonschema.

Future commits will slowly remove the hacks and shims once the initial
generation hurdle has been cleared.

Rather than reviewing a standard diff. It is recommended to instead view
the diff output by:

`dyff between -i  --exclude-regexp '.*annotations|.*labels' (git show origin/main:charts/redpanda/values.schema.json | psub) ./charts/redpanda/values.schema.json`

- `dyff` will simplify the overall diff.
- `-i` ignores any change in the ordering of keys or elements within an
  array as neither are relevant in the context of a jsonschema.
- `--exclude-regexp '.*annotations|.*labels'` many label and annotation
  fields did not have typed keys. As the Kubernetes API server would
  validate that all values are strings, this is now enforced at the
  schema level.

For reviewers thereof, here is an explanation of the larger diffs:

`properties.storage.properties.tiered.properties.credentialsSecretRef`
was missing a `properties` key in the handwritten schema.

`properties.statefulset.properties.sideCars.properties.configWatcher.controllers`
was incorrectly nested within `configWatcher` _and_ missing a
`properties` key. It's now been hoisted to the correct location within
sideCars and formatted correctly.

`properties.logging` used the key `parameters` instead of `properties`.
  • Loading branch information
chrisseto committed Mar 20, 2024
1 parent ce26bcf commit 3ec7ade
Show file tree
Hide file tree
Showing 11 changed files with 2,713 additions and 1,363 deletions.
7 changes: 6 additions & 1 deletion Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ tasks:
cmds:
- task: lint:chart:redpanda

lint:chart:redpanda:
chart:redpanda:lint:
cmds:
- ct lint --config .github/ct-redpanda.yaml --github-groups
- .github/check-ci-files.sh charts/redpanda/ci

chart:redpanda:generate:
cmds:
- go run ./cmd/genpartial/main.go -out charts/redpanda/values_partial.gen.go -struct Values ./charts/redpanda
- go run ./cmd/genvalues/main.go > charts/redpanda/values.schema.json

generate:
desc: "[Re]Generate all generated files"
cmds:
Expand Down
49 changes: 26 additions & 23 deletions charts/redpanda/chart_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package redpanda
package redpanda_test

import (
"os"
"os/exec"
"testing"

"github.com/redpanda-data/helm-charts/charts/redpanda"
"github.com/redpanda-data/helm-charts/pkg/helm"
"github.com/redpanda-data/helm-charts/pkg/helm/helmtest"
"github.com/redpanda-data/helm-charts/pkg/kube"
Expand All @@ -14,23 +15,23 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TieredStorageStatic(t *testing.T) Values {
func TieredStorageStatic(t *testing.T) redpanda.Values {
if os.Getenv("REDPANDA_LICENSE") == "" {
t.Skipf("$REDPANDA_LICENSE is not set")
}

return Values{
Config: &Config{
return redpanda.Values{
Config: redpanda.Config{
Node: map[string]any{
"developer_mode": true,
},
},
Enterprise: &Enterprise{
Enterprise: redpanda.Enterprise{
License: os.Getenv("REDPANDA_LICENSE"),
},
Storage: &Storage{
Tiered: &Tiered{
Config: map[string]any{
Storage: redpanda.Storage{
Tiered: &redpanda.Tiered{
Config: redpanda.TieredStorageConfig{
"cloud_storage_enabled": true,
"cloud_storage_region": "static-region",
"cloud_storage_bucket": "static-bucket",
Expand All @@ -55,25 +56,25 @@ func TieredStorageSecret(namespace string) corev1.Secret {
}
}

func TieredStorageSecretRefs(t *testing.T, secret *corev1.Secret) Values {
func TieredStorageSecretRefs(t *testing.T, secret *corev1.Secret) redpanda.Values {
if os.Getenv("REDPANDA_LICENSE") == "" {
t.Skipf("$REDPANDA_LICENSE is not set")
}

return Values{
Config: &Config{
return redpanda.Values{
Config: redpanda.Config{
Node: map[string]any{
"developer_mode": true,
},
},
Enterprise: &Enterprise{
Enterprise: redpanda.Enterprise{
License: os.Getenv("REDPANDA_LICENSE"),
},
Storage: &Storage{
Tiered: &Tiered{
CredentialsSecretRef: &TieredStorageCredentials{
AccessKey: &SecretRef{Name: secret.Name, Key: "access"},
SecretKey: &SecretRef{Name: secret.Name, Key: "secret"},
Storage: redpanda.Storage{
Tiered: &redpanda.Tiered{
CredentialsSecretRef: redpanda.TieredStorageCredentials{
AccessKey: &redpanda.SecretRef{Name: secret.Name, Key: "access"},
SecretKey: &redpanda.SecretRef{Name: secret.Name, Key: "secret"},
},
Config: map[string]any{
"cloud_storage_enabled": true,
Expand Down Expand Up @@ -128,6 +129,8 @@ func TestChart(t *testing.T) {
t.Skipf("Skipping log running test...")
}

redpandaChart := "."

env := helmtest.Setup(t).Namespaced(t)

t.Run("tiered-storage-secrets", func(t *testing.T) {
Expand All @@ -136,30 +139,30 @@ func TestChart(t *testing.T) {
credsSecret, err := kube.Create(ctx, env.Ctl(), TieredStorageSecret(env.Namespace()))
require.NoError(t, err)

rpRelease := env.Install(".", helm.InstallOptions{
Values: Values{
Config: &Config{
rpRelease := env.Install(redpandaChart, helm.InstallOptions{
Values: redpanda.Values{
Config: redpanda.Config{
Node: map[string]any{
"developer_mode": true,
},
},
},
})

rpk := Client{Ctl: env.Ctl(), Release: &rpRelease}
rpk := redpanda.Client{Ctl: env.Ctl(), Release: &rpRelease}

config, err := rpk.ClusterConfig(ctx)
require.NoError(t, err)
require.Equal(t, false, config["cloud_storage_enabled"])

rpRelease = env.Upgrade(".", rpRelease, helm.UpgradeOptions{Values: TieredStorageStatic(t)})
rpRelease = env.Upgrade(redpandaChart, rpRelease, helm.UpgradeOptions{Values: TieredStorageStatic(t)})

config, err = rpk.ClusterConfig(ctx)
require.NoError(t, err)
require.Equal(t, true, config["cloud_storage_enabled"])
require.Equal(t, "static-access-key", config["cloud_storage_access_key"])

rpRelease = env.Upgrade(".", rpRelease, helm.UpgradeOptions{Values: TieredStorageSecretRefs(t, credsSecret)})
rpRelease = env.Upgrade(redpandaChart, rpRelease, helm.UpgradeOptions{Values: TieredStorageSecretRefs(t, credsSecret)})

config, err = rpk.ClusterConfig(ctx)
require.NoError(t, err)
Expand Down
Loading

0 comments on commit 3ec7ade

Please sign in to comment.