github.com/midokura/kubeedge@v1.2.0-mido.0/tests/stubs/edge/handlerstub/podmanager.go (about) 1 /* 2 Copyright 2019 The KubeEdge 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 handlerstub 18 19 import ( 20 "sync" 21 22 "github.com/kubeedge/kubeedge/tests/stubs/common/types" 23 ) 24 25 // NewPodManager creates pod manger 26 func NewPodManager() (*PodManager, error) { 27 pm := &PodManager{} 28 return pm, nil 29 } 30 31 // PodManager is a manager watch pod change event 32 type PodManager struct { 33 // pods map 34 pods sync.Map 35 } 36 37 // AddPod adds pod in cache 38 func (pm *PodManager) AddPod(k string, v types.FakePod) { 39 pm.pods.Store(k, v) 40 } 41 42 // DeletePod deletes pod in cache 43 func (pm *PodManager) DeletePod(k string) { 44 pm.pods.Delete(k) 45 } 46 47 // ListPods lists all pods in cache 48 func (pm *PodManager) ListPods() []types.FakePod { 49 pods := make([]types.FakePod, 0) 50 pm.pods.Range(func(k, v interface{}) bool { 51 pods = append(pods, v.(types.FakePod)) 52 return true 53 }) 54 return pods 55 }