...

Source file src/k8s.io/kubernetes/cmd/kubeadm/app/componentconfigs/kubelet_windows_test.go

Documentation: k8s.io/kubernetes/cmd/kubeadm/app/componentconfigs

     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 componentconfigs
    18  
    19  import (
    20  	"path/filepath"
    21  	"reflect"
    22  	"testing"
    23  
    24  	kubeletconfig "k8s.io/kubelet/config/v1beta1"
    25  	"k8s.io/utils/ptr"
    26  )
    27  
    28  func TestMutatePaths(t *testing.T) {
    29  	const drive = "C:"
    30  	var fooResolverConfig string = "/foo/resolver"
    31  
    32  	tests := []struct {
    33  		name     string
    34  		cfg      *kubeletconfig.KubeletConfiguration
    35  		expected *kubeletconfig.KubeletConfiguration
    36  	}{
    37  		{
    38  			name: "valid: all fields are absolute paths",
    39  			cfg: &kubeletconfig.KubeletConfiguration{
    40  				ResolverConfig: &fooResolverConfig,
    41  				StaticPodPath:  "/foo/staticpods",
    42  				Authentication: kubeletconfig.KubeletAuthentication{
    43  					X509: kubeletconfig.KubeletX509Authentication{
    44  						ClientCAFile: "/foo/ca.crt",
    45  					},
    46  				},
    47  			},
    48  			expected: &kubeletconfig.KubeletConfiguration{
    49  				ResolverConfig: ptr.To(""),
    50  				StaticPodPath:  filepath.Join(drive, "/foo/staticpods"),
    51  				Authentication: kubeletconfig.KubeletAuthentication{
    52  					X509: kubeletconfig.KubeletX509Authentication{
    53  						ClientCAFile: filepath.Join(drive, "/foo/ca.crt"),
    54  					},
    55  				},
    56  			},
    57  		},
    58  		{
    59  			name: "valid: some fields are not absolute paths",
    60  			cfg: &kubeletconfig.KubeletConfiguration{
    61  				ResolverConfig: &fooResolverConfig,
    62  				StaticPodPath:  "./foo/staticpods", // not an absolute Unix path
    63  				Authentication: kubeletconfig.KubeletAuthentication{
    64  					X509: kubeletconfig.KubeletX509Authentication{
    65  						ClientCAFile: "/foo/ca.crt",
    66  					},
    67  				},
    68  			},
    69  			expected: &kubeletconfig.KubeletConfiguration{
    70  				ResolverConfig: ptr.To(""),
    71  				StaticPodPath:  "./foo/staticpods",
    72  				Authentication: kubeletconfig.KubeletAuthentication{
    73  					X509: kubeletconfig.KubeletX509Authentication{
    74  						ClientCAFile: filepath.Join(drive, "/foo/ca.crt"),
    75  					},
    76  				},
    77  			},
    78  		},
    79  	}
    80  
    81  	for _, test := range tests {
    82  		t.Run(test.name, func(t *testing.T) {
    83  			mutatePaths(test.cfg, drive)
    84  			if !reflect.DeepEqual(test.cfg, test.expected) {
    85  				t.Errorf("Missmatch between expected and got:\nExpected:\n%+v\n---\nGot:\n%+v",
    86  					test.expected, test.cfg)
    87  			}
    88  		})
    89  	}
    90  }
    91  

View as plain text