...

Source file src/k8s.io/kubernetes/pkg/kubelet/sysctl/util_test.go

Documentation: k8s.io/kubernetes/pkg/kubelet/sysctl

     1  /*
     2  Copyright 2021 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package sysctl
    18  
    19  import (
    20  	"testing"
    21  
    22  	v1 "k8s.io/api/core/v1"
    23  
    24  	"github.com/stretchr/testify/assert"
    25  )
    26  
    27  // TestConvertPodSysctlsVariableToDotsSeparator tests whether the sysctls variable
    28  // can be correctly converted to a dot as a separator.
    29  func TestConvertPodSysctlsVariableToDotsSeparator(t *testing.T) {
    30  
    31  	sysctls := []v1.Sysctl{
    32  		{
    33  			Name:  "kernel.msgmax",
    34  			Value: "8192",
    35  		},
    36  		{
    37  			Name:  "kernel.shm_rmid_forced",
    38  			Value: "1",
    39  		},
    40  		{
    41  			Name:  "net.ipv4.conf.eno2/100.rp_filter",
    42  			Value: "1",
    43  		},
    44  		{
    45  			Name:  "net/ipv4/ip_local_port_range",
    46  			Value: "1024 65535",
    47  		},
    48  	}
    49  	exceptSysctls := []v1.Sysctl{
    50  		{
    51  			Name:  "kernel.msgmax",
    52  			Value: "8192",
    53  		},
    54  		{
    55  			Name:  "kernel.shm_rmid_forced",
    56  			Value: "1",
    57  		},
    58  		{
    59  			Name:  "net.ipv4.conf.eno2/100.rp_filter",
    60  			Value: "1",
    61  		},
    62  		{
    63  			Name:  "net.ipv4.ip_local_port_range",
    64  			Value: "1024 65535",
    65  		},
    66  	}
    67  	securityContext := &v1.PodSecurityContext{
    68  		Sysctls: sysctls,
    69  	}
    70  
    71  	ConvertPodSysctlsVariableToDotsSeparator(securityContext)
    72  	assert.Equalf(t, exceptSysctls, securityContext.Sysctls, "The sysctls name was not converted correctly. got: %s, want: %s", securityContext.Sysctls, exceptSysctls)
    73  
    74  }
    75  

View as plain text