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.
This commit is contained in:
18 files changed
+1086
-56
No files matched your search
@@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -170,6 +169,21 @@ func TriggerPostAppRenameSetup(oldAppName string, newAppName string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
if _, err := DeleteTLSSecret(ctx, oldAppName); err != nil {
|
||||
common.LogWarn(fmt.Sprintf("Error deleting TLS secret for old app name %s: %v", oldAppName, err))
|
||||
}
|
||||
|
||||
if err := DeleteConfigSecret(ctx, oldAppName); err != nil {
|
||||
common.LogWarn(fmt.Sprintf("Error deleting config secret for old app name %s: %v", oldAppName, err))
|
||||
}
|
||||
|
||||
if err := DeleteImagePullSecret(ctx, oldAppName); err != nil {
|
||||
common.LogWarn(fmt.Sprintf("Error deleting image pull secret for old app name %s: %v", oldAppName, err))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -403,8 +417,9 @@ func TriggerSchedulerDeploy(scheduler string, appName string, imageTag string) e
|
||||
}
|
||||
|
||||
deploymentId := time.Now().Unix()
|
||||
pullSecretBase64 := base64.StdEncoding.EncodeToString([]byte(""))
|
||||
imagePullSecrets := getComputedImagePullSecrets(appName)
|
||||
dokkuManagedPullSecret := false
|
||||
var dokkuPullSecretBytes []byte
|
||||
if imagePullSecrets == "" {
|
||||
dockerConfigPath := filepath.Join(registry.GetComputedAppRegistryConfigDir(appName), "config.json")
|
||||
if fi, err := os.Stat(dockerConfigPath); err == nil && !fi.IsDir() {
|
||||
@@ -413,12 +428,13 @@ func TriggerSchedulerDeploy(scheduler string, appName string, imageTag string) e
|
||||
return fmt.Errorf("Error reading docker config: %w", err)
|
||||
}
|
||||
|
||||
imagePullSecrets = fmt.Sprintf("ims-%s.%d", appName, deploymentId)
|
||||
pullSecretBase64 = base64.StdEncoding.EncodeToString(b)
|
||||
imagePullSecrets = GetImagePullSecretName(appName)
|
||||
dokkuManagedPullSecret = true
|
||||
dokkuPullSecretBytes = b
|
||||
}
|
||||
}
|
||||
|
||||
globalTemplateFiles := []string{"service-account", "secret", "image-pull-secret"}
|
||||
globalTemplateFiles := []string{"service-account"}
|
||||
for _, templateName := range globalTemplateFiles {
|
||||
b, err := templates.ReadFile(fmt.Sprintf("templates/chart/%s.yaml", templateName))
|
||||
if err != nil {
|
||||
@@ -541,7 +557,6 @@ func TriggerSchedulerDeploy(scheduler string, appName string, imageTag string) e
|
||||
Keda: kedaValues,
|
||||
Image: GlobalImage{
|
||||
ImagePullSecrets: imagePullSecrets,
|
||||
PullSecretBase64: pullSecretBase64,
|
||||
Name: image,
|
||||
Type: imageSourceType,
|
||||
WorkingDir: workingDir,
|
||||
@@ -553,7 +568,6 @@ func TriggerSchedulerDeploy(scheduler string, appName string, imageTag string) e
|
||||
PrimaryPort: primaryPort,
|
||||
PrimaryServicePort: primaryServicePort,
|
||||
},
|
||||
Secrets: map[string]string{},
|
||||
SecurityContext: securityContext,
|
||||
},
|
||||
Processes: map[string]ProcessValues{},
|
||||
@@ -851,10 +865,6 @@ func TriggerSchedulerDeploy(scheduler string, appName string, imageTag string) e
|
||||
}
|
||||
}
|
||||
|
||||
for key, value := range env.Map() {
|
||||
values.Global.Secrets[key] = base64.StdEncoding.EncodeToString([]byte(value))
|
||||
}
|
||||
|
||||
b, err := templates.ReadFile("templates/chart/_helpers.tpl")
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error reading _helpers template: %w", err)
|
||||
@@ -925,6 +935,28 @@ func TriggerSchedulerDeploy(scheduler string, appName string, imageTag string) e
|
||||
}
|
||||
}
|
||||
|
||||
if err := CreateOrUpdateConfigSecret(ctx, appName, env.Map()); err != nil {
|
||||
return fmt.Errorf("Error syncing config secret: %w", err)
|
||||
}
|
||||
|
||||
if dokkuManagedPullSecret {
|
||||
if err := CreateOrUpdateImagePullSecret(ctx, appName, dokkuPullSecretBytes); err != nil {
|
||||
return fmt.Errorf("Error syncing image pull secret: %w", err)
|
||||
}
|
||||
} else {
|
||||
if err := DeleteImagePullSecret(ctx, appName); err != nil {
|
||||
return fmt.Errorf("Error removing stale image pull secret: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
keepImagePullSecrets := []string{}
|
||||
if imagePullSecrets != "" {
|
||||
keepImagePullSecrets = []string{imagePullSecrets}
|
||||
}
|
||||
if err := pruneStaleImagePullSecretsFromDeployments(ctx, clientset, namespace, appName, keepImagePullSecrets); err != nil {
|
||||
return fmt.Errorf("Error pruning stale imagePullSecrets entries: %w", err)
|
||||
}
|
||||
|
||||
kustomizeRootPath := ""
|
||||
if hasKustomizeDirectory(appName) {
|
||||
kustomizeRootPath = getProcessSpecificKustomizeRootPath(appName)
|
||||
@@ -1402,7 +1434,7 @@ func TriggerSchedulerRun(scheduler string, appName string, envCount int, args []
|
||||
|
||||
imagePullSecrets := getComputedImagePullSecrets(appName)
|
||||
if imagePullSecrets == "" {
|
||||
imagePullSecrets = fmt.Sprintf("ims-%s.%d", appName, deploymentID)
|
||||
imagePullSecrets = GetImagePullSecretName(appName)
|
||||
_, err := clientset.GetSecret(context.Background(), GetSecretInput{
|
||||
Name: imagePullSecrets,
|
||||
Namespace: namespace,
|
||||
@@ -1723,6 +1755,14 @@ func TriggerSchedulerPostDelete(scheduler string, appName string) error {
|
||||
common.LogWarn(fmt.Sprintf("Error deleting TLS secret for %s: %v", appName, err))
|
||||
}
|
||||
|
||||
if err := DeleteConfigSecret(ctx, appName); err != nil {
|
||||
common.LogWarn(fmt.Sprintf("Error deleting config secret for %s: %v", appName, err))
|
||||
}
|
||||
|
||||
if err := DeleteImagePullSecret(ctx, appName); err != nil {
|
||||
common.LogWarn(fmt.Sprintf("Error deleting image pull secret for %s: %v", appName, err))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user