...

Source file src/k8s.io/kubernetes/pkg/kubelet/container/testing/fake_runtime_helper.go

Documentation: k8s.io/kubernetes/pkg/kubelet/container/testing

     1  /*
     2  Copyright 2017 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 testing
    18  
    19  import (
    20  	"context"
    21  
    22  	v1 "k8s.io/api/core/v1"
    23  	kubetypes "k8s.io/apimachinery/pkg/types"
    24  	runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
    25  	kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
    26  )
    27  
    28  // FakeRuntimeHelper implements RuntimeHelper interfaces for testing purposes.
    29  type FakeRuntimeHelper struct {
    30  	DNSServers      []string
    31  	DNSSearches     []string
    32  	DNSOptions      []string
    33  	HostName        string
    34  	HostDomain      string
    35  	PodContainerDir string
    36  	Err             error
    37  }
    38  
    39  func (f *FakeRuntimeHelper) GenerateRunContainerOptions(_ context.Context, pod *v1.Pod, container *v1.Container, podIP string, podIPs []string) (*kubecontainer.RunContainerOptions, func(), error) {
    40  	var opts kubecontainer.RunContainerOptions
    41  	if len(container.TerminationMessagePath) != 0 {
    42  		opts.PodContainerDir = f.PodContainerDir
    43  	}
    44  	return &opts, nil, nil
    45  }
    46  
    47  func (f *FakeRuntimeHelper) GetPodCgroupParent(pod *v1.Pod) string {
    48  	return ""
    49  }
    50  
    51  func (f *FakeRuntimeHelper) GetPodDNS(pod *v1.Pod) (*runtimeapi.DNSConfig, error) {
    52  	return &runtimeapi.DNSConfig{
    53  		Servers:  f.DNSServers,
    54  		Searches: f.DNSSearches,
    55  		Options:  f.DNSOptions}, f.Err
    56  }
    57  
    58  // This is not used by docker runtime.
    59  func (f *FakeRuntimeHelper) GeneratePodHostNameAndDomain(pod *v1.Pod) (string, string, error) {
    60  	return f.HostName, f.HostDomain, f.Err
    61  }
    62  
    63  func (f *FakeRuntimeHelper) GetPodDir(podUID kubetypes.UID) string {
    64  	return "/poddir/" + string(podUID)
    65  }
    66  
    67  func (f *FakeRuntimeHelper) GetExtraSupplementalGroupsForPod(pod *v1.Pod) []int64 {
    68  	return nil
    69  }
    70  
    71  func (f *FakeRuntimeHelper) GetOrCreateUserNamespaceMappings(pod *v1.Pod, runtimeHandler string) (*runtimeapi.UserNamespace, error) {
    72  	return nil, nil
    73  }
    74  
    75  func (f *FakeRuntimeHelper) PrepareDynamicResources(pod *v1.Pod) error {
    76  	return nil
    77  }
    78  
    79  func (f *FakeRuntimeHelper) UnprepareDynamicResources(pod *v1.Pod) error {
    80  	return nil
    81  }
    82  

View as plain text