diff options
| author | zhangjie <iamkadisi@163.com> | 2019-11-14 10:56:09 +0800 |
|---|---|---|
| committer | zhangjie <iamkadisi@163.com> | 2019-11-15 21:24:25 +0800 |
| commit | 4be615d72dde4e5795a13eee114a7545fe8fa7af (patch) | |
| tree | e3dba03c41e4c47cc939cae96fe962a3a625a8fa /edge | |
| parent | edgecontroller: delete beehiveContext field from edgecontroller struct (diff) | |
| download | kubeedge-4be615d72dde4e5795a13eee114a7545fe8fa7af.tar.gz | |
cloudcore: delete beehiveContext field form cloudcore module struct
Signed-off-by: zhangjie <iamkadisi@163.com>
edgecore: delete beehiveContext fiield from edgecore module struct
Signed-off-by: zhangjie <iamkadisi@163.com>
Diffstat (limited to 'edge')
23 files changed, 82 insertions, 133 deletions
diff --git a/edge/pkg/devicetwin/devicetwin.go b/edge/pkg/devicetwin/devicetwin.go index af057569c..a71284b0f 100644 --- a/edge/pkg/devicetwin/devicetwin.go +++ b/edge/pkg/devicetwin/devicetwin.go @@ -6,7 +6,6 @@ import ( "k8s.io/klog" "github.com/kubeedge/beehive/pkg/core" - beehiveContext "github.com/kubeedge/beehive/pkg/core/context" "github.com/kubeedge/kubeedge/edge/pkg/common/modules" "github.com/kubeedge/kubeedge/edge/pkg/devicetwin/dtclient" "github.com/kubeedge/kubeedge/edge/pkg/devicetwin/dtcontext" @@ -15,7 +14,6 @@ import ( //DeviceTwin the module type DeviceTwin struct { - Context *beehiveContext.Context HeartBeatToModule map[string]chan interface{} DTContexts *dtcontext.DTContext DTModules map[string]dtmodule.DTModule @@ -40,13 +38,12 @@ func (dt *DeviceTwin) Group() string { } //Start run the module -func (dt *DeviceTwin) Start(c *beehiveContext.Context) { +func (dt *DeviceTwin) Start() { var ctx context.Context - dtContexts, _ := dtcontext.InitDTContext(c) + dtContexts, _ := dtcontext.InitDTContext() dt.HeartBeatToModule = make(map[string]chan interface{}) dt.DTModules = make(map[string]dtmodule.DTModule) dt.DTContexts = dtContexts - dt.Context = c ctx, dt.cancel = context.WithCancel(context.Background()) err := SyncSqlite(dt.DTContexts) if err != nil { @@ -59,5 +56,4 @@ func (dt *DeviceTwin) Start(c *beehiveContext.Context) { //Cleanup clean resource after quit func (dt *DeviceTwin) Cleanup() { dt.cancel() - dt.Context.Cleanup(dt.Name()) } diff --git a/edge/pkg/devicetwin/dtcontext/dtcontext.go b/edge/pkg/devicetwin/dtcontext/dtcontext.go index 7573c6064..8ad7649da 100644 --- a/edge/pkg/devicetwin/dtcontext/dtcontext.go +++ b/edge/pkg/devicetwin/dtcontext/dtcontext.go @@ -1,6 +1,7 @@ package dtcontext import ( + "context" "errors" "strings" "sync" @@ -9,7 +10,6 @@ import ( "k8s.io/klog" "github.com/kubeedge/beehive/pkg/common/config" - "github.com/kubeedge/beehive/pkg/core/context" "github.com/kubeedge/beehive/pkg/core/model" "github.com/kubeedge/kubeedge/edge/pkg/common/modules" "github.com/kubeedge/kubeedge/edge/pkg/devicetwin/dtcommon" @@ -38,7 +38,7 @@ type DTContext struct { } //InitDTContext init dtcontext -func InitDTContext(context *context.Context) (*DTContext, error) { +func InitDTContext() (*DTContext, error) { groupID := "" nodeID, err := config.CONFIG.GetValue("edgehub.controller.node-id").ToString() if err != nil { @@ -54,17 +54,16 @@ func InitDTContext(context *context.Context) (*DTContext, error) { // var deviceVersionList sync.Map return &DTContext{ - GroupID: groupID, - NodeID: nodeID, - CommChan: commChan, - ConfirmChan: confirmChan, - ConfirmMap: &confirm, - ModulesHealth: &modulesHealth, - ModulesContext: context, - DeviceList: &deviceList, - DeviceMutex: &deviceMutex, - Mutex: &mutex, - State: dtcommon.Disconnected, + GroupID: groupID, + NodeID: nodeID, + CommChan: commChan, + ConfirmChan: confirmChan, + ConfirmMap: &confirm, + ModulesHealth: &modulesHealth, + DeviceList: &deviceList, + DeviceMutex: &deviceMutex, + Mutex: &mutex, + State: dtcommon.Disconnected, }, nil } diff --git a/edge/pkg/devicetwin/dtmanager/communicate.go b/edge/pkg/devicetwin/dtmanager/communicate.go index 4a2ff739c..f4db8ef68 100644 --- a/edge/pkg/devicetwin/dtmanager/communicate.go +++ b/edge/pkg/devicetwin/dtmanager/communicate.go @@ -8,6 +8,7 @@ import ( "k8s.io/klog" + beehiveContext "github.com/kubeedge/beehive/pkg/core/context" "github.com/kubeedge/beehive/pkg/core/model" connect "github.com/kubeedge/kubeedge/edge/pkg/common/cloudconnection" "github.com/kubeedge/kubeedge/edge/pkg/devicetwin/dtcommon" @@ -69,7 +70,7 @@ func initActionCallBack() { } func dealSendToEdge(context *dtcontext.DTContext, resource string, msg interface{}) (interface{}, error) { - context.ModulesContext.Send(dtcommon.EventHubModule, *msg.(*model.Message)) + beehiveContext.Send(dtcommon.EventHubModule, *msg.(*model.Message)) return nil, nil } func dealSendToCloud(context *dtcontext.DTContext, resource string, msg interface{}) (interface{}, error) { @@ -81,7 +82,7 @@ func dealSendToCloud(context *dtcontext.DTContext, resource string, msg interfac if !ok { return nil, errors.New("msg not Message type") } - context.ModulesContext.Send(dtcommon.HubModule, *message) + beehiveContext.Send(dtcommon.HubModule, *message) msgID := message.GetID() context.ConfirmMap.Store(msgID, &dttype.DTMessage{Msg: message, Action: dtcommon.SendToCloud, Type: dtcommon.CommModule}) return nil, nil @@ -139,7 +140,7 @@ func detailRequest(context *dtcontext.DTContext, msg interface{}) (interface{}, klog.Info("Request detail") msgID := message.GetID() context.ConfirmMap.Store(msgID, &dttype.DTMessage{Msg: message, Action: dtcommon.SendToCloud, Type: dtcommon.CommModule}) - context.ModulesContext.Send(dtcommon.HubModule, *message) + beehiveContext.Send(dtcommon.HubModule, *message) return nil, nil } diff --git a/edge/pkg/devicetwin/process.go b/edge/pkg/devicetwin/process.go index efc815dde..eed7b41c6 100644 --- a/edge/pkg/devicetwin/process.go +++ b/edge/pkg/devicetwin/process.go @@ -11,6 +11,7 @@ import ( "k8s.io/klog" + beehiveContext "github.com/kubeedge/beehive/pkg/core/context" "github.com/kubeedge/beehive/pkg/core/model" "github.com/kubeedge/kubeedge/edge/pkg/devicetwin/dtclient" "github.com/kubeedge/kubeedge/edge/pkg/devicetwin/dtcommon" @@ -287,7 +288,7 @@ func (dt *DeviceTwin) runDeviceTwin(ctx context.Context) { default: } - if msg, ok := dt.DTContexts.ModulesContext.Receive("twin"); ok == nil { + if msg, ok := beehiveContext.Receive("twin"); ok == nil { klog.Info("DeviceTwin receive msg") err := dt.distributeMsg(msg) if err != nil { diff --git a/edge/pkg/edged/edged.go b/edge/pkg/edged/edged.go index e7d197afa..d837820f7 100644 --- a/edge/pkg/edged/edged.go +++ b/edge/pkg/edged/edged.go @@ -185,7 +185,6 @@ type podReady struct { type edged struct { //dns config dnsConfigurer *kubedns.Configurer - context *beehiveContext.Context cancel context.CancelFunc hostname string namespace string @@ -285,9 +284,8 @@ func (e *edged) Group() string { return modules.EdgedGroup } -func (e *edged) Start(c *beehiveContext.Context) { - e.context = c - e.metaClient = client.New(c) +func (e *edged) Start() { + e.metaClient = client.New() var ctx context.Context ctx, e.cancel = context.WithCancel(context.Background()) @@ -352,7 +350,6 @@ func (e *edged) Start(c *beehiveContext.Context) { func (e *edged) Cleanup() { e.cancel() - e.context.Cleanup(e.Name()) } // isInitPodReady is used to safely return initPodReady flag @@ -919,7 +916,7 @@ func (e *edged) syncPod(ctx context.Context) { //send msg to metamanager to get existing pods info := model.NewMessage("").BuildRouter(e.Name(), e.Group(), e.namespace+"/"+model.ResourceTypePod, model.QueryOperation) - e.context.Send(metamanager.MetaManagerModuleName, *info) + beehiveContext.Send(metamanager.MetaManagerModuleName, *info) for { select { case <-ctx.Done(): @@ -927,7 +924,7 @@ func (e *edged) syncPod(ctx context.Context) { return default: } - result, err := e.context.Receive(e.Name()) + result, err := beehiveContext.Receive(e.Name()) if err != nil { klog.Errorf("failed to get pod") continue @@ -1003,7 +1000,7 @@ func (e *edged) syncPod(ctx context.Context) { klog.Errorf("handle volume failed: %v", err) } else { resp := result.NewRespByMessage(&result, res) - e.context.SendResp(*resp) + beehiveContext.SendResp(*resp) } default: klog.Errorf("resType is not pod or configmap or secret: esType is %s", resType) diff --git a/edge/pkg/edgehub/edgehub.go b/edge/pkg/edgehub/edgehub.go index e8981fdcc..89fce4be1 100644 --- a/edge/pkg/edgehub/edgehub.go +++ b/edge/pkg/edgehub/edgehub.go @@ -8,7 +8,6 @@ import ( "k8s.io/klog" "github.com/kubeedge/beehive/pkg/core" - beehiveContext "github.com/kubeedge/beehive/pkg/core/context" "github.com/kubeedge/beehive/pkg/core/model" "github.com/kubeedge/kubeedge/edge/pkg/common/modules" "github.com/kubeedge/kubeedge/edge/pkg/edgehub/clients" @@ -22,7 +21,6 @@ const ( //EdgeHub defines edgehub object structure type EdgeHub struct { - context *beehiveContext.Context chClient clients.Adapter config *config.ControllerConfig reconnectChan chan struct{} @@ -51,9 +49,8 @@ func (eh *EdgeHub) Group() string { } //Start sets context and starts the controller -func (eh *EdgeHub) Start(c *beehiveContext.Context) { +func (eh *EdgeHub) Start() { var ctx context.Context - eh.context = c ctx, eh.cancel = context.WithCancel(context.Background()) config.InitEdgehubConfig() @@ -109,5 +106,4 @@ func (eh *EdgeHub) Start(c *beehiveContext.Context) { //Cleanup sets up context cleanup through Edgehub name func (eh *EdgeHub) Cleanup() { eh.cancel() - eh.context.Cleanup(eh.Name()) } diff --git a/edge/pkg/edgehub/process.go b/edge/pkg/edgehub/process.go index 2e869c6e5..e9c9a40f4 100644 --- a/edge/pkg/edgehub/process.go +++ b/edge/pkg/edgehub/process.go @@ -8,6 +8,7 @@ import ( "k8s.io/klog" bhconfig "github.com/kubeedge/beehive/pkg/common/config" + beehiveContext "github.com/kubeedge/beehive/pkg/core/context" "github.com/kubeedge/beehive/pkg/core/model" connect "github.com/kubeedge/kubeedge/edge/pkg/common/cloudconnection" "github.com/kubeedge/kubeedge/edge/pkg/common/message" @@ -98,7 +99,7 @@ func (eh *EdgeHub) dispatch(message model.Message) error { isResponse := eh.isSyncResponse(message.GetParentID()) if !isResponse { - eh.context.SendToGroup(md, message) + beehiveContext.SendToGroup(md, message) return nil } return eh.sendToKeepChannel(message) @@ -143,7 +144,7 @@ func (eh *EdgeHub) sendToCloud(message model.Message) error { select { case response := <-tempChannel: sendTimer.Stop() - eh.context.SendResp(response) + beehiveContext.SendResp(response) eh.deleteKeepChannel(response.GetParentID()) case <-sendTimer.C: klog.Warningf("timeout to receive response for message: %+v", message) @@ -166,7 +167,7 @@ func (eh *EdgeHub) routeToCloud(ctx context.Context) { return default: } - message, err := eh.context.Receive(ModuleNameEdgeHub) + message, err := beehiveContext.Receive(ModuleNameEdgeHub) if err != nil { klog.Errorf("failed to receive message from edge: %v", err) time.Sleep(time.Second) @@ -218,6 +219,6 @@ func (eh *EdgeHub) pubConnectInfo(isConnected bool) { for _, group := range groupMap { message := model.NewMessage("").BuildRouter(message.SourceNodeConnection, group, message.ResourceTypeNodeConnection, message.OperationNodeConnection).FillBody(content) - eh.context.SendToGroup(group, *message) + beehiveContext.SendToGroup(group, *message) } } diff --git a/edge/pkg/edgehub/process_test.go b/edge/pkg/edgehub/process_test.go index f43883765..c6ade049f 100644 --- a/edge/pkg/edgehub/process_test.go +++ b/edge/pkg/edgehub/process_test.go @@ -125,6 +125,8 @@ func TestIsSyncResponse(t *testing.T) { //TestSendToKeepChannel() tests the reception of response in the syncKeep channel func TestSendToKeepChannel(t *testing.T) { + beehiveContext.InitContext(beehiveContext.MsgCtxTypeChannel) + defer beehiveContext.DestroyContext() message := model.NewMessage("test_id") tests := []struct { name string @@ -136,7 +138,6 @@ func TestSendToKeepChannel(t *testing.T) { { name: "SyncKeeper Error Case in send to keep channel", hub: &EdgeHub{ - context: beehiveContext.InitContext(beehiveContext.MsgCtxTypeChannel), syncKeeper: make(map[string]chan model.Message), }, message: message, @@ -146,7 +147,6 @@ func TestSendToKeepChannel(t *testing.T) { { name: "Negative Test Case without syncKeeper Error ", hub: &EdgeHub{ - context: beehiveContext.InitContext(beehiveContext.MsgCtxTypeChannel), syncKeeper: make(map[string]chan model.Message), }, message: model.NewMessage("test_id"), @@ -156,7 +156,6 @@ func TestSendToKeepChannel(t *testing.T) { { name: "Send to keep channel with valid input", hub: &EdgeHub{ - context: beehiveContext.InitContext(beehiveContext.MsgCtxTypeChannel), syncKeeper: make(map[string]chan model.Message), }, message: model.NewMessage("test_id"), @@ -183,6 +182,9 @@ func TestSendToKeepChannel(t *testing.T) { //TestDispatch() tests whether the messages are properly dispatched to their respective modules func TestDispatch(t *testing.T) { + beehiveContext.InitContext(beehiveContext.MsgCtxTypeChannel) + defer beehiveContext.DestroyContext() + tests := []struct { name string hub *EdgeHub @@ -193,7 +195,6 @@ func TestDispatch(t *testing.T) { { name: "dispatch with valid input", hub: &EdgeHub{ - context: beehiveContext.InitContext(beehiveContext.MsgCtxTypeChannel), syncKeeper: make(map[string]chan model.Message), }, message: model.NewMessage("").BuildRouter(ModuleNameEdgeHub, module.TwinGroup, "", ""), @@ -203,7 +204,6 @@ func TestDispatch(t *testing.T) { { name: "Error Case in dispatch", hub: &EdgeHub{ - context: beehiveContext.InitContext(beehiveContext.MsgCtxTypeChannel), syncKeeper: make(map[string]chan model.Message), }, message: model.NewMessage("test").BuildRouter(ModuleNameEdgeHub, module.EdgedGroup, "", ""), @@ -213,7 +213,6 @@ func TestDispatch(t *testing.T) { { name: "Response Case in dispatch", hub: &EdgeHub{ - context: beehiveContext.InitContext(beehiveContext.MsgCtxTypeChannel), syncKeeper: make(map[string]chan model.Message), }, message: model.NewMessage("test").BuildRouter(ModuleNameEdgeHub, module.TwinGroup, "", ""), @@ -246,6 +245,9 @@ func TestRouteToEdge(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() mockAdapter := edgehub.NewMockAdapter(mockCtrl) + beehiveContext.InitContext(beehiveContext.MsgCtxTypeChannel) + defer beehiveContext.DestroyContext() + tests := []struct { name string hub *EdgeHub @@ -254,7 +256,6 @@ func TestRouteToEdge(t *testing.T) { { name: "Route to edge with proper input", hub: &EdgeHub{ - context: beehiveContext.InitContext(beehiveContext.MsgCtxTypeChannel), chClient: mockAdapter, syncKeeper: make(map[string]chan model.Message), reconnectChan: make(chan struct{}), @@ -264,7 +265,6 @@ func TestRouteToEdge(t *testing.T) { { name: "Receive Error in route to edge", hub: &EdgeHub{ - context: beehiveContext.InitContext(beehiveContext.MsgCtxTypeChannel), chClient: mockAdapter, syncKeeper: make(map[string]chan model.Message), reconnectChan: make(chan struct{}), @@ -291,6 +291,8 @@ func TestSendToCloud(t *testing.T) { mockCtrl := gomock.NewController(t) defer mockCtrl.Finish() mockAdapter := edgehub.NewMockAdapter(mockCtrl) + beehiveContext.InitContext(beehiveContext.MsgCtxTypeChannel) + defer beehiveContext.DestroyContext() msg := model.NewMessage("").BuildHeader("test_id", "", 1) msg.Header.Sync = true @@ -305,7 +307,6 @@ func TestSendToCloud(t *testing.T) { { name: "send to cloud with proper input", hub: &EdgeHub{ - context: beehiveContext.InitContext(beehiveContext.MsgCtxTypeChannel), chClient: mockAdapter, config: &config.ControllerConfig{ Protocol: "websocket", @@ -381,7 +382,9 @@ func TestRouteToCloud(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() mockAdapter := edgehub.NewMockAdapter(mockCtrl) - testContext := beehiveContext.InitContext(beehiveContext.MsgCtxTypeChannel) + beehiveContext.InitContext(beehiveContext.MsgCtxTypeChannel) + defer beehiveContext.DestroyContext() + tests := []struct { name string hub *EdgeHub @@ -389,7 +392,6 @@ func TestRouteToCloud(t *testing.T) { { name: "Route to cloud with valid input", hub: &EdgeHub{ - context: testContext, chClient: mockAdapter, reconnectChan: make(chan struct{}), }, @@ -401,9 +403,9 @@ func TestRouteToCloud(t *testing.T) { go tt.hub.routeToCloud(ctx) time.Sleep(2 * time.Second) core.Register(&EdgeHub{}) - testContext.AddModule(ModuleNameEdgeHub) + beehiveContext.AddModule(ModuleNameEdgeHub) msg := model.NewMessage("").BuildHeader("test_id", "", 1) - testContext.Send(ModuleNameEdgeHub, *msg) + beehiveContext.Send(ModuleNameEdgeHub, *msg) stopChan := <-tt.hub.reconnectChan if stopChan != struct{}{} { t.Errorf("Error in route to cloud") diff --git a/edge/pkg/eventbus/eventbus.go b/edge/pkg/eventbus/eventbus.go index 016a8e3b5..fff27119b 100644 --- a/edge/pkg/eventbus/eventbus.go +++ b/edge/pkg/eventbus/eventbus.go @@ -32,7 +32,6 @@ const ( // eventbus struct type eventbus struct { - context *beehiveContext.Context cancel context.CancelFunc mqttMode int } @@ -55,9 +54,8 @@ func (*eventbus) Group() string { return modules.BusGroup } -func (eb *eventbus) Start(c *beehiveContext.Context) { +func (eb *eventbus) Start() { // no need to call TopicInit now, we have fixed topic - eb.context = c var ctx context.Context ctx, eb.cancel = context.WithCancel(context.Background()) @@ -68,7 +66,6 @@ func (eb *eventbus) Start(c *beehiveContext.Context) { } mqttBus.NodeID = nodeID.(string) - mqttBus.ModuleContext = c if eb.mqttMode >= bothMqttMode { // launch an external mqtt server @@ -125,7 +122,6 @@ func (eb *eventbus) Start(c *beehiveContext.Context) { func (eb *eventbus) Cleanup() { eb.cancel() - eb.context.Cleanup(eb.Name()) } func pubMQTT(topic string, payload []byte) { @@ -145,7 +141,7 @@ func (eb *eventbus) pubCloudMsgToEdge(ctx context.Context) { return default: } - accessInfo, err := eb.context.Receive(eb.Name()) + accessInfo, err := beehiveContext.Receive(eb.Name()) if err != nil { klog.Errorf("Fail to get a message from channel: %v", err) continue diff --git a/edge/pkg/eventbus/mqtt/client.go b/edge/pkg/eventbus/mqtt/client.go index 23098f377..ca6e484f9 100644 --- a/edge/pkg/eventbus/mqtt/client.go +++ b/edge/pkg/eventbus/mqtt/client.go @@ -10,7 +10,7 @@ import ( MQTT "github.com/eclipse/paho.mqtt.golang" "k8s.io/klog" - "github.com/kubeedge/beehive/pkg/core/context" + beehiveContext "github.com/kubeedge/beehive/pkg/core/context" "github.com/kubeedge/beehive/pkg/core/model" "github.com/kubeedge/kubeedge/edge/pkg/common/modules" "github.com/kubeedge/kubeedge/edge/pkg/eventbus/common/util" @@ -19,8 +19,6 @@ import ( var ( // MQTTHub client MQTTHub *Client - // ModuleContext variable - ModuleContext *context.Context // NodeID stands for node id NodeID string // GroupID stands for group id @@ -111,7 +109,7 @@ func OnSubMessageReceived(client MQTT.Client, message MQTT.Message) { msg := model.NewMessage("").BuildRouter(modules.BusGroup, "user", resource, "response").FillBody(string(message.Payload())) klog.Info(fmt.Sprintf("received msg from mqttserver, deliver to %s with resource %s", target, resource)) - ModuleContext.SendToGroup(target, *msg) + beehiveContext.SendToGroup(target, *msg) } // InitSubClient init sub client diff --git a/edge/pkg/eventbus/mqtt/server.go b/edge/pkg/eventbus/mqtt/server.go index 3f3274066..301cf94e8 100644 --- a/edge/pkg/eventbus/mqtt/server.go +++ b/edge/pkg/eventbus/mqtt/server.go @@ -27,6 +27,7 @@ import ( "github.com/256dpi/gomqtt/transport" "k8s.io/klog" + beehiveContext "github.com/kubeedge/beehive/pkg/core/context" "github.com/kubeedge/beehive/pkg/core/model" "github.com/kubeedge/kubeedge/edge/pkg/common/modules" ) @@ -116,7 +117,7 @@ func (m *Server) onSubscribe(msg *packet.Message) { message := model.NewMessage("").BuildRouter(modules.BusGroup, "user", resource, "response").FillBody(string(msg.Payload)) klog.Info(fmt.Sprintf("Received msg from mqttserver, deliver to %s with resource %s", target, resource)) - ModuleContext.SendToGroup(target, *message) + beehiveContext.SendToGroup(target, *message) } // InitInternalTopics sets internal topics to server by default. diff --git a/edge/pkg/metamanager/client/configmap.go b/edge/pkg/metamanager/client/configmap.go index 5790463bf..84ab87217 100644 --- a/edge/pkg/metamanager/client/configmap.go +++ b/edge/pkg/metamanager/client/configmap.go @@ -6,7 +6,6 @@ import ( api "k8s.io/api/core/v1" - "github.com/kubeedge/beehive/pkg/core/context" "github.com/kubeedge/beehive/pkg/core/model" "github.com/kubeedge/kubeedge/edge/pkg/common/message" "github.com/kubeedge/kubeedge/edge/pkg/common/modules" @@ -29,13 +28,11 @@ type ConfigMapsInterface interface { type configMaps struct { namespace string - context *context.Context send SendInterface } -func newConfigMaps(namespace string, c *context.Context, s SendInterface) *configMaps { +func newConfigMaps(namespace string, s SendInterface) *configMaps { return &configMaps{ - context: c, send: s, namespace: namespace, } diff --git a/edge/pkg/metamanager/client/endpoint.go b/edge/pkg/metamanager/client/endpoint.go index 99a2f52c6..7a614f356 100644 --- a/edge/pkg/metamanager/client/endpoint.go +++ b/edge/pkg/metamanager/client/endpoint.go @@ -6,7 +6,6 @@ import ( api "k8s.io/api/core/v1" - "github.com/kubeedge/beehive/pkg/core/context" "github.com/kubeedge/beehive/pkg/core/model" "github.com/kubeedge/kubeedge/common/constants" "github.com/kubeedge/kubeedge/edge/pkg/common/message" @@ -31,13 +30,11 @@ type EndpointsInterface interface { // Endpoints is struct implementing EndpointsInterface type Endpoints struct { namespace string - context *context.Context send SendInterface } -func newEndpoints(namespace string, c *context.Context, s SendInterface) *Endpoints { +func newEndpoints(namespace string, s SendInterface) *Endpoints { return &Endpoints{ - context: c, send: s, namespace: namespace, } diff --git a/edge/pkg/metamanager/client/metaclient.go b/edge/pkg/metamanager/client/metaclient.go index 03644a075..c5d81950b 100644 --- a/edge/pkg/metamanager/client/metaclient.go +++ b/edge/pkg/metamanager/client/metaclient.go @@ -6,7 +6,7 @@ import ( "k8s.io/apimachinery/pkg/util/wait" "k8s.io/klog" - "github.com/kubeedge/beehive/pkg/core/context" + beehiveContext "github.com/kubeedge/beehive/pkg/core/context" "github.com/kubeedge/beehive/pkg/core/model" "github.com/kubeedge/kubeedge/edge/pkg/metamanager" ) @@ -32,64 +32,62 @@ type CoreInterface interface { } type metaClient struct { - context *context.Context - send SendInterface + send SendInterface } func (m *metaClient) Pods(namespace string) PodsInterface { - return newPods(namespace, m.context, m.send) + return newPods(namespace, m.send) } func (m *metaClient) ConfigMaps(namespace string) ConfigMapsInterface { - return newConfigMaps(namespace, m.context, m.send) + return newConfigMaps(namespace, m.send) } func (m *metaClient) Nodes(namespace string) NodesInterface { - return newNodes(namespace, m.context, m.send) + return newNodes(namespace, m.send) } func (m *metaClient) NodeStatus(namespace string) NodeStatusInterface { - return newNodeStatus(namespace, m.context, m.send) + return newNodeStatus(namespace, m.send) } func (m *metaClient) Secrets(namespace string) SecretsInterface { - return newSecrets(namespace, m.context, m.send) + return newSecrets(namespace, m.send) } func (m *metaClient) PodStatus(namespace string) PodStatusInterface { - return newPodStatus(namespace, m.context, m.send) + return newPodStatus(namespace, m.send) } //New creates a new metaclient func (m *metaClient) Endpoints(namespace string) EndpointsInterface { - return newEndpoints(namespace, m.context, m.send) + return newEndpoints(namespace, m.send) } // New Services metaClient func (m *metaClient) Services(namespace string) ServiceInterface { - return newServices(namespace, m.context, m.send) + return newServices(namespace, m.send) } // New PersistentVolumes metaClient func (m *metaClient) PersistentVolumes(namespace string) PersistentVolumesInterface { - return newPersistentVolumes(namespace, m.context, m.send) + return newPersistentVolumes(namespace, m.send) } // New PersistentVolumeClaims metaClient func (m *metaClient) PersistentVolumeClaims(namespace string) PersistentVolumeClaimsInterface { - return newPersistentVolumeClaims(namespace, m.context, m.send) + return newPersistentVolumeClaims(namespace, m.send) } // New VolumeAttachments metaClient func (m *metaClient) VolumeAttachments(namespace string) VolumeAttachmentsInterface { - return newVolumeAttachments(namespace, m.context, m.send) + return newVolumeAttachments(namespace, m.send) } // New creates new metaclient -func New(c *context.Context) CoreInterface { +func New() CoreInterface { return &metaClient{ - context: c, - send: newSend(c), + send: newSend(), } } @@ -99,11 +97,10 @@ type SendInterface interface { } type send struct { - context *context.Context } -func newSend(c *context.Context) SendInterface { - return &send{c} +func newSend() SendInterface { + return &send{} } func (s *send) SendSync(message *model.Message) (*model.Message, error) { @@ -111,7 +108,7 @@ func (s *send) SendSync(message *model.Message) (*model.Message, error) { var resp model.Message retries := 0 err = wait.Poll(syncPeriod, syncMsgRespTimeout, func() (bool, error) { - resp, err = s.context.SendSync(metamanager.MetaManagerModuleName, *message, syncMsgRespTimeout) + resp, err = beehiveContext.SendSync(metamanager.MetaManagerModuleName, *message, syncMsgRespTimeout) retries++ if err == nil { klog.Infof("send sync message %s successed and response: %v", message.GetResource(), resp) diff --git a/edge/pkg/metamanager/client/node.go b/edge/pkg/metamanager/client/node.go index b83e25542..7f2db2576 100644 --- a/edge/pkg/metamanager/client/node.go +++ b/edge/pkg/metamanager/client/node.go @@ -6,7 +6,6 @@ import ( api "k8s.io/api/core/v1" - "github.com/kubeedge/beehive/pkg/core/context" "github.com/kubeedge/beehive/pkg/core/model" "github.com/kubeedge/kubeedge/edge/pkg/common/message" "github.com/kubeedge/kubeedge/edge/pkg/common/modules" @@ -28,13 +27,11 @@ type NodesInterface interface { type nodes struct { namespace string - context *context.Context send SendInterface } -func newNodes(namespace string, c *context.Context, s SendInterface) *nodes { +func newNodes(namespace string, s SendInterface) *nodes { return &nodes{ - context: c, send: s, namespace: namespace, } diff --git a/edge/pkg/metamanager/client/nodestatus.go b/edge/pkg/metamanager/client/nodestatus.go index 0ebb11524..f5ebf4b8f 100644 --- a/edge/pkg/metamanager/client/nodestatus.go +++ b/edge/pkg/metamanager/client/nodestatus.go @@ -3,7 +3,6 @@ package client import ( "fmt" - "github.com/kubeedge/beehive/pkg/core/context" "github.com/kubeedge/beehive/pkg/core/model" edgeapi "github.com/kubeedge/kubeedge/common/types" @@ -26,13 +25,11 @@ type NodeStatusInterface interface { type nodeStatus struct { namespace string - context *context.Context send SendInterface } -func newNodeStatus(namespace string, c *context.Context, s SendInterface) *nodeStatus { +func newNodeStatus(namespace string, s SendInterface) *nodeStatus { return &nodeStatus{ - context: c, send: s, namespace: namespace, } diff --git a/edge/pkg/metamanager/client/persistentvolume.go b/edge/pkg/metamanager/client/persistentvolume.go index f28f83340..1595b5f13 100644 --- a/edge/pkg/metamanager/client/persistentvolume.go +++ b/edge/pkg/metamanager/client/persistentvolume.go @@ -7,7 +7,6 @@ import ( api "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/kubeedge/beehive/pkg/core/context" "github.com/kubeedge/beehive/pkg/core/model" "github.com/kubeedge/kubeedge/edge/pkg/common/message" "github.com/kubeedge/kubeedge/edge/pkg/common/modules" @@ -29,14 +28,12 @@ type PersistentVolumesInterface interface { type persistentvolumes struct { namespace string - context *context.Context send SendInterface } -func newPersistentVolumes(n string, c *context.Context, s SendInterface) *persistentvolumes { +func newPersistentVolumes(n string, s SendInterface) *persistentvolumes { return &persistentvolumes{ namespace: n, - context: c, send: s, } } diff --git a/edge/pkg/metamanager/client/persistentvolumeclaim.go b/edge/pkg/metamanager/client/persistentvolumeclaim.go index edec442bb..94f3edc14 100644 --- a/edge/pkg/metamanager/client/persistentvolumeclaim.go +++ b/edge/pkg/metamanager/client/persistentvolumeclaim.go @@ -7,7 +7,6 @@ import ( api "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/kubeedge/beehive/pkg/core/context" "github.com/kubeedge/beehive/pkg/core/model" "github.com/kubeedge/kubeedge/edge/pkg/common/message" "github.com/kubeedge/kubeedge/edge/pkg/common/modules" @@ -29,14 +28,12 @@ type PersistentVolumeClaimsInterface interface { type persistentvolumeclaims struct { namespace string - context *context.Context send SendInterface } -func newPersistentVolumeClaims(n string, c *context.Context, s SendInterface) *persistentvolumeclaims { +func newPersistentVolumeClaims(n string, s SendInterface) *persistentvolumeclaims { return &persistentvolumeclaims{ namespace: n, - context: c, send: s, } } diff --git a/edge/pkg/metamanager/client/pod.go b/edge/pkg/metamanager/client/pod.go index 4d06f4d83..c8c6b124e 100644 --- a/edge/pkg/metamanager/client/pod.go +++ b/edge/pkg/metamanager/client/pod.go @@ -1,10 +1,6 @@ package client -import ( - api "k8s.io/api/core/v1" - - "github.com/kubeedge/beehive/pkg/core/context" -) +import api "k8s.io/api/core/v1" //PodsGetter is interface to get pods type PodsGetter interface { @@ -21,13 +17,11 @@ type PodsInterface interface { type pods struct { namespace string - context *context.Context send SendInterface } -func newPods(namespace string, c *context.Context, s SendInterface) *pods { +func newPods(namespace string, s SendInterface) *pods { return &pods{ - context: c, send: s, namespace: namespace, } diff --git a/edge/pkg/metamanager/client/podstatus.go b/edge/pkg/metamanager/client/podstatus.go index a885ab46b..dc50f8137 100644 --- a/edge/pkg/metamanager/client/podstatus.go +++ b/edge/pkg/metamanager/client/podstatus.go @@ -3,7 +3,6 @@ package client import ( "fmt" - "github.com/kubeedge/beehive/pkg/core/context" "github.com/kubeedge/beehive/pkg/core/model" edgeapi "github.com/kubeedge/kubeedge/common/types" @@ -26,13 +25,11 @@ type PodStatusInterface interface { type podStatus struct { namespace string - context *context.Context send SendInterface } -func newPodStatus(namespace string, c *context.Context, s SendInterface) *podStatus { +func newPodStatus(namespace string, s SendInterface) *podStatus { return &podStatus{ - context: c, send: s, namespace: namespace, } diff --git a/edge/pkg/metamanager/client/secret.go b/edge/pkg/metamanager/client/secret.go index b634541dc..336618bf7 100644 --- a/edge/pkg/metamanager/client/secret.go +++ b/edge/pkg/metamanager/client/secret.go @@ -6,7 +6,6 @@ import ( api "k8s.io/api/core/v1" - "github.com/kubeedge/beehive/pkg/core/context" "github.com/kubeedge/beehive/pkg/core/model" "github.com/kubeedge/kubeedge/edge/pkg/common/message" "github.com/kubeedge/kubeedge/edge/pkg/common/modules" @@ -28,13 +27,11 @@ type SecretsInterface interface { type secrets struct { namespace string - context *context.Context send SendInterface } -func newSecrets(namespace string, c *context.Context, s SendInterface) *secrets { +func newSecrets(namespace string, s SendInterface) *secrets { return &secrets{ - context: c, send: s, namespace: namespace, } diff --git a/edge/pkg/metamanager/client/service.go b/edge/pkg/metamanager/client/service.go index b9d8b341d..f60b440e9 100644 --- a/edge/pkg/metamanager/client/service.go +++ b/edge/pkg/metamanager/client/service.go @@ -6,7 +6,6 @@ import ( v1 "k8s.io/api/core/v1" - "github.com/kubeedge/beehive/pkg/core/context" "github.com/kubeedge/beehive/pkg/core/model" "github.com/kubeedge/kubeedge/common/constants" "github.com/kubeedge/kubeedge/edge/pkg/common/message" @@ -30,14 +29,12 @@ type ServiceInterface interface { type services struct { namespace string - context *context.Context send SendInterface } -func newServices(namespace string, c *context.Context, s SendInterface) *services { +func newServices(namespace string, s SendInterface) *services { return &services{ namespace: namespace, - context: c, send: s, } } diff --git a/edge/pkg/metamanager/client/volumeattachment.go b/edge/pkg/metamanager/client/volumeattachment.go index 0b18b2ac3..56a10c942 100644 --- a/edge/pkg/metamanager/client/volumeattachment.go +++ b/edge/pkg/metamanager/client/volumeattachment.go @@ -7,7 +7,6 @@ import ( api "k8s.io/api/storage/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/kubeedge/beehive/pkg/core/context" "github.com/kubeedge/beehive/pkg/core/model" "github.com/kubeedge/kubeedge/edge/pkg/common/message" "github.com/kubeedge/kubeedge/edge/pkg/common/modules" @@ -29,14 +28,12 @@ type VolumeAttachmentsInterface interface { type volumeattachments struct { namespace string - context *context.Context send SendInterface } -func newVolumeAttachments(n string, c *context.Context, s SendInterface) *volumeattachments { +func newVolumeAttachments(n string, s SendInterface) *volumeattachments { return &volumeattachments{ namespace: n, - context: c, send: s, } } |
