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

v1.14 Backports 2024-03-15 #31474

Merged
merged 6 commits into from Mar 19, 2024
Merged

v1.14 Backports 2024-03-15 #31474

merged 6 commits into from Mar 19, 2024

Conversation

tklauser
Copy link
Member

@tklauser tklauser commented Mar 19, 2024

[ upstream commit bba0ff5 ]

The functions updateEndpointLabel is only used in one place. Inline it
to improve readability and simplify changes in successive commits.

Signed-off-by: Tobias Klauser <tobias@cilium.io>
[ upstream commit 9a26446 ]

Currently, failure to update endpoint labels based on pod labels on pod
update is silently ignored by the callers or only reflected in error
count metrics. Report a warning to clearly indicate that pod and
endpoint labels might be out of sync.

Signed-off-by: Tobias Klauser <tobias@cilium.io>
[ upstream commit 2309805 ]

Currently GetPodMetadata is the only caller of SanitizePodLabels but
other callers will be introduced in successive changes. This change
ensures the io.cilium.k8s.* labels are filtered for these callers as
well.

Signed-off-by: Tobias Klauser <tobias@cilium.io>
[ upstream commit 5508746 ]

The labels on the CEP are set to the unfiltered pod labels on CEP
creation, see [1]. On any label update where labels contain filtered
labels, e.g. io.cilium.k8s.* labels or labels filtered out by the user
by means of the --label and/or --label-prefix-file agent options the
current logic would wrongly remove the filtered labels from the CEP
labels. Fix this by always using the unfiltered pod labels.

[1] https://github.com/cilium/cilium/blob/b58125d885edbb278f11f84303c0e7c934ca7ea4/pkg/endpointmanager/endpointsynchronizer.go#L185-L187

Signed-off-by: Tobias Klauser <tobias@cilium.io>
[ upstream commit ed4e650 ]

Currently `io.cilium.k8s.*` pod labels are only filtered out on pod
creation. On pod update, they are currently not filtered which leads to
a situation where no pod label update is reflected in the endpoint
anymore in case of a `io.cilium.k8s.*` label set on the pod:

$ cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
  name: foo
  namespace: default
  labels:
    app: foobar
    io.cilium.k8s.something: bazbar
spec:
  containers:
  - name: nginx
    image: nginx:1.25.4
    ports:
    - containerPort: 80
EOF
$ kubectl -n kube-system exec -it cilium-nnnn -- cilium-dbg endpoint list
ENDPOINT   POLICY (ingress)   POLICY (egress)   IDENTITY   LABELS (source:key[=value])                                              IPv6                  IPv4           STATUS
           ENFORCEMENT        ENFORCEMENT
252        Disabled           Disabled          50316      k8s:app=foobar                                                           fd00:10:244:1::8b69   10.244.1.78    ready
                                                           k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=default
                                                           k8s:io.cilium.k8s.policy.cluster=kind-kind
                                                           k8s:io.cilium.k8s.policy.serviceaccount=default
                                                           k8s:io.kubernetes.pod.namespace=default
$ kubectl label pods foo app=nothing --overwrite
$ kubectl describe pod foo
[...]
Labels:           app=nothing
                  io.cilium.k8s.something=bazbar
[...]
$ kubectl describe cep foo
[...]
Labels:       app=foobar
              io.cilium.k8s.something=bazbar
[...]
$ kubectl -n kube-system exec -it cilium-nnnn -- cilium-dbg endpoint list
ENDPOINT   POLICY (ingress)   POLICY (egress)   IDENTITY   LABELS (source:key[=value])                                              IPv6                  IPv4           STATUS
           ENFORCEMENT        ENFORCEMENT
252        Disabled           Disabled          50316      k8s:app=foobar                                                           fd00:10:244:1::8b69   10.244.1.78    ready
                                                           k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=default
                                                           k8s:io.cilium.k8s.policy.cluster=kind-kind
                                                           k8s:io.cilium.k8s.policy.serviceaccount=default
                                                           k8s:io.kubernetes.pod.namespace=default
1285       Disabled           Disabled          1          reserved:host                                                                                                 ready
1297       Disabled           Disabled          4          reserved:health                                                          fd00:10:244:1::ebfb   10.244.1.222   ready

Note that the `app` label didn't change from `foobar` to `nothing` in
the endpoint and the CiliumEndpoint CRD

This is because the filtered labels are passed wrongly passed
to `(*Endpoint).ModifyIdentityLabels` which in turn calls
`e.OpLabels.ModifyIdentityLabels` which checks whether all of the
deleted labels (which contains the filtered label on pod update
for the example above) were present before, i.e. on pod creation. This
check fails however because the labels were filtered out on pod
creation.

Fix this issue by also filtering out the labels on pod update and thus
allowing the label update to successfully complete in the presence of
filtered labels.

After this change, the labels are correctly updated on the endpoint and
the CiliumEndpoint CRD:

$ kubectl label pods foo app=nothing --overwrite
$ kubectl describe pod foo
[...]
Labels:           app=nothing
                  io.cilium.k8s.something=bazbar
[...]
$ kubectl describe cep foo
[...]
Labels:       app=nothing
              io.cilium.k8s.something=bazbar
[...]
$ kubectl -n kube-system exec -it cilium-x2x5r -- cilium-dbg endpoint list
ENDPOINT   POLICY (ingress)   POLICY (egress)   IDENTITY   LABELS (source:key[=value])                                              IPv6                  IPv4           STATUS
           ENFORCEMENT        ENFORCEMENT
57         Disabled           Disabled          56486      k8s:app=nothing                                                          fd00:10:244:1::71b7   10.244.1.187   ready
                                                           k8s:io.cilium.k8s.namespace.labels.kubernetes.io/metadata.name=default
                                                           k8s:io.cilium.k8s.policy.cluster=kind-kind
                                                           k8s:io.cilium.k8s.policy.serviceaccount=default
                                                           k8s:io.kubernetes.pod.namespace=default
201        Disabled           Disabled          4          reserved:health                                                          fd00:10:244:1::c8de   10.244.1.221   ready
956        Disabled           Disabled          1          reserved:host                                                                                                 ready

Fixes: 599dde3 ("k8s: Filter out cilium owned from pod labels")

Signed-off-by: Tobias Klauser <tobias@cilium.io>
[ upstream commit 280b69d ]

Filter the labels before iterating them, otherwise they are added to
sanitizedLabels again. Also remove forbidden keys prefixed with
io.cilium.k8s because they are already filtered out by filterPodLabels
and inline the check for kubernetes namespace labels.

Fixes: ed4e650 ("k8s/utils: filter out cilium-owned labels on pod update")
Signed-off-by: Tobias Klauser <tobias@cilium.io>
@tklauser tklauser added kind/backports This PR provides functionality previously merged into master. backport/1.14 This PR represents a backport for Cilium 1.14.x of a PR that was merged to main. labels Mar 19, 2024
@tklauser tklauser marked this pull request as ready for review March 19, 2024 08:50
@tklauser tklauser requested a review from a team as a code owner March 19, 2024 08:50
@tklauser tklauser temporarily deployed to release-base-images March 19, 2024 08:51 — with GitHub Actions Inactive
@tklauser
Copy link
Member Author

/test-backport-1.14

@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Mar 19, 2024
@tklauser tklauser merged commit 4f7ebad into v1.14 Mar 19, 2024
236 checks passed
@tklauser tklauser deleted the pr/v1.14-backport-2024-03-15-04-32 branch March 19, 2024 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/1.14 This PR represents a backport for Cilium 1.14.x of a PR that was merged to main. kind/backports This PR provides functionality previously merged into master. ready-to-merge This PR has passed all tests and received consensus from code owners to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants