Skip to content
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

redpanda: generate values.schema.json from go structs #1090

Merged
merged 1 commit into from
Mar 22, 2024
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
5 changes: 5 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ tasks:
- ct lint --config .github/ct-redpanda.yaml --github-groups
- .github/check-ci-files.sh charts/redpanda/ci

chart:generate:redpanda:
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
Copy link
Contributor

Choose a reason for hiding this comment

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

going the reverse of what we had, interesting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How do you mean? Were we generating something from the json schema previously?

Copy link
Contributor

Choose a reason for hiding this comment

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

exactly. I took an existing tool to take schemas from us and create apis.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What was the output of that and was it ever automated anywhere? The values.schema.json file as it currently exists is missing a good chunk of fields and it's fairly malformed as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, we never got around to make it automated, ill send you the link so you can see the repo.

Copy link
Contributor

Choose a reason for hiding this comment

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


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
Loading