k3s/pkg/kubelet/kuberuntime
Kubernetes Submit Queue ce5c41ab0f Merge pull request #52363 from balajismaniam/fix-cpuman-restartpol-never-bug
Automatic merge from submit-queue (batch tested with PRs 52442, 52247, 46542, 52363, 51781)

Make CPU manager release CPUs when Pod enters completed phase. 

**What this PR does / why we need it**: When CPU manager is enabled, this PR releases allocated CPUs when container is not running and is non-restartable. 

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #52351

**Special notes for your reviewer**:
This bug is only reproduced for pods with `restartPolicy` = `Never` or `OnFailure`.  The following output is from a 4 CPU node. This bug can be reproduced as long >= half the cores are requested. 

pod1.yaml:
```
apiVersion: v1
kind: Pod
metadata:
  name: test-pod1
spec:
  containers:
  - image: ubuntu
    command: ["/bin/bash"]
    args: ["-c", "sleep 5"]
    name: test-container1
    resources:
      requests:
        cpu: 2
        memory: 100Mi
      limits:
        cpu: 2
        memory: 100Mi
  restartPolicy: "Never"
```

pod2.yaml:
```
apiVersion: v1
kind: Pod
metadata:
  name: test-pod2
spec:
  containers:
  - image: ubuntu
    command: ["/bin/bash"]
    args: ["-c", "sleep 5"]
    name: test-container1
    resources:
      requests:
        cpu: 2
        memory: 100Mi
      limits:
        cpu: 2
        memory: 100Mi
  restartPolicy: "Never"
```
Run a local Kubernetes cluster with CPU manager enabled. 
```sh
KUBELET_FLAGS='--feature-gates=CPUManager=true --cpu-manager-policy=static --cpu-manager-reconcile-period=1s --kube-reserved=cpu=500m' ./hack/local-up-cluster.sh
```
_Before:_
Create `test-pod1` using pod1.yaml. 
```
./cluster/kubectl.sh create -f pod1.yaml
```
Wait for the pod to complete and wait another 90 seconds (give enough time for GC to kick-in). 

Create `test-pod2` using pod2.yaml. 
```
./cluster/kubectl.sh create -f pod2.yaml
```

Get all pods in the cluster. 
```
./cluster/kubectl.sh get pods -a
NAME        READY     STATUS                                         RESTARTS   AGE
test-pod1   0/1       Completed                                      0          1m
test-pod2   0/1       not enough cpus available to satisfy request   0          9s
```

_After:_
Create `test-pod1` using pod1.yaml. 
```
./cluster/kubectl.sh create -f pod1.yaml
```
Wait for the pod to complete and wait another 90 seconds (give enough time for GC to kick-in). 

Create `test-pod2` using pod2.yaml. 
```
./cluster/kubectl.sh create -f pod2.yaml
```

Get all pods in the cluster. 
```
./cluster/kubectl.sh get pods -a
NAME        READY     STATUS      RESTARTS   AGE
test-pod1   0/1       Completed    0          1m
test-pod2   0/1       Completed    0          9s
```
2017-09-15 00:11:14 -07:00
..
BUILD Un-revert "CPU manager wiring and `none` policy" 2017-09-04 07:24:59 -07:00
doc.go
fake_kuberuntime_manager.go Merge pull request #50350 from dashpole/eviction_container_deletion 2017-09-05 17:30:03 -07:00
helpers.go Rename runtime/default to docker default 2017-08-13 15:42:15 +08:00
helpers_test.go follow our go code style: error->err 2017-07-07 09:34:38 +08:00
instrumented_services.go add UpdateContainerResources function to CRI 2017-07-31 20:47:56 -05:00
instrumented_services_test.go Improving test coverage for kubelet/kuberuntime. 2017-06-01 09:43:15 +02:00
kuberuntime_container.go Merge pull request #50350 from dashpole/eviction_container_deletion 2017-09-05 17:30:03 -07:00
kuberuntime_container_test.go Do not try run preStop hook when the gracePeriod is 0 2017-08-03 07:57:21 +05:30
kuberuntime_gc.go wait for container cleanup before deletion 2017-09-04 17:38:09 -07:00
kuberuntime_gc_test.go wait for container cleanup before deletion 2017-09-04 17:38:09 -07:00
kuberuntime_image.go run hack/update-all 2017-06-22 11:31:03 -07:00
kuberuntime_image_test.go run hack/update-all 2017-06-22 11:31:03 -07:00
kuberuntime_logs.go Use local JSON log buffer in parseDockerJSONLog. 2017-08-09 12:41:15 -04:00
kuberuntime_logs_test.go run hack/update-all 2017-06-22 11:31:03 -07:00
kuberuntime_manager.go Merge pull request #52363 from balajismaniam/fix-cpuman-restartpol-never-bug 2017-09-15 00:11:14 -07:00
kuberuntime_manager_test.go Refactor kuberuntime test case with sets.String 2017-08-22 19:43:18 +08:00
kuberuntime_sandbox.go Support seccomp profile from container's security context 2017-08-13 15:42:15 +08:00
kuberuntime_sandbox_test.go run hack/update-all 2017-06-22 11:31:03 -07:00
labels.go run hack/update-all 2017-06-22 11:31:03 -07:00
labels_test.go run hack/update-all 2017-06-22 11:31:03 -07:00
legacy.go Move legacy log symlink to kuberuntime 2017-05-05 11:48:08 -07:00
legacy_test.go Move legacy log symlink to kuberuntime 2017-05-05 11:48:08 -07:00
security_context.go Support seccomp profile from container's security context 2017-08-13 15:42:15 +08:00
security_context_test.go run hack/update-all 2017-06-22 11:31:03 -07:00