Skip to content

Commit

Permalink
Remove old ConfigMap test
Browse files Browse the repository at this point in the history
As migration to go based Redpanda configuration is done, any further differences
should not be handled in test case.
  • Loading branch information
RafalKorepta committed Jul 3, 2024
1 parent 61ceed2 commit d2444af
Showing 1 changed file with 0 additions and 87 deletions.
87 changes: 0 additions & 87 deletions charts/redpanda/chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package redpanda_test
import (
"maps"
"os"
"path/filepath"
"testing"

"github.com/redpanda-data/helm-charts/charts/redpanda"
Expand All @@ -17,8 +16,6 @@ import (
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/yaml"
)

func TieredStorageStatic(t *testing.T) redpanda.PartialValues {
Expand Down Expand Up @@ -143,90 +140,6 @@ func TestChart(t *testing.T) {
})
}

// preTranspilerChartVersion is the latest release of the Redpanda helm chart prior to the introduction of
// ConfigMap go base implementation. It's used to verify that translated code is functionally equivalent.
const preTranspilerChartVersion = "redpanda-5.8.8.tgz"

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

// Downloading Redpanda helm chart release is required as client.Template
// function does not pass HELM_CONFIG_HOME, that prevents from downloading specific
// Redpanda helm chart version from public helm repository.
require.NoError(t, client.DownloadFile(ctx, "https://github.com/redpanda-data/helm-charts/releases/download/redpanda-5.8.8/redpanda-5.8.8.tgz", preTranspilerChartVersion))

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

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

// First generate latest released Redpanda charts manifests. From ConfigMap bootstrap,
// redpanda node configuration and RPK profile.
manifests, err := client.Template(ctx, filepath.Join(client.GetConfigHome(), preTranspilerChartVersion), 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)

oldRedpanda, oldRPKProfile, err := getConfigMaps(manifests)
require.NoError(t, err)

// Now helm template will generate Redpanda configuration from local definition
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)

newRedpanda, newRPKProfile, err := getConfigMaps(manifests)
require.NoError(t, err)

// Overprovisioned field till Redpanda chart version 5.8.8 was wrongly set to `false`
// when CPU request value was bellow 1000 mili cores. Function `redpanda-smp`, that
// should overwrite `overprovisioned` flag in old implementation, was not called
// before setting `overprovisioned` flag (`{{ dig "cpu" "overprovisioned" false .Values.resources }}`).
// redpanda-smp template - https://github.com/redpanda-data/helm-charts/blob/5f287d45a3bda2763896840e505fb3de82b968b6/charts/redpanda/templates/_helpers.tpl#L187
// redpanda-smp template invocation - https://github.com/redpanda-data/helm-charts/blob/5f287d45a3bda2763896840e505fb3de82b968b6/charts/redpanda/templates/_configmap.tpl#L610
// overprovisioned flag - https://github.com/redpanda-data/helm-charts/blob/5f287d45a3bda2763896840e505fb3de82b968b6/charts/redpanda/templates/_configmap.tpl#L607
var newUnstructuredRedpandaConf map[string]any
require.NoError(t, yaml.Unmarshal([]byte(newRedpanda.Data["redpanda.yaml"]), &newUnstructuredRedpandaConf))
require.NoError(t, unstructured.SetNestedField(newUnstructuredRedpandaConf, false, "rpk", "overprovisioned"))

require.Equal(t, getJSONObject(t, oldRedpanda.Data["redpanda.yaml"]), newUnstructuredRedpandaConf)
require.Equal(t, getJSONObject(t, oldRedpanda.Data["bootstrap.yaml"]), getJSONObject(t, newRedpanda.Data["bootstrap.yaml"]))
require.Equal(t, getJSONObject(t, oldRPKProfile.Data["profile"]), getJSONObject(t, newRPKProfile.Data["profile"]))
})
}
}

func getJSONObject(t *testing.T, input string) any {
var output any
require.NoError(t, yaml.Unmarshal([]byte(input), &output))
return output
}

// getConfigMaps is parsing all manifests (resources) created by helm template
// execution. Redpanda helm chart creates 3 distinct files in ConfigMap:
// redpanda.yaml (node, tunable and cluster configuration), bootstrap.yaml
Expand Down

0 comments on commit d2444af

Please sign in to comment.