mirror of https://github.com/k3s-io/k3s
![]() Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. kubectl: fix a panic when createGeneratedObject failed **What this PR does / why we need it**: This PR fixed two bugs in the `kubectl run` command. The first commit fixed a panic that can be reproduced with the following two commands: ```bash kubectl run --image=alpine hello -- sleep 1d kubectl run --image=alpine --stdin --tty --attach hello -- /bin/sh ``` When the panic happens, the stack trace is as the following: ``` panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x12f92e6] goroutine 1 [running]: k8s.io/kubernetes/pkg/kubectl/cmd.RunRun(0x1890d20, 0xc4207f6210, 0x184e700, 0xc42000c010, 0x184e720, 0xc42000c018, 0x184e720, 0xc42000c020, 0xc42052ef00, 0xc42054f980, ...) /home/star/go/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/pkg/kubectl/cmd/run.go:328 +0x10b6 k8s.io/kubernetes/pkg/kubectl/cmd.NewCmdRun.func1(0xc42052ef00, 0xc42054f980, 0x2, 0x8) /home/star/go/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/pkg/kubectl/cmd/run.go:105 +0x144 ... ``` The reason for the panic is that the original code didn't handle the error returned by `createGeneratedObject` correctly. See https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/cmd/run.go#L281 If the function `createGeneratedObject` fails, the returned `runObject` will be `nil`. At https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/cmd/run.go#L328 a nil pointer dereference will happen. The second problem this PR fixed is a resource leak if both `--rm` and `--expose` flags are provided. The original code used a map (https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/cmd/run.go#L280) to trace the created objects. But at https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/cmd/run.go#L296 the code will overwrite the previously created object with the same key. So at https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/cmd/run.go#L348 only the service will be deleted. The deployment will be left behind. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ``` /kind bug /sig cli |
||
---|---|---|
.. | ||
api | ||
apis | ||
auth | ||
capabilities | ||
client | ||
cloudprovider | ||
controller | ||
credentialprovider | ||
features | ||
fieldpath | ||
generated | ||
kubeapiserver | ||
kubectl | ||
kubelet | ||
kubemark | ||
master | ||
printers | ||
probe | ||
proxy | ||
quota | ||
registry | ||
routes | ||
scheduler | ||
security | ||
securitycontext | ||
serviceaccount | ||
ssh | ||
util | ||
version | ||
volume | ||
watch/json | ||
windows/service | ||
.import-restrictions | ||
BUILD | ||
OWNERS |