Skip to content

Flux ignores schema error #5808

@Cajga

Description

@Cajga

Describe the bug

Flux kustomization is used to deploy an application. We made a change in the deployment that makes the deployment manifest invalid by schema.
Flux reconciles the kustomization, but acts like there was not change and shows that everything is ready without pointing our the schema error.

Consider the following example change:
The deployment that was originally applied by flux without any issues:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    reloader.stakater.com/auto: "true"
  labels:
    app.kubernetes.io/instance: rester
    app.kubernetes.io/name: rester
    app.kubernetes.io/part-of: rester
    app.kubernetes.io/version: 0.2.7
  name: rester
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/instance: rester
      app.kubernetes.io/name: rester
  strategy: {}
  template:
    metadata:
      labels:
        app.kubernetes.io/instance: rester
        app.kubernetes.io/name: rester
        app.kubernetes.io/part-of: rester
        app.kubernetes.io/version: 0.2.7
    spec:
      containers:
      - env:
        image: registry.example.com/rester/rester:0.2.7-21
        imagePullPolicy: Always
        name: rester
        resources:
          limits:
            cpu: 500m
            ephemeral-storage: 512Mi
            memory: 512Mi
          requests:
            cpu: 200m
            ephemeral-storage: 256Mi
            memory: 256Mi
        securityContext:
          allowPrivilegeEscalation: false
          capabilities:
            drop:
            - ALL
      imagePullSecrets:
      - name: private-registry-auth
      securityContext:
        runAsNonRoot: true
        seccompProfile:
          type: RuntimeDefault

The change that introduces an invalid field by schema:

$ git diff
diff --git a/kubernetes/plain/flux-schema-issue/deplyoment.yaml b/kubernetes/plain/flux-schema-issue/deplyoment.yaml
index 50c6aec..98e91e3 100644
--- a/kubernetes/plain/flux-schema-issue/deplyoment.yaml
+++ b/kubernetes/plain/flux-schema-issue/deplyoment.yaml
@@ -18,6 +18,8 @@ spec:
       app.kubernetes.io/name: rester
   strategy: {}
   template:
+    labels:
+      flux-test: test
     metadata:
       labels:
         app.kubernetes.io/instance: rester

kubectl server side diff sees this invalid:

$ kubectl diff -f deployment.yaml --server-side
Error from server: failed to create typed patch object (default/rester; apps/v1, Kind=Deployment): .spec.template.labels: field not declared in schema

flux ignores the schema issue and says everything is fine:

$ flux diff kustomization --namespace=gitops-rester-kustomize-dev rester-on-gitlabx --path=./ --verbose
✓  Kustomization diffing...

NOTE: when we push this change kustomize-controller does the same like flux cli and shows everything in ready state (but obviously the change is not applied)

Steps to reproduce

  • create a deployment and apply it with flux
  • modify the deployment manifest and add .spec.template.labels to it
  • commit the change and wait for reconcile. flux will not report error

Expected behavior

Flux should report an error about the invalid schema so users understand why their "change" is not synced.

Screenshots and recordings

No response

OS / Distro

Ubuntu 24.04 LTS

Flux version

v2.7.5

Flux check

$ flux check
► checking prerequisites
✗ flux 2.7.5 <2.8.3 (new CLI version is available, please upgrade)
✔ Kubernetes 1.34.3-eks-3c60543 >=1.32.0-0
► checking version in cluster
✔ distribution: flux-v2.7.5
✔ bootstrapped: true
► checking controllers
✔ helm-controller: deployment ready
► ghcr.io/fluxcd/helm-controller:v1.4.5
✔ kustomize-controller: deployment ready
► ghcr.io/fluxcd/kustomize-controller:v1.7.3
✔ notification-controller: deployment ready
► ghcr.io/fluxcd/notification-controller:v1.7.5
✔ source-controller: deployment ready
► ghcr.io/fluxcd/source-controller:v1.7.4
► checking crds
✔ alerts.notification.toolkit.fluxcd.io/v1beta3
✔ buckets.source.toolkit.fluxcd.io/v1
✔ externalartifacts.source.toolkit.fluxcd.io/v1
✔ gitrepositories.source.toolkit.fluxcd.io/v1
✔ helmcharts.source.toolkit.fluxcd.io/v1
✔ helmreleases.helm.toolkit.fluxcd.io/v2
✔ helmrepositories.source.toolkit.fluxcd.io/v1
✔ kustomizations.kustomize.toolkit.fluxcd.io/v1
✔ ocirepositories.source.toolkit.fluxcd.io/v1
✔ providers.notification.toolkit.fluxcd.io/v1beta3
✔ receivers.notification.toolkit.fluxcd.io/v1
✔ all checks passed

Git provider

GitLab

Container Registry provider

Harbor

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    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