github.com/midokura/kubeedge@v1.2.0-mido.0/tests/stubs/cloud/controllerstub/downstream.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 controllerstub 18 19 import ( 20 "k8s.io/klog" 21 22 beehiveContext "github.com/kubeedge/beehive/pkg/core/context" 23 "github.com/kubeedge/kubeedge/tests/stubs/common/constants" 24 ) 25 26 // NewDownstreamController creates a downstream controller 27 func NewDownstreamController(pm *PodManager) (*DownstreamController, error) { 28 // New downstream controller 29 dc := &DownstreamController{podManager: pm} 30 return dc, nil 31 } 32 33 // DownstreamController receives http request and send to cloudhub 34 type DownstreamController struct { 35 podManager *PodManager 36 } 37 38 // Start DownstreamController 39 func (dc *DownstreamController) Start() error { 40 klog.Infof("Start downstream controller") 41 go dc.SyncPods() 42 return nil 43 } 44 45 // SyncPods is used to send message to cloudhub 46 func (dc *DownstreamController) SyncPods() { 47 for { 48 select { 49 case <-beehiveContext.Done(): 50 klog.Info("Stop sync pod") 51 return 52 case msg := <-dc.podManager.GetEvent(): 53 klog.Infof("Send message to cloudhub: %v", *msg) 54 beehiveContext.Send(constants.CloudHub, *msg) 55 klog.Info("Finish send message to cloudhub") 56 } 57 } 58 }