Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tdemin opened this issue Dec 9, 2024 · 1 comment
Labels
blocked/upstream Blocked by an upstream dependency or issue

Comments

@tdemin
Copy link

tdemin commented Dec 9, 2024

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:.

@stefanprodan
Copy link
Member

Flux uses Kustomize Go SDK, if this doesn't work with the kustomize CLI then it can't work with Flux.

@stefanprodan stefanprodan added the blocked/upstream Blocked by an upstream dependency or issue label Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked/upstream Blocked by an upstream dependency or issue
Projects
None yet
Development

No branches or pull requests

2 participants