「连载」边缘计算(三十三)03-15:边缘部分源码(源码分析篇)

(接上篇)

初始化porxy,具体如下所示。

KubeEdge/edgemesh/pkg/proxy/proxy.go

// Init: init the proxy. create virtual device and assign ips, etc..

func Init() {

go func() {

unused = make([]string, 0)

addrByService = &addrTable{}

c := context.GetContext(context.MsgCtxTypeChannel)

metaClient = client.New(c)

//create virtual network device

for {

err := vdev.CreateDevice()

if err == nil {

break

}

klog.Warningf("[L4 Proxy] create Device is failed : %s", err)

//there may have some exception need to be fixed on OS

time.Sleep(2 * time.Second)

}

//configure vir ip

ipPoolSize = 0

expandIpPool()

//open epoll

ep, err := poll.CreatePoll(pollCallback)

if err != nil {

vdev.DestroyDevice()

klog.Errorf("[L4 Proxy] epoll is open failed : %s", err)

return

}

epoll = ep

go epoll.Loop()

klog.Infof("[L4 Proxy] proxy is running now")

}()

}

Init()函数主要做3件事情。

1)创建获得pod原数据的client;

2)创建和维护虚拟网络设备;

3)通过epoll管理代理进程。

CreateDevice()函数先判断虚拟网络设备edge0是否存在,如果存在就将其删除并重建;如果不存在就直接创建虚拟网络设备edge0。

启动服务

server.Start()定义具体内容如下所示。

KubeEdge/edgemesh/pkg/server/server.go

func Start() {

//Initialize the resolvers

r := &resolver.MyResolver{"http"}

resolver.RegisterResolver(r)

//Initialize the handlers

config.GlobalDefinition = &model.GlobalCfg{}

config.GlobalDefinition.Panel.Infra = "fake"

opts := control.Options{

Infra:   config.GlobalDefinition.Panel.Infra,

Address: config.GlobalDefinition.Panel.Settings["address"],

}

config.GlobalDefinition.Ssl = make(map[string]string)

control.Init(opts)

opt := registry.Options{}

registry.DefaultServiceDiscoveryService = edgeregistry.NewServiceDiscovery(opt)

myStrategy := mconfig.CONFIG.GetConfigurationByKey("mesh.loadbalance.strategy-name").(string)

loadbalancer.InstallStrategy(myStrategy, func() loadbalancer.Strategy {

switch myStrategy {

case "RoundRobin":

return &loadbalancer.RoundRobinStrategy{}

case "Random":

return &loadbalancer.RandomStrategy{}

default:

return &loadbalancer.RoundRobinStrategy{}

}

})

//Start dns server

go DnsStart()

//Start server

StartTCP()

}

Start()函数做了3件事情:

1)初始化resolvers、handlers。初始化的resolvers、handlers在TCP服务处理连接的过程中被使用。

2)启动 DNS服务。该DNS服务主要为节点内的应用做域名解析。

3)启动TCP服务。该TCP服务在节点间做流量代理。

通过一个for循环接收通信管道中关于edgemesh的信息并处理,具体如下所示。

KubeEdge/edgemesh/pkg/module.go

//Start sets context and starts the controller

func (em *EdgeMesh) Start(c *context.Context) {

...

// we need watch message to update the cache of instances

for {

if msg, ok := em.context.Receive(constant.ModuleNameEdgeMesh); ok == nil {

proxy.MsgProcess(msg)

klog.Infof("get message: %v", msg)

continue

}

}

}

未完待续……     

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-16 16:28:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-16 16:28:01       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-16 16:28:01       82 阅读
  4. Python语言-面向对象

    2024-03-16 16:28:01       91 阅读

热门阅读

  1. MySQL的索引下推

    2024-03-16 16:28:01       36 阅读
  2. Python最常用的库

    2024-03-16 16:28:01       47 阅读
  3. 如何用Python搭建聊天室

    2024-03-16 16:28:01       36 阅读
  4. ReactNative

    2024-03-16 16:28:01       39 阅读
  5. qt QtMultimedia 报错

    2024-03-16 16:28:01       44 阅读
  6. P8752 [蓝桥杯 2021 省 B2] 特殊年份 Python

    2024-03-16 16:28:01       39 阅读
  7. 乐观锁与悲观锁

    2024-03-16 16:28:01       43 阅读
  8. Flink 简述

    2024-03-16 16:28:01       40 阅读
  9. python adb脚本

    2024-03-16 16:28:01       42 阅读
  10. 交叉编译代码

    2024-03-16 16:28:01       45 阅读
  11. ChatGPT升级版:如何借助ChatGPT高效撰写学术论文

    2024-03-16 16:28:01       49 阅读