mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
fix a flag replace of container-runtime=remote
This commit is contained in:
parent
b6020d263c
commit
f445764969
@ -279,7 +279,8 @@ func CleanupKubeletDynamicEnvFileContainerRuntime(dryRun bool) error {
|
|||||||
func cleanupKubeletDynamicEnvFileContainerRuntime(str string) string {
|
func cleanupKubeletDynamicEnvFileContainerRuntime(str string) string {
|
||||||
const (
|
const (
|
||||||
// `remote` is the only possible value
|
// `remote` is the only possible value
|
||||||
flag = "container-runtime"
|
containerRuntimeFlag = "container-runtime"
|
||||||
|
endpointFlag = "container-runtime-endpoint"
|
||||||
)
|
)
|
||||||
// Trim the prefix
|
// Trim the prefix
|
||||||
str = strings.TrimLeft(str, fmt.Sprintf("%s=\"", kubeadmconstants.KubeletEnvFileVariableName))
|
str = strings.TrimLeft(str, fmt.Sprintf("%s=\"", kubeadmconstants.KubeletEnvFileVariableName))
|
||||||
@ -289,7 +290,7 @@ func cleanupKubeletDynamicEnvFileContainerRuntime(str string) string {
|
|||||||
// its value to have the scheme prefix.
|
// its value to have the scheme prefix.
|
||||||
split := strings.Split(str, " ")
|
split := strings.Split(str, " ")
|
||||||
for i, s := range split {
|
for i, s := range split {
|
||||||
if !strings.Contains(s, flag) {
|
if !(strings.Contains(s, containerRuntimeFlag) && !strings.Contains(s, endpointFlag)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
keyValue := strings.Split(s, "=")
|
keyValue := strings.Split(s, "=")
|
||||||
@ -309,6 +310,7 @@ func cleanupKubeletDynamicEnvFileContainerRuntime(str string) string {
|
|||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove the flag and value in one
|
// remove the flag and value in one
|
||||||
split = append(split[:i], split[i+1:]...)
|
split = append(split[:i], split[i+1:]...)
|
||||||
}
|
}
|
||||||
|
@ -109,10 +109,15 @@ func TestCleanupKubeletDynamicEnvFileContainerRuntime(t *testing.T) {
|
|||||||
input string
|
input string
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
name: "common flag",
|
||||||
|
input: fmt.Sprintf("%s=\"--container-runtime=remote --container-runtime-endpoint=unix:///var/run/containerd/containerd.sock --pod-infra-container-image=registry.k8s.io/pause:3.8\"", constants.KubeletEnvFileVariableName),
|
||||||
|
expected: fmt.Sprintf("%s=\"--container-runtime-endpoint=unix:///var/run/containerd/containerd.sock --pod-infra-container-image=registry.k8s.io/pause:3.8\"", constants.KubeletEnvFileVariableName),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "missing flag of interest",
|
name: "missing flag of interest",
|
||||||
input: fmt.Sprintf("%s=\"--foo=abc --bar=def\"", constants.KubeletEnvFileVariableName),
|
input: fmt.Sprintf("%s=\"--foo=abc --bar=def --container-runtime-endpoint=unix:///var/run/containerd/containerd.sock\"", constants.KubeletEnvFileVariableName),
|
||||||
expected: fmt.Sprintf("%s=\"--foo=abc --bar=def\"", constants.KubeletEnvFileVariableName),
|
expected: fmt.Sprintf("%s=\"--foo=abc --bar=def --container-runtime-endpoint=unix:///var/run/containerd/containerd.sock\"", constants.KubeletEnvFileVariableName),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "add missing URL scheme",
|
name: "add missing URL scheme",
|
||||||
@ -121,13 +126,13 @@ func TestCleanupKubeletDynamicEnvFileContainerRuntime(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "add missing URL scheme if there is no '=' after the flag name",
|
name: "add missing URL scheme if there is no '=' after the flag name",
|
||||||
input: fmt.Sprintf("%s=\"--foo=abc --container-runtime remote --bar=def\"", constants.KubeletEnvFileVariableName),
|
input: fmt.Sprintf("%s=\"--foo=abc --container-runtime remote --container-runtime-endpoint=unix:///var/run/containerd/containerd.sock --bar=def\"", constants.KubeletEnvFileVariableName),
|
||||||
expected: fmt.Sprintf("%s=\"--foo=abc --bar=def\"", constants.KubeletEnvFileVariableName),
|
expected: fmt.Sprintf("%s=\"--foo=abc --container-runtime-endpoint=unix:///var/run/containerd/containerd.sock --bar=def\"", constants.KubeletEnvFileVariableName),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "empty flag of interest value following '='",
|
name: "empty flag of interest value following '='",
|
||||||
input: fmt.Sprintf("%s=\"--foo=abc --container-runtime= --bar=def\"", constants.KubeletEnvFileVariableName),
|
input: fmt.Sprintf("%s=\"--foo=abc --container-runtime= --container-runtime-endpoint unix:///var/run/containerd/containerd.sock --bar=def\"", constants.KubeletEnvFileVariableName),
|
||||||
expected: fmt.Sprintf("%s=\"--foo=abc --bar=def\"", constants.KubeletEnvFileVariableName),
|
expected: fmt.Sprintf("%s=\"--foo=abc --container-runtime-endpoint unix:///var/run/containerd/containerd.sock --bar=def\"", constants.KubeletEnvFileVariableName),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "empty flag of interest value without '='",
|
name: "empty flag of interest value without '='",
|
||||||
|
Loading…
Reference in New Issue
Block a user