kubeadm: conditionally set the kubelet cgroup driver for Docker
Add a new utility file - util/cgroupdriver.go. Currently it only contains the public function GetCgroupDriverDocker(). The function uses 'docker info' to obtain the cgroup driver for Docker. On a later stage this file can contain more methods for different CRI. Use GetCgroupDriverDocker() in phases/kubelet/flags.go to conditionally set the 'cgroup-driver' argument. On error print a warning and don't set the argument value. Add unit tests in cgroupdriver_test.go.
This commit is contained in:
68
cmd/kubeadm/app/util/cgroupdriver_test.go
Normal file
68
cmd/kubeadm/app/util/cgroupdriver_test.go
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package util
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetCgroupDriverDocker(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
info string
|
||||
expectedError bool
|
||||
}{
|
||||
{
|
||||
name: "valid: value is 'cgroupfs'",
|
||||
info: `Cgroup Driver: cgroupfs`,
|
||||
expectedError: false,
|
||||
},
|
||||
{
|
||||
name: "valid: value is 'systemd'",
|
||||
info: `Cgroup Driver: systemd`,
|
||||
expectedError: false,
|
||||
},
|
||||
{
|
||||
name: "invalid: missing 'Cgroup Driver' key and value",
|
||||
info: "",
|
||||
expectedError: true,
|
||||
},
|
||||
{
|
||||
name: "invalid: only a 'Cgroup Driver' key is present",
|
||||
info: `Cgroup Driver`,
|
||||
expectedError: true,
|
||||
},
|
||||
{
|
||||
name: "invalid: empty 'Cgroup Driver' value",
|
||||
info: `Cgroup Driver: `,
|
||||
expectedError: true,
|
||||
},
|
||||
{
|
||||
name: "invalid: unknown 'Cgroup Driver' value",
|
||||
info: `Cgroup Driver: invalid-value`,
|
||||
expectedError: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if _, err := getCgroupDriverFromDockerInfo(tc.info); (err != nil) != tc.expectedError {
|
||||
t.Fatalf("expected error: %v, saw: %v, error: %v", tc.expectedError, (err != nil), err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user