...

Source file src/k8s.io/kubernetes/pkg/kubelet/volumemanager/volume_manager_fake.go

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

     1  /*
     2  Copyright 2019 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 volumemanager
    18  
    19  import (
    20  	"context"
    21  
    22  	v1 "k8s.io/api/core/v1"
    23  	"k8s.io/kubernetes/pkg/kubelet/config"
    24  	"k8s.io/kubernetes/pkg/kubelet/container"
    25  	"k8s.io/kubernetes/pkg/volume/util/types"
    26  )
    27  
    28  // FakeVolumeManager is a test implementation that just tracks calls
    29  type FakeVolumeManager struct {
    30  	volumes       map[v1.UniqueVolumeName]bool
    31  	reportedInUse map[v1.UniqueVolumeName]bool
    32  }
    33  
    34  // NewFakeVolumeManager creates a new VolumeManager test instance
    35  func NewFakeVolumeManager(initialVolumes []v1.UniqueVolumeName) *FakeVolumeManager {
    36  	volumes := map[v1.UniqueVolumeName]bool{}
    37  	for _, v := range initialVolumes {
    38  		volumes[v] = true
    39  	}
    40  	return &FakeVolumeManager{
    41  		volumes:       volumes,
    42  		reportedInUse: map[v1.UniqueVolumeName]bool{},
    43  	}
    44  }
    45  
    46  // Run is not implemented
    47  func (f *FakeVolumeManager) Run(sourcesReady config.SourcesReady, stopCh <-chan struct{}) {
    48  }
    49  
    50  // WaitForAttachAndMount is not implemented
    51  func (f *FakeVolumeManager) WaitForAttachAndMount(ctx context.Context, pod *v1.Pod) error {
    52  	return nil
    53  }
    54  
    55  // WaitForUnmount is not implemented
    56  func (f *FakeVolumeManager) WaitForUnmount(ctx context.Context, pod *v1.Pod) error {
    57  	return nil
    58  }
    59  
    60  // GetMountedVolumesForPod is not implemented
    61  func (f *FakeVolumeManager) GetMountedVolumesForPod(podName types.UniquePodName) container.VolumeMap {
    62  	return nil
    63  }
    64  
    65  // GetPossiblyMountedVolumesForPod is not implemented
    66  func (f *FakeVolumeManager) GetPossiblyMountedVolumesForPod(podName types.UniquePodName) container.VolumeMap {
    67  	return nil
    68  }
    69  
    70  // GetExtraSupplementalGroupsForPod is not implemented
    71  func (f *FakeVolumeManager) GetExtraSupplementalGroupsForPod(pod *v1.Pod) []int64 {
    72  	return nil
    73  }
    74  
    75  // GetVolumesInUse returns a list of the initial volumes
    76  func (f *FakeVolumeManager) GetVolumesInUse() []v1.UniqueVolumeName {
    77  	inuse := []v1.UniqueVolumeName{}
    78  	for v := range f.volumes {
    79  		inuse = append(inuse, v)
    80  	}
    81  	return inuse
    82  }
    83  
    84  // ReconcilerStatesHasBeenSynced is not implemented
    85  func (f *FakeVolumeManager) ReconcilerStatesHasBeenSynced() bool {
    86  	return true
    87  }
    88  
    89  // VolumeIsAttached is not implemented
    90  func (f *FakeVolumeManager) VolumeIsAttached(volumeName v1.UniqueVolumeName) bool {
    91  	return false
    92  }
    93  
    94  // MarkVolumesAsReportedInUse adds the given volumes to the reportedInUse map
    95  func (f *FakeVolumeManager) MarkVolumesAsReportedInUse(volumesReportedAsInUse []v1.UniqueVolumeName) {
    96  	for _, reportedVolume := range volumesReportedAsInUse {
    97  		if _, ok := f.volumes[reportedVolume]; ok {
    98  			f.reportedInUse[reportedVolume] = true
    99  		}
   100  	}
   101  }
   102  
   103  // GetVolumesReportedInUse is a test function only that returns a list of volumes
   104  // from the reportedInUse map
   105  func (f *FakeVolumeManager) GetVolumesReportedInUse() []v1.UniqueVolumeName {
   106  	inuse := []v1.UniqueVolumeName{}
   107  	for reportedVolume := range f.reportedInUse {
   108  		inuse = append(inuse, reportedVolume)
   109  	}
   110  	return inuse
   111  }
   112  

View as plain text