Skip to content

Kustomization reconciliation fails on multiple $patch: delete uses in a single strategic merge patch #1306

@tdemin

Description

@tdemin

Environment

  • Flux v2.4.0 (kustomize-controller v1.4.0)
  • Kubernetes v1.29.3 (seemingly irrelevant)

Description

If multiple $patch: delete strategic merge patches are provided in a single spec.patches.patch in a kustomize.toolkit.fluxcd.io/v1.Kustomization resource, kustomize-controller fails to reconcile with the following status:

flux-system   kustomization.kustomize.toolkit.fluxcd.io/debug         3m20s   False     kustomize build failed: recovered from kustomize build panic: runtime error: invalid memory address or nil pointer dereference

kustomize-controller log reports the following:

{"level":"error","ts":"2024-12-09T18:41:35.677Z","msg":"Reconciliation failed after 108.007784ms, next try in 1h0m0s","controller":"kustomization","controllerGroup":"kustomize.toolkit.fluxcd.io","controllerKind":"Kustomization","Kustomization":{"name":"debug","namespace":"flux-system"},"namespace":"flux-system","name":"debug","reconcileID":"5eef40e9-8bf0-4a65-a178-eae10b04f877","revision":"main@sha1:4258282a038ab9506e1b37b3a44cc5ab4d38075e","error":"kustomize build failed: recovered from kustomize build panic: runtime error: invalid memory address or nil pointer dereference"}

The Kustomization resource needs to look like that:

apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
  name: whatever
spec:
  patches:
    - patch: |-
        $patch: delete
        apiVersion: v1
        kind: Whatever
        metadata:
          name: whatever1
        ---
        $patch: delete
        apiVersion: v1
        kind: Whatever
        metadata:
          name: whatever2

Reproduction steps

  1. Create a fresh Kubernetes cluster and install Flux v2.4.0 in whatever way convenient.
  2. Create a Kustomization with the following files:
% cat > kustomization.yaml
resources:
  - configmaps.yml
% cat > configmaps.yml
apiVersion: v1
kind: Namespace
metadata:
  name: debug
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: debug1
  namespace: debug
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: debug2
  namespace: debug
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: debug3
  namespace: debug
  1. Setup Flux to reconcile this Kustomization while deleting two of the ConfigMaps:
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
  name: debug
  namespace: flux-system
spec:
  interval: 1h
  sourceRef:
    kind: GitRepository
    name: flux-system
  path: ./debug
  prune: true
  patches:
    - patch: |-
        $patch: delete
        apiVersion: v1
        kind: ConfigMap
        metadata:
          name: debug1
          namespace: debug
        ---
        $patch: delete
        apiVersion: v1
        kind: ConfigMap
        metadata:
          name: debug2
          namespace: debug
  1. Wait for Flux to reconcile and observe the status above.

Additional details

Apparently closely related to kubernetes-sigs/kustomize#5552? The current Flux-specific workaround is simply to split every removal patch into its separate - patch:.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions