-
Notifications
You must be signed in to change notification settings - Fork 952
kubectl apply with "--selector" fails if an unrelated label is set to Null #1743
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
Comments
This issue is currently awaiting triage. SIG CLI takes a lead on issue triage for this repo, but any Kubernetes member can accept issues by applying the The Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Do you mean this I'm not sure that kubectl apply supports setting a label on command line (i.e. -l='label_b=bar') while you are passing a file to be applied (i.e. -f test_file.yaml). |
Yes. If the file does not contain If the resource contains
The |
Did you try |
I don't think the order of the arguments matters 🤔. I tried it nevertheless and still fails. |
Thank you for testing. Could you please try |
> kubectl apply -l='label_b=bar' --server-side -f test_file.yaml
error: no objects passed to apply |
I tried these steps and it didn't fail;
firstly create resource;
After that I re-applied;
I've used kubectl that is built from master branch. |
I just tried it with v1.33.0 and it works. Maybe there was a change in the newer versions of kubectl that fixes the problem! kubectl version --client
Client Version: v1.33.0 client-side apply: > kubectl apply -f test_cm.yaml -l='label_b=bar'
configmap/test-config created
> k get cm test-config -oyaml
apiVersion: v1
data:
config_key_1: value1
kind: ConfigMap
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","data":{"config_key_1":"value1"},"kind":"ConfigMap","metadata":{"annotations":{},"labels":{"app.kubernetes.io/version":"v1.0.0","label_a":null,"label_b":"bar"},"name":"test-config","namespace":"default"}}
creationTimestamp: "2025-05-12T10:06:08Z"
labels:
app.kubernetes.io/version: v1.0.0
label_b: bar
name: test-config
namespace: default
... server-side apply
For server-side the resource contains As far as I am concerned, it seems that the newer versions of kubectl do not show the issue with the label selector anymore and I just need to update my version to the latest. Thank you for checking and your help @ardaguclu |
Thank you for your collaboration @fjolublar I think we can close this issue. WDYT? |
Yes. Closing this issue. Thank you again. |
What happened:
If you have a resource with 2+ labels and one of the labels is set to
Null
or is emptykubectl apply
works with no issues.If you try to apply the resource using a selector
-l
the apply command fails with not so useful error message:What you expected to happen:
The filtering should work.
The existing error message caused confusion because the label that we are searching for is actually set and we would expect that the filtering would find that resource.
How to reproduce it (as minimally and precisely as possible):
Create a
test_file.yaml
with a CM resource definition.>> kubectl apply -f test_file.yaml configmap/test-config created
If you try to apply the resource using a selector
-l
the apply command fails with not so useful error message:The
label_a
being Null/missing is causing issues with the-l
label selector, even thoughlabel_b
is being filtered.Anything else we need to know?:
Environment:
kubectl version
): Client Version: v1.30.5, Server Version: v1.31.4cat /etc/os-release
): Darwin 24.4.0 Darwin Kernel Version 24.4.0:The text was updated successfully, but these errors were encountered: