kubernetes / kubernetes/kubectl
kubectl label output from file input with multiple objects does not include a document separator
- Dominant language
- Go
- Stars
- 3.3k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
**What happened**:
When running "kubectl label" with file input containing multiple objects no document separator is included in the output. This means only the last object will be picked up to be labelled on the cluster (or passed on to an apply command etc).
**What you expected to happen**:
Multiple objects labelled with a document separator in between.
**How to reproduce it (as minimally and precisely as possible)**:
```
cat < /tmp/cm_test.yaml
apiVersion: v1
items:
- apiVersion: v1
kind: ConfigMap
metadata:
name: test1
- apiVersion: v1
kind: ConfigMap
metadata:
name: test2
kind: List
metadata:
resourceVersion: ""
selfLink: ""
EOF
cat /tmp/cm_test.yaml | kubectl label testlabel=foo -o yaml -f - --local
```
Output:
```
apiVersion: v1
kind: ConfigMap
metadata:
labels:
testlabel: foo
name: test1
apiVersion: v1 # No record separator here
kind: ConfigMap
metadata:
labels:
testlabel: foo
name: test2
```
**Anything else we need to know?**:
The same process and data but using the "annotate" command instead of "label" works perfectly and includes document separators. as per output below.
```
apiVersion: v1
kind: ConfigMap
metadata:
annotations:
testlabel: foo
name: test1
---
apiVersion: v1
kind: ConfigMap
metadata:
annotations:
testlabel: foo
name: test2
```
**Environment**:
- Kubernetes client and server versions (use `kubectl version`):
```
Client Version: version.Info{Major:"1", Minor:"24", GitVersion:"v1.24.0", GitCommit:"4ce5a8954017644c5420bae81d72b09b735c21f0", GitTreeState:"clean", BuildDate:"2022-05-03T13:46:05Z", GoVersion:"go1.18.1", Compiler:"gc", Platform:"linux/amd64"}
Kustomize Version: v4.5.4
Server Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.5+70fb84c", GitCommit:"3c28e7a79b58e78b4c1dc1ab7e5f6c6c2d3aedd3", GitTreeState:"clean", BuildDate:"2022-04-25T15:58:12Z", GoVersion:"go1.17.5", Compiler:"gc", Platform:"linux/amd64"}
```
Contributor guide
Research direction
Reproduce the issue with the provided multi-object ConfigMap input and compare `kubectl label` output with the working `kubectl annotate` output. Trace the label command's output path and verify that multiple labelled objects are separated by `---`, then rerun the reproduction command to confirm the output can be consumed as separate documents.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 66/100