fix: persist scheduler-k3s chart overrides as JSON maps

Chart property names containing `/` failed because per-key flat-file storage interpreted the slash as a filesystem path separator, and any move to line-based storage would silently truncate multi-line values. A new `PropertyMap*` helper family in `common` persists each map as a single JSON file so both `/` in keys and `\n` in values round-trip losslessly. Chart overrides move to `chart-overrides.<chart>` and an idempotent `TriggerInstall` migration rewrites any legacy `chart.<chart>.<key>` files into the new layout. The deprecated `scheduler-k3s:set --global chart.*` form is rerouted through the same map storage so it does not silently orphan writes. Closes #8717.
This commit is contained in:
Jose Diaz-Gonzalez committed 2026-05-31 01:54:28 -04:00
1 parent ff00bcb218
commit b8929712d4
11 files changed
+488 -22

No files matched your search

+1 -2
View File
@@ -1774,12 +1774,11 @@ func installHelmCharts(ctx context.Context, clientset KubernetesClient, shouldIn
values = updateVectorValues(values)
}
chartProperties, err := common.PropertyGetAllByPrefix("scheduler-k3s", "--global", "chart."+chart.ReleaseName+".")
chartProperties, err := common.PropertyMapGet("scheduler-k3s", "--global", "chart-overrides."+chart.ReleaseName)
if err != nil {
return fmt.Errorf("Error getting chart properties: %w", err)
}
for key, value := range chartProperties {
key = strings.TrimPrefix(key, "chart."+chart.ReleaseName+".")
strval := fmt.Sprintf("%s=%s", key, value)
if err := strvals.ParseInto(strval, values); err != nil {
return fmt.Errorf("Error parsing chart property %s: %w", strval, err)
+11 -8
View File
@@ -105,14 +105,17 @@ func ReportSingleApp(appName string, format string, infoFlag string) error {
}
}
chartProperties, err := common.PropertyGetAllByPrefix("scheduler-k3s", "--global", "chart.")
if err != nil {
return fmt.Errorf("Unable to get property list: %w", err)
}
for name, value := range chartProperties {
flagName := "--scheduler-k3s-global-" + name
flags[flagName] = func(appName string) string {
return value
for _, chart := range HelmCharts {
chartOverrides, err := common.PropertyMapGet("scheduler-k3s", "--global", "chart-overrides."+chart.ReleaseName)
if err != nil {
return fmt.Errorf("Unable to get property list: %w", err)
}
for key, value := range chartOverrides {
flagName := fmt.Sprintf("--scheduler-k3s-global-chart.%s.%s", chart.ReleaseName, key)
value := value
flags[flagName] = func(appName string) string {
return value
}
}
}
+1
View File
@@ -95,6 +95,7 @@ var LabelResourceTypes = []string{
// exclude such properties when scanning the property store.
var reservedAnnotationPrefixes = []string{
"chart.",
"chart-overrides.",
"labels.",
"node-profile-",
TriggerAuthPropertyPrefix,
+24 -12
View File
@@ -471,16 +471,17 @@ func CommandChartsSet(propertyArg string, value string) error {
}
key := fmt.Sprintf("chart.%s.%s", chartName, chartProperty)
mapProperty := "chart-overrides." + chartName
if value != "" {
common.LogInfo2Quiet(fmt.Sprintf("Setting %s to %s", key, value))
if err := common.PropertyWrite("scheduler-k3s", "--global", key, value); err != nil {
if err := common.PropertyMapSet("scheduler-k3s", "--global", mapProperty, chartProperty, value); err != nil {
return fmt.Errorf("Unable to write property: %w", err)
}
return nil
}
common.LogInfo2Quiet(fmt.Sprintf("Unsetting %s", key))
if err := common.PropertyDelete("scheduler-k3s", "--global", key); err != nil {
if err := common.PropertyMapDelete("scheduler-k3s", "--global", mapProperty, chartProperty); err != nil {
return fmt.Errorf("Unable to delete property: %w", err)
}
return nil
@@ -522,16 +523,12 @@ func CommandChartsReport(chartName string, format string, infoFlag string) error
flatOverrides := map[string]string{}
flagToValue := map[string]string{}
for _, chart := range charts {
properties, err := common.PropertyGetAllByPrefix("scheduler-k3s", "--global", "chart."+chart.ReleaseName+".")
chartOverrides, err := common.PropertyMapGet("scheduler-k3s", "--global", "chart-overrides."+chart.ReleaseName)
if err != nil {
return fmt.Errorf("Unable to get chart properties: %w", err)
}
chartOverrides := map[string]string{}
prefix := "chart." + chart.ReleaseName + "."
for key, value := range properties {
overrideKey := strings.TrimPrefix(key, prefix)
chartOverrides[overrideKey] = value
for overrideKey, value := range chartOverrides {
flatKey := chart.ReleaseName + "." + overrideKey
flatOverrides[flatKey] = value
flagToValue["--scheduler-k3s-charts-"+flatKey] = value
@@ -1372,17 +1369,32 @@ func CommandSet(appName string, property string, value string) error {
}
chartName := chartParts[1]
chartProperty := chartParts[2]
chartFound := false
for _, chart := range HelmCharts {
if chart.ReleaseName == chartName {
validProperties[property] = ""
globalProperties[property] = true
chartFound = true
break
}
}
if _, ok := validProperties[property]; !ok {
if !chartFound {
return fmt.Errorf("Invalid chart property, no matching chart found: %s", property)
}
mapProperty := "chart-overrides." + chartName
if value != "" {
common.LogInfo2Quiet(fmt.Sprintf("Setting %s to %s", property, value))
if err := common.PropertyMapSet("scheduler-k3s", "--global", mapProperty, chartProperty, value); err != nil {
return fmt.Errorf("Unable to write property: %w", err)
}
return nil
}
common.LogInfo2Quiet(fmt.Sprintf("Unsetting %s", property))
if err := common.PropertyMapDelete("scheduler-k3s", "--global", mapProperty, chartProperty); err != nil {
return fmt.Errorf("Unable to delete property: %w", err)
}
return nil
}
common.CommandPropertySet("scheduler-k3s", appName, property, value, validProperties, globalProperties)
+44
View File
@@ -75,6 +75,10 @@ func TriggerInstall() error {
return err
}
if err := migrateChartPropertiesToMapFormat(); err != nil {
return fmt.Errorf("Unable to migrate chart properties: %w", err)
}
if err := syncExistingCertificates(); err != nil {
common.LogWarn(fmt.Sprintf("Warning: failed to sync existing certificates: %v", err))
}
@@ -82,6 +86,46 @@ func TriggerInstall() error {
return nil
}
// migrateChartPropertiesToMapFormat moves legacy per-key chart.<chart>.<key>
// property files into a single chart-overrides.<chart> JSON map per chart.
// Without this migration, a dokku upgrade would silently strand any existing
// chart overrides because the new render path only reads chart-overrides.*.
// Idempotent: once the legacy files are gone the helper short-circuits per
// chart, and legacy values take precedence over any partial pre-existing
// entries on re-runs.
func migrateChartPropertiesToMapFormat() error {
for _, chart := range HelmCharts {
prefix := "chart." + chart.ReleaseName + "."
legacy, err := common.PropertyGetAllByPrefix("scheduler-k3s", "--global", prefix)
if err != nil {
return fmt.Errorf("Unable to read legacy chart properties for %s: %w", chart.ReleaseName, err)
}
if len(legacy) == 0 {
continue
}
mapProperty := "chart-overrides." + chart.ReleaseName
merged, err := common.PropertyMapGet("scheduler-k3s", "--global", mapProperty)
if err != nil {
return fmt.Errorf("Unable to read existing chart-overrides for %s: %w", chart.ReleaseName, err)
}
for fullKey, value := range legacy {
merged[strings.TrimPrefix(fullKey, prefix)] = value
}
if err := common.PropertyMapWrite("scheduler-k3s", "--global", mapProperty, merged); err != nil {
return fmt.Errorf("Unable to write chart-overrides for %s: %w", chart.ReleaseName, err)
}
for fullKey := range legacy {
if err := common.PropertyDelete("scheduler-k3s", "--global", fullKey); err != nil {
return fmt.Errorf("Unable to remove legacy chart property %s: %w", fullKey, err)
}
}
}
return nil
}
// TriggerPostCertsUpdate handles post-certs-update trigger
func TriggerPostCertsUpdate(appName string) error {
scheduler := common.PropertyGetDefault("scheduler", appName, "selected", "")
+86
View File
@@ -0,0 +1,86 @@
package scheduler_k3s
import (
"testing"
"github.com/dokku/dokku/plugins/common"
. "github.com/onsi/gomega"
)
func setupChartMigrationTest(t *testing.T) {
t.Helper()
RegisterTestingT(t)
t.Setenv("PLUGIN_PATH", "/var/lib/dokku/plugins")
t.Setenv("PLUGIN_ENABLED_PATH", "/var/lib/dokku/plugins/enabled")
t.Setenv("DOKKU_LIB_ROOT", t.TempDir())
Expect(common.PropertySetup("scheduler-k3s")).To(Succeed())
}
func TestMigrateChartPropertiesToMapFormat(t *testing.T) {
setupChartMigrationTest(t)
Expect(common.PropertyWrite("scheduler-k3s", "--global", "chart.cert-manager.installCRDs", "false")).To(Succeed())
Expect(common.PropertyWrite("scheduler-k3s", "--global", "chart.cert-manager.version", "1.13.3")).To(Succeed())
Expect(common.PropertyWrite("scheduler-k3s", "--global", "chart.traefik.replicas", "2")).To(Succeed())
Expect(migrateChartPropertiesToMapFormat()).To(Succeed())
certManager, err := common.PropertyMapGet("scheduler-k3s", "--global", "chart-overrides.cert-manager")
Expect(err).NotTo(HaveOccurred())
Expect(certManager).To(Equal(map[string]string{
"installCRDs": "false",
"version": "1.13.3",
}))
traefik, err := common.PropertyMapGet("scheduler-k3s", "--global", "chart-overrides.traefik")
Expect(err).NotTo(HaveOccurred())
Expect(traefik).To(Equal(map[string]string{"replicas": "2"}))
Expect(common.PropertyExists("scheduler-k3s", "--global", "chart.cert-manager.installCRDs")).To(BeFalse())
Expect(common.PropertyExists("scheduler-k3s", "--global", "chart.cert-manager.version")).To(BeFalse())
Expect(common.PropertyExists("scheduler-k3s", "--global", "chart.traefik.replicas")).To(BeFalse())
}
func TestMigrateChartPropertiesToMapFormatIsIdempotent(t *testing.T) {
setupChartMigrationTest(t)
Expect(common.PropertyWrite("scheduler-k3s", "--global", "chart.cert-manager.version", "1.13.3")).To(Succeed())
Expect(migrateChartPropertiesToMapFormat()).To(Succeed())
Expect(migrateChartPropertiesToMapFormat()).To(Succeed())
got, err := common.PropertyMapGet("scheduler-k3s", "--global", "chart-overrides.cert-manager")
Expect(err).NotTo(HaveOccurred())
Expect(got).To(Equal(map[string]string{"version": "1.13.3"}))
}
func TestMigrateChartPropertiesToMapFormatPreservesExistingNonOverlappingKeys(t *testing.T) {
setupChartMigrationTest(t)
Expect(common.PropertyMapWrite("scheduler-k3s", "--global", "chart-overrides.cert-manager", map[string]string{
"installCRDs": "true",
"service.annotations.prometheus.io/scrape": "true",
})).To(Succeed())
Expect(common.PropertyWrite("scheduler-k3s", "--global", "chart.cert-manager.installCRDs", "false")).To(Succeed())
Expect(common.PropertyWrite("scheduler-k3s", "--global", "chart.cert-manager.version", "1.13.3")).To(Succeed())
Expect(migrateChartPropertiesToMapFormat()).To(Succeed())
got, err := common.PropertyMapGet("scheduler-k3s", "--global", "chart-overrides.cert-manager")
Expect(err).NotTo(HaveOccurred())
Expect(got).To(Equal(map[string]string{
"installCRDs": "false",
"service.annotations.prometheus.io/scrape": "true",
"version": "1.13.3",
}))
}
func TestMigrateChartPropertiesToMapFormatNoLegacyIsNoOp(t *testing.T) {
setupChartMigrationTest(t)
Expect(migrateChartPropertiesToMapFormat()).To(Succeed())
for _, chart := range HelmCharts {
Expect(common.PropertyExists("scheduler-k3s", "--global", "chart-overrides."+chart.ReleaseName)).To(BeFalse())
}
}