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)
}