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 |
||
---|---|---|
.. | ||
apply | ||
apps | ||
categories | ||
cmd | ||
explain | ||
metricsutil | ||
plugins | ||
proxy | ||
resource | ||
scheme | ||
util | ||
validation | ||
.import-restrictions | ||
BUILD | ||
OWNERS | ||
apply.go | ||
autoscale.go | ||
autoscale_test.go | ||
bash_comp_utils.go | ||
clusterrolebinding.go | ||
clusterrolebinding_test.go | ||
conditions.go | ||
configmap.go | ||
configmap_test.go | ||
delete.go | ||
delete_test.go | ||
deployment.go | ||
deployment_test.go | ||
doc.go | ||
env_file.go | ||
env_file_test.go | ||
generate.go | ||
generate_test.go | ||
history.go | ||
history_test.go | ||
interfaces.go | ||
kubectl.go | ||
namespace.go | ||
namespace_test.go | ||
pdb.go | ||
pdb_test.go | ||
priorityclass.go | ||
priorityclass_test.go | ||
quota.go | ||
quota_test.go | ||
rolebinding.go | ||
rolebinding_test.go | ||
rollback.go | ||
rollback_test.go | ||
rolling_updater.go | ||
rolling_updater_test.go | ||
rollout_status.go | ||
rollout_status_test.go | ||
run.go | ||
run_test.go | ||
scale.go | ||
scale_test.go | ||
secret.go | ||
secret_for_docker_registry.go | ||
secret_for_docker_registry_test.go | ||
secret_for_tls.go | ||
secret_for_tls_test.go | ||
secret_test.go | ||
service.go | ||
service_basic.go | ||
service_basic_test.go | ||
service_test.go | ||
serviceaccount.go | ||
serviceaccount_test.go | ||
sorting_printer.go | ||
sorting_printer_test.go |