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:
Jose Diaz-Gonzalez committed 2026-04-29 12:18:03 -04:00
1 parent f06048a266
commit ef9bdc0379
18 files changed
+1086 -56

No files matched your search

+59
View File
@@ -3,6 +3,7 @@ package scheduler_k3s
import (
"bufio"
"context"
"encoding/json"
"errors"
"fmt"
"io"
@@ -977,6 +978,64 @@ func (k KubernetesClient) ScaleDeployment(ctx context.Context, input ScaleDeploy
return nil
}
// SetDeploymentImagePullSecretsInput contains all the information needed to overwrite a Deployment's imagePullSecrets list
type SetDeploymentImagePullSecretsInput struct {
// Name is the Kubernetes deployment name
Name string
// Namespace is the Kubernetes namespace
Namespace string
// ImagePullSecrets is the desired list of imagePullSecret names. May be empty.
ImagePullSecrets []string
}
// SetDeploymentImagePullSecrets overwrites the deployment pod template's imagePullSecrets list with exactly
// the names supplied in input.ImagePullSecrets. Strategic-merge patches honor patchMergeKey semantics, which
// is precisely what causes leaked entries to accumulate in the first place. To force a hard replace we use
// a JSON merge patch on the imagePullSecrets path; JSON merge patch replaces array fields wholesale.
func (k KubernetesClient) SetDeploymentImagePullSecrets(ctx context.Context, input SetDeploymentImagePullSecretsInput) error {
type patchPodSpec struct {
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets"`
}
type patchPodTemplate struct {
Spec patchPodSpec `json:"spec"`
}
type patchSpec struct {
Template patchPodTemplate `json:"template"`
}
type patchBody struct {
Spec patchSpec `json:"spec"`
}
refs := make([]corev1.LocalObjectReference, 0, len(input.ImagePullSecrets))
for _, name := range input.ImagePullSecrets {
refs = append(refs, corev1.LocalObjectReference{Name: name})
}
body := patchBody{
Spec: patchSpec{
Template: patchPodTemplate{
Spec: patchPodSpec{
ImagePullSecrets: refs,
},
},
},
}
data, err := json.Marshal(body)
if err != nil {
return fmt.Errorf("error marshalling deployment patch: %w", err)
}
_, err = k.Client.AppsV1().Deployments(input.Namespace).Patch(ctx, input.Name, types.MergePatchType, data, metav1.PatchOptions{})
if err != nil {
return fmt.Errorf("error patching deployment imagePullSecrets: %w", err)
}
return nil
}
type StreamLogsInput struct {
// ContainerName is the Kubernetes container name
ContainerName string