1
0
mirror of synced 2026-06-19 11:50:47 +00:00

Add DriftIgnoreRules support to flux diff kustomization

Signed-off-by: Dipti Pai <diptipai89@outlook.com>
Assisted-by: GitHub Copilot/Claude Opus 4.7
This commit is contained in:
Dipti Pai
2026-06-01 15:26:50 -07:00
parent a969646a56
commit 4e815ab5e2
5 changed files with 108 additions and 0 deletions
+33
View File
@@ -270,3 +270,36 @@ func createObjectFromFile(objectFile string, templateValues map[string]string, t
return clientObjects
}
// TestDiffKustomizationDriftIgnoreRules tests `flux diff ks` with drift ignore
// rules. A service with a drifted port is pre-applied to the cluster, and the
// kustomization specifies driftIgnoreRules that ignore /spec/ports on Services.
// The diff should not show the service as drifted.
func TestDiffKustomizationDriftIgnoreRules(t *testing.T) {
tmpl := map[string]string{
"fluxns": allocateNamespace("flux-system"),
}
setupTestNamespace(tmpl["fluxns"], t)
b, _ := build.NewBuilder("podinfo", "", build.WithClientConfig(kubeconfigArgs, kubeclientOptions))
resourceManager, err := b.Manager()
if err != nil {
t.Fatal(err)
}
// Pre-apply the drifted service (port 9899 instead of 9898) without Flux labels.
if _, err := resourceManager.ApplyAll(context.Background(), createObjectFromFile("./testdata/diff-kustomization/drifted-service-no-labels.yaml", tmpl, t), ssa.DefaultApplyOptions()); err != nil {
t.Fatal(err)
}
cmd := cmdTestCase{
args: "diff kustomization podinfo --path ./testdata/build-kustomization/podinfo --progress-bar=false " +
"--kustomization-file ./testdata/diff-kustomization/flux-kustomization-drift-ignore.yaml " +
"--ignore-not-found" +
" -n " + tmpl["fluxns"],
assert: assertGoldenFile("./testdata/diff-kustomization/diff-with-drift-ignore.golden"),
}
cmd.runTestCmd(t)
testEnv.DeleteObjectFile("./testdata/diff-kustomization/drifted-service-no-labels.yaml", tmpl, t)
}
@@ -0,0 +1,14 @@
► Deployment/default/podinfo created
► HorizontalPodAutoscaler/default/podinfo created
► Service/default/podinfo drifted
metadata
+ one map entry added:
labels:
kustomize.toolkit.fluxcd.io/name: podinfo
kustomize.toolkit.fluxcd.io/namespace:
► Secret/default/docker-secret created
► Secret/default/secret-basic-auth-stringdata created
► Secret/default/podinfo-token-77t89m9b67 created
► Secret/default/db-user-pass-bkbd782d2c created
@@ -0,0 +1,18 @@
apiVersion: v1
kind: Service
metadata:
name: podinfo
namespace: default
spec:
type: ClusterIP
selector:
app: podinfo
ports:
- name: http
port: 9899
protocol: TCP
targetPort: http
- port: 9999
targetPort: grpc
protocol: TCP
name: grpc
@@ -0,0 +1,19 @@
---
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: podinfo
spec:
interval: 5m0s
path: ./kustomize
force: true
prune: true
sourceRef:
kind: GitRepository
name: podinfo
targetNamespace: default
ignore:
- paths:
- "/spec/ports"
target:
kind: Service