github.com/midokura/kubeedge@v1.2.0-mido.0/tests/stubs/cloud/controllerstub/module.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 "net/http" 21 22 "k8s.io/klog" 23 24 "github.com/kubeedge/beehive/pkg/core" 25 "github.com/kubeedge/kubeedge/tests/stubs/common/constants" 26 ) 27 28 // Init module 29 func init() { 30 core.Register(&ControllerStub{}) 31 } 32 33 // HandlerStub definition 34 type ControllerStub struct { 35 } 36 37 // Return module name 38 func (*ControllerStub) Name() string { 39 return constants.ControllerStub 40 } 41 42 // Return module group 43 func (*ControllerStub) Group() string { 44 return constants.ControllerGroup 45 } 46 47 // Start controller hub 48 func (cs *ControllerStub) Start() { 49 // New pod manager 50 pm, err := NewPodManager() 51 if err != nil { 52 klog.Errorf("Failed to create pod manager with error: %v", err) 53 return 54 } 55 56 // Start downstream controller 57 downstream, err := NewDownstreamController(pm) 58 if err != nil { 59 klog.Errorf("New downstream controller failed with error: %v", err) 60 return 61 } 62 downstream.Start() 63 64 // Start upstream controller 65 upstream, err := NewUpstreamController(pm) 66 if err != nil { 67 klog.Errorf("New upstream controller failed with error: %v", err) 68 return 69 } 70 upstream.Start() 71 72 // Start http server 73 http.HandleFunc(constants.PodResource, pm.PodHandlerFunc) 74 klog.Info("Start http service") 75 go http.ListenAndServe(":54321", nil) 76 }