Skip to content

Commit

Permalink
Move configmap definition from template to go
Browse files Browse the repository at this point in the history
This commits includes the following additions:
* For statement handler in transpiler
* operand handlers in transpiler for
  * modulo
  * great or equal
  * less or equal
* handle until buildin function in AST tree
* add buildin functions to helmette
  * regexReplaceAll
  * toYaml
  * first
  * trimSuffix
  * min
  * semverCompare
* fix tiered storage enabled conditions check
* add validation test that compares Redpanda chart version 5.8.5 with new implementation
  • Loading branch information
RafalKorepta committed May 23, 2024
1 parent 72a867b commit b6bfb03
Show file tree
Hide file tree
Showing 64 changed files with 10,141 additions and 7,916 deletions.
10 changes: 7 additions & 3 deletions charts/redpanda/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (

certmanagerv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
cmmeta "github.com/cert-manager/cert-manager/pkg/apis/meta/v1"
"github.com/redpanda-data/helm-charts/pkg/gotohelm/helmette"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"

"github.com/redpanda-data/helm-charts/pkg/gotohelm/helmette"
)

func ClientCerts(dot *helmette.Dot) []certmanagerv1.Certificate {
Expand Down Expand Up @@ -83,16 +84,19 @@ func ClientCerts(dot *helmette.Dot) []certmanagerv1.Certificate {
}

name := values.Listeners.Kafka.TLS.Cert
if name == nil {
return certs
}

data, ok := values.TLS.Certs[name]
data, ok := values.TLS.Certs[*name]
if !ok || (helmette.Empty(data.SecretRef) && !ClientAuthRequired(dot)) {
return certs
}

issuerRef := cmmeta.ObjectReference{
Group: "cert-manager.io",
Kind: "Issuer",
Name: fmt.Sprintf("%s-%s-root-issuer", fullname, name),
Name: fmt.Sprintf("%s-%s-root-issuer", fullname, ptr.Deref(name, "")),
}

if data.IssuerRef != nil {
Expand Down
2 changes: 2 additions & 0 deletions charts/redpanda/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
_ "embed"

certmanagerv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
"github.com/redpanda-data/helm-charts/pkg/gotohelm/helmette"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/scheme"
Expand All @@ -25,6 +26,7 @@ var (
func init() {
must(scheme.AddToScheme(Scheme))
must(certmanagerv1.AddToScheme(Scheme))
must(monitoringv1.AddToScheme(Scheme))

// NB: We can't directly unmarshal into a helmette.Chart as adding json
// tags to it breaks gotohelm.
Expand Down
118 changes: 114 additions & 4 deletions charts/redpanda/chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ import (
"os/exec"
"testing"

"github.com/stretchr/testify/require"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/yaml"

"github.com/redpanda-data/helm-charts/charts/redpanda"
"github.com/redpanda-data/helm-charts/pkg/gotohelm/helmette"
"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"
"github.com/redpanda-data/helm-charts/pkg/testutil"
"github.com/redpanda-data/helm-charts/pkg/valuesutil"
"github.com/stretchr/testify/require"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TieredStorageStatic(t *testing.T) redpanda.PartialValues {
Expand Down Expand Up @@ -200,6 +202,114 @@ func TestChart(t *testing.T) {
})
}

func TestConfigMap(t *testing.T) {
ctx := testutil.Context(t)
client, err := helm.New(helm.Options{ConfigHome: testutil.TempDir(t)})
require.NoError(t, err)

// Chart deps are kept within ./charts as a tgz archive, which is git
// ignored. Helm dep build will ensure that ./charts is in sync with
// Chart.lock, which is tracked by git.
require.NoError(t, client.RepoAdd(ctx, "redpanda", "https://charts.redpanda.com"))
require.NoError(t, client.DependencyBuild(ctx, "."), "failed to refresh helm dependencies")

values, err := os.ReadDir("./ci")
require.NoError(t, err)

for _, v := range values {
v := v
t.Run(v.Name(), func(t *testing.T) {
t.Parallel()

manifests, err := client.Template(ctx, "redpanda/redpanda", helm.TemplateOptions{
Name: "redpanda",
ValuesFile: "./ci/" + v.Name(),
Set: []string{
// Tests utilize some non-deterministic helpers (rng). We don't
// really care about the stability of their output, so globally
// disable them.
"tests.enabled=false",
// jwtSecret defaults to a random string. Can't have that
// in snapshot testing so set it to a static value.
"console.secret.login.jwtSecret=SECRETKEY",
},
Version: "5.8.5",
})
require.NoError(t, err)

oldConf, err := getRedpandaConfiguration(manifests)
require.NoError(t, err)

manifests, err = client.Template(ctx, ".", helm.TemplateOptions{
Name: "redpanda",
ValuesFile: "./ci/" + v.Name(),
Set: []string{
// Tests utilize some non-deterministic helpers (rng). We don't
// really care about the stability of their output, so globally
// disable them.
"tests.enabled=false",
// jwtSecret defaults to a random string. Can't have that
// in snapshot testing so set it to a static value.
"console.secret.login.jwtSecret=SECRETKEY",
},
})
require.NoError(t, err)

newConf, err := getRedpandaConfiguration(manifests)
require.NoError(t, err)

require.JSONEq(t, oldConf.redpanda, newConf.redpanda)
require.JSONEq(t, oldConf.bootstrap, newConf.bootstrap)
require.JSONEq(t, oldConf.rpkProfile, newConf.rpkProfile)
})
}
}

type Configuration struct {
redpanda string
bootstrap string
rpkProfile string
}

func getRedpandaConfiguration(manifests []byte) (*Configuration, error) {
result := Configuration{}
objs, err := kube.DecodeYAML(manifests, redpanda.Scheme)
if err != nil {
return &result, err
}

for _, obj := range objs {
switch obj := obj.(type) {
case *corev1.ConfigMap:
switch obj.Name {
case "redpanda":
r := obj.Data["redpanda.yaml"]
jsonR, err := yaml.YAMLToJSON([]byte(r))
if err != nil {
return nil, err
}
result.redpanda = string(jsonR)

b := obj.Data["bootstrap.yaml"]
jsonB, err := yaml.YAMLToJSON([]byte(b))
if err != nil {
return nil, err
}
result.bootstrap = string(jsonB)
case "redpanda-rpk":
p := obj.Data["profile"]
jsonP, err := yaml.YAMLToJSON([]byte(p))
if err != nil {
return nil, err
}
result.rpkProfile = string(jsonP)
}
}
}

return &result, nil
}

func TestLabels(t *testing.T) {
ctx := testutil.Context(t)
client, err := helm.New(helm.Options{ConfigHome: testutil.TempDir(t)})
Expand Down
Loading

0 comments on commit b6bfb03

Please sign in to comment.