carvel-dev / kapp

kapp is a simple deployment tool focused on the concept of "Kubernetes application" — a set of resources with the same label

Home Page:https://carvel.dev/kapp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

hasAnnotationMatcher not working

antwacky opened this issue · comments

What steps did you take:

I have the below kapp config, which I expect to ignore changed to the labels field on all resources with the kapp.k14s.io/change-group.app annotation:

diffAgainstLastAppliedFieldExclusionRules:
- path: [metadata, labels]
  resourceMatchers:
    - hasAnnotationMatcher:
        keys:
        - "kapp.k14s.io/change-group.app"

What happened:

Kapp still detects changed to the labels for those resources with the given annotation.

What did you expect:

Kapp to ignore changes to those labels for resources with the given annotation.

Environment:

  • kapp version (use kapp --version):
kapp version 0.62.0
  • OS (e.g. from /etc/os-release):
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
  • Kubernetes version (use kubectl version)
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short.  Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:"1", Minor:"25", GitVersion:"v1.25.16", GitCommit:"c5f43560a4f98f2af3743a59299fb79f07924373", GitTreeState:"clean", BuildDate:"2023-11-15T22:39:12Z", GoVersion:"go1.20.10", Compiler:"gc", Platform:"linux/amd64"}
Kustomize Version: v4.5.7
Server Version: version.Info{Major:"1", Minor:"24", GitVersion:"v1.24.17+k3s1", GitCommit:"026bb0ec396744e93f870b624b6871de85de0ff9", GitTreeState:"clean", BuildDate:"2023-09-05T20:48:24Z", GoVersion:"go1.20.7", Compiler:"gc", Platform:"linux/amd64"}

Hey @antwacky!
If your intention is to not update certain fields, then I would recommend using the rebase rules. So for your use case, you can have something like:

rebaseRules:
- path: [metadata, labels]
  type: copy
  sources: [existing]
  resourceMatchers:
    - hasAnnotationMatcher:
        keys:
        - "kapp.k14s.io/change-group.app"

The LastApplied in diffAgainstLastAppliedFieldExclusionRules is something that kapp uses to do a "smart diff", so diffAgainstLast... is generally helpful for scenarios where something is not tracked in LastApplied. The matcher should be working fine, you can try using the - allMatcher: {} instead of it and I am sure that it would have the same result with diffAgainstLast....

That works, thanks :)