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