Files
dokku/plugins/scheduler-k3s/pull_secret_test.go
Jose Diaz-Gonzalez ef9bdc0379 fix: split env config and image pull secret into separate helm releases
Bundling these Secrets in the app helm chart caused two bugs in the scheduler-k3s plugin: a chart rollback could delete Secrets that older ReplicaSets still referenced by exact timestamped name (`env-{app}.{ts}` and `ims-{app}.{ts}`), hard-crashing pods until manual intervention; and the strategic-merge `patchMergeKey` on `imagePullSecrets` let stale entries leak into the live Deployment until the list pointed at many nonexistent Secrets. Each Secret now lives in its own helm release with a stable name (`config-{app}` and `pull-secret-{app}`), installed before the app chart on every deploy. The deployment trigger also prunes any leaked `imagePullSecrets` entries from the live Deployment so the next deploy lands on a clean list, and the rename and destroy paths uninstall the new releases (and the previously-leaked TLS release on rename) under the old app name.
2026-04-29 12:18:03 -04:00

62 lines
1.6 KiB
Go

package scheduler_k3s
import (
"encoding/base64"
"testing"
"gopkg.in/yaml.v3"
)
func TestGetImagePullSecretReleaseName(t *testing.T) {
got := GetImagePullSecretReleaseName("myapp")
want := "pull-secret-myapp"
if got != want {
t.Fatalf("GetImagePullSecretReleaseName(\"myapp\") = %q, want %q", got, want)
}
}
func TestGetImagePullSecretName(t *testing.T) {
got := GetImagePullSecretName("myapp")
want := "pull-secret-myapp"
if got != want {
t.Fatalf("GetImagePullSecretName(\"myapp\") = %q, want %q", got, want)
}
}
func TestImagePullSecretValuesEncoding(t *testing.T) {
dockerConfig := []byte(`{"auths":{"https://index.docker.io/v1/":{"auth":"dXNlcjpwYXNz"}}}`)
values := &ImagePullSecretValues{
Global: ImagePullSecretGlobalValues{
AppName: "myapp",
Namespace: "default",
PullSecretBase64: base64.StdEncoding.EncodeToString(dockerConfig),
},
}
data, err := yaml.Marshal(values)
if err != nil {
t.Fatalf("yaml.Marshal returned error: %v", err)
}
var roundTrip ImagePullSecretValues
if err := yaml.Unmarshal(data, &roundTrip); err != nil {
t.Fatalf("yaml.Unmarshal returned error: %v", err)
}
if roundTrip.Global.AppName != "myapp" {
t.Errorf("AppName = %q, want \"myapp\"", roundTrip.Global.AppName)
}
if roundTrip.Global.Namespace != "default" {
t.Errorf("Namespace = %q, want \"default\"", roundTrip.Global.Namespace)
}
decoded, err := base64.StdEncoding.DecodeString(roundTrip.Global.PullSecretBase64)
if err != nil {
t.Fatalf("base64 decode failed: %v", err)
}
if string(decoded) != string(dockerConfig) {
t.Errorf("PullSecretBase64 decoded = %q, want %q", string(decoded), string(dockerConfig))
}
}