sidecar启动

1,定时任务

边车启动以后会开启定时10s的任务,该任务周期性获取k8s中所有的Deployment和StatefulSet资源,并将资源中就绪信息更新到redis中。如下流程图:

点击展开puml
@startuml
start
:检查是否为master;
if (configUtils.APP_NAME != configUtils.APP_MASTER_NAME) then (不是)
  stop
else (是)
  :创建Kubernetes客户端;
    :获取Deployment列表;
    :获取StatefulSet列表;
    :合并Deployment和StatefulSet列表到allList;
    :从Dapr获取状态;
    if (appHashMap == null) then (是)
      stop
    else (不是)
      :同步app安装数据,初始化删除集合set;
      repeat
        :遍历appHashMap的每个键;
        if (状态 == "installing") then (是)
          :检查创建时间是否超过10秒;
          if (未超过10秒) then (是)
          endif
        endif
        repeat
          :遍历allList的每个对象;
          if (名称匹配) then (是)
            :获取replicas和readyReplicas;
            :更新appHashMap;
            :isdel = false;
            break
          endif
        repeat while (allList有更多对象)
        if (isdel) then (是)
          :将键添加到删除集合set中;
        endif
      repeat while (appHashMap有更多键)
      :从appHashMap中删除set中的键;
      if (storedEtag != null) then (是)
          :保存状态到Dapr(使用storedEtag);
          :记录错误日志;
      else (不是)
        :保存状态到Dapr;
      endif
    endif
endif
stop
@enduml

2,启动后执行

sidecar启动后会立刻周期性检测与其绑定的引擎容器是否启动成功,如果启动成功则调用安装app的接口。

sidecar会携带存储在redis的安装参数请求引擎,比如对于独立安装的sie-iidp-monitor的安装相关参数信息:


{
    "app": "excel",
    "replicas": 1,
    "kind": "unStateful",
    "readyReplicas": 1,
    "svcName": "sie-iidp-monitor",
    "dependencies": [

    ],
    "extend": [

    ],
    "caller": "install",
    "createTime": 1733469256223,
    "ids": [
        "04cinh2hf6d3s",
        "04cpb3w4s8afm",
        "04ernw6s9r0sm"
    ],
    "tag": "master",
    "apps": [
        {
            "name": "sie-iidp-monitor",
            "id": "04cinh2hf6d3s"
        },
        {
            "name": "oppmApp",
            "id": "04cpb3w4s8afm"
        },
        {
            "name": "excel",
            "id": "04ernw6s9r0sm"
        }
    ]
}

下面是检测流程图:

上图中 deployService.installInvoke 调用流程图如下:

app安装

sidecar对外提供了http接口来安装卸载app,下图是响应安装和卸载的流程图:

继续查看上图中 deployService.install(args) 的流程图:

如果service名称已经存在,则更新redis缓存,并重新pod,如果不存在则从app.yaml 和 svc.yaml 模板文件中填充对应的字段,生产yaml文件并apply到k8s中。

下图是 deployService.uninstall(args) 的流程图:

从redis缓存中获取app列表,如果卸载的app在列表中,且删除以后还有app,则重启pod,如果app列表为空,则删除整个pod。