Skip to content

Commit

Permalink
fix(k8s): correctly set image pull secret on sync pod
Browse files Browse the repository at this point in the history
Before this fix, we'd add image pull secrets with name and namespace to
the Pod spec but the namespace field isn't allowed so applying the
manifest fails.

Now we only add the name. Also added test for the 'configureSyncMode'
function.

The compiler didn't catch this because it allows excess properties
(except for object literals).
  • Loading branch information
eysi09 committed Oct 14, 2024
1 parent 04de6e6 commit 26481cf
Show file tree
Hide file tree
Showing 4 changed files with 592 additions and 6 deletions.
1 change: 1 addition & 0 deletions core/src/plugins/kubernetes/container/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ export async function createWorkloadManifest({
production,
}: CreateDeploymentParams): Promise<KubernetesWorkload> {
const spec = action.getSpec()

const mode = action.mode()

let configuredReplicas = spec.replicas || DEFAULT_MINIMUM_REPLICAS
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/kubernetes/kubernetes-type/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ async function configureSpecialModesForManifests({
log,
})
} else if (mode === "sync" && spec.sync && !isEmpty(spec.sync)) {
// The "sync-mode" annotation is set in `configureDevMode`.
// The "sync-mode" annotation is already set.
return configureSyncMode({
ctx,
log,
Expand Down
7 changes: 5 additions & 2 deletions core/src/plugins/kubernetes/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export async function configureSyncMode({
spec,
}: {
ctx: PluginContext
log: Log
log: ActionLog
provider: KubernetesProvider
action: Resolved<SyncableRuntimeAction>
defaultTarget: KubernetesTargetResourceSpec | undefined
Expand Down Expand Up @@ -461,10 +461,12 @@ export async function configureSyncMode({
if (!podSpec.initContainers) {
podSpec.initContainers = []
}

if (!podSpec.imagePullSecrets) {
podSpec.imagePullSecrets = []
}
const k8sSyncUtilImageName = getK8sSyncUtilImageName()

if (!podSpec.initContainers.find((c) => c.image === k8sSyncUtilImageName)) {
const initContainer: V1Container = {
name: k8sSyncUtilContainerName,
Expand All @@ -479,7 +481,8 @@ export async function configureSyncMode({
volumeMounts: [gardenVolumeMount],
}
podSpec.initContainers.push(initContainer)
podSpec.imagePullSecrets.push(...provider.config.imagePullSecrets)

podSpec.imagePullSecrets.push(...provider.config.imagePullSecrets.map((s) => ({ name: s.name })))
}

if (!targetContainer.volumeMounts) {
Expand Down
Loading

0 comments on commit 26481cf

Please sign in to comment.