github.com/jingruilea/kubeedge@v1.2.0-beta.0.0.20200410162146-4bb8902b3879/edge/pkg/edged/volume/csi/csi_drivers_store.go (about) 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 KubeEdge Authors: To create mini-kubelet for edge deployment scenario, 17 this file is derived from kubernetes v1.15.3, 18 and the full file path is k8s.io/kubernetes/pkg/volume/csi/csi_drivers_store.go 19 */ 20 21 package csi 22 23 import ( 24 "sync" 25 26 utilversion "k8s.io/apimachinery/pkg/util/version" 27 ) 28 29 // Driver is a description of a CSI Driver, defined by an endpoint and the 30 // highest CSI version supported 31 type Driver struct { 32 endpoint string 33 highestSupportedVersion *utilversion.Version 34 } 35 36 // DriversStore holds a list of CSI Drivers 37 type DriversStore struct { 38 store 39 sync.RWMutex 40 } 41 42 type store map[string]Driver 43 44 // Get lets you retrieve a CSI Driver by name. 45 // This method is protected by a mutex. 46 func (s *DriversStore) Get(driverName string) (Driver, bool) { 47 s.RLock() 48 defer s.RUnlock() 49 50 driver, ok := s.store[driverName] 51 return driver, ok 52 } 53 54 // Set lets you save a CSI Driver to the list and give it a specific name. 55 // This method is protected by a mutex. 56 func (s *DriversStore) Set(driverName string, driver Driver) { 57 s.Lock() 58 defer s.Unlock() 59 60 if s.store == nil { 61 s.store = store{} 62 } 63 64 s.store[driverName] = driver 65 } 66 67 // Delete lets you delete a CSI Driver by name. 68 // This method is protected by a mutex. 69 func (s *DriversStore) Delete(driverName string) { 70 s.Lock() 71 defer s.Unlock() 72 73 delete(s.store, driverName) 74 } 75 76 // Clear deletes all entries in the store. 77 // This methiod is protected by a mutex. 78 func (s *DriversStore) Clear() { 79 s.Lock() 80 defer s.Unlock() 81 82 s.store = store{} 83 }