当前位置: 首页 > news >正文

Koordinator-NodeSLO

Reconcile()

  • 获取node和nodeSLO,设置nodeExist和nodeSLOExist
  • node和nodeSLO都不存在,直接返回
  • 若!nodeExist
    • 删除对应nodeSLO
  • 若!nodeSLOExist
    • 初始化nodeSLO
    • 创建nodeSLO
  • 若nodeExist和nodeSLOExist都存在
    • 获取nodeSLOSpec,若nodeSLOSpec改变了,则更新nodeSLO。
func (r *NodeSLOReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
    // reconcile for 2 things:
    //   1. ensuring the NodeSLO exists iff the Node exists
    //   2. update NodeSLO Spec
    _ = log.FromContext(ctx, "node-slo-reconciler", req.NamespacedName)
    // if cache unavailable, requeue the req
    if !r.sloCfgCache.IsCfgAvailable() {
        // all nodes would be enqueued once the config is available, so here we just drop the req
        klog.Warningf("slo config is not available, drop the req %v until a valid config is set",
            req.NamespacedName)
        return ctrl.Result{}, nil
    }
    // get the node
    nodeExist := true
    nodeName := req.Name
    node := &corev1.Node{}
    err := r.Client.Get(context.TODO(), req.NamespacedName, node)
    if err != nil {
        if !errors.IsNotFound(err) {
            metrics.RecordNodeSLOReconcileCount(false, "reconcileNodeGetError")
            klog.Errorf("failed to find node %v, error: %v", nodeName, err)
            return ctrl.Result{Requeue: true}, err
        }
        nodeExist = false
    }
    // get the nodeSLO
    nodeSLOExist := true
    nodeSLOName := req.Name
    nodeSLO := &slov1alpha1.NodeSLO{}
    err = r.Client.Get(context.TODO(), req.NamespacedName, nodeSLO)
    if err != nil {
        if !errors.IsNotFound(err) {
            metrics.RecordNodeSLOReconcileCount(false, "reconcileNodeSLOGetError")
            klog.Errorf("failed to find nodeSLO %v, error: %v", nodeName, err)
            return ctrl.Result{Requeue: true}, err
        }
        nodeSLOExist = false
    }
    // NodeSLO lifecycle management
    if !nodeExist && !nodeSLOExist {
        // do nothing if both does not exist
        return ctrl.Result{}, nil
    } else if !nodeExist {
        // delete CR if only the nodeSLO exists
        err = r.Client.Delete(context.TODO(), nodeSLO)
        if err != nil {
            if errors.IsNotFound(err) {
                klog.V(4).Infof("failed to delete nodeSLO %v because error: %v", nodeSLOName, err)
                return ctrl.Result{}, nil
            }
            metrics.RecordNodeSLOReconcileCount(false, "deleteNodeSLO")
            klog.Errorf("failed to delete nodeSLO %v, error: %v", nodeSLOName, err)
            return reconcile.Result{Requeue: true}, err
        }
        metrics.RecordNodeSLOReconcileCount(true, "deleteNodeSLO")
        return ctrl.Result{}, nil
    } else if !nodeSLOExist {
        // create and initialize CR if only the node exists
        if err = r.initNodeSLO(node, nodeSLO); err != nil {
            klog.Errorf("failed to init nodeSLO instance %v: %v", nodeSLOName, err)
            return ctrl.Result{Requeue: true}, err
        }
        err = r.Client.Create(context.TODO(), nodeSLO)
        if err != nil {
            metrics.RecordNodeSLOReconcileCount(false, "createNodeSLO")
            klog.Errorf("failed to create nodeSLO instance %v: %v", nodeSLOName, err)
            return ctrl.Result{Requeue: true}, err
        }
        metrics.RecordNodeSLOReconcileCount(true, "createNodeSLO")
    } else {
        // update nodeSLO spec if both exists
        nodeSLOSpec, err := r.getNodeSLOSpec(node, &nodeSLO.Spec)
        if err != nil {
            klog.Errorf("failed to get nodeSLO %v, spec: %v", nodeSLOName, err)
            return ctrl.Result{Requeue: true}, err
        }
        if !reflect.DeepEqual(nodeSLOSpec, &nodeSLO.Spec) {
            nodeSLO.Spec = *nodeSLOSpec
            err = r.Client.Update(context.TODO(), nodeSLO)
            if err != nil {
                metrics.RecordNodeSLOReconcileCount(false, "updateNodeSLO")
                klog.Errorf("failed to update nodeSLO %v, error: %v", nodeSLOName, err)
                return ctrl.Result{Requeue: true}, err
            }
            metrics.RecordNodeSLOReconcileCount(true, "updateNodeSLO")
        }
    }
    klog.V(6).Infof("nodeslo-controller succeeded to update nodeSLO %v", nodeSLOName)
    return ctrl.Result{}, nil
}

相关文章:

  • 使用Python解决Logistic方程
  • vue项目使用html2canvas和jspdf将页面导出成PDF文件
  • springboot新增调度任务
  • 当当平台商品详情接口设计与调用指南
  • PostgreSQL 的 COPY 命令
  • 算法思想之位运算(一)
  • Model Context Protocol (MCP) 模型上下文协议
  • U盘引导盘制作Rufus v4.7.2231
  • 第十六届蓝桥杯 省赛C/C++ 大学B组
  • 大模型开发:源码分析 Qwen 2.5-VL 视频抽帧模块(附加FFmpeg 性能对比测试)
  • 软考day03
  • THM Billing
  • Win10 开机自动开启手动代理 “手动设置代理”,如何关闭 “使用代理服务器” 如何开机时保持关闭VPN
  • C++初阶-inline的使用
  • Linux xorg-server 解析(一)- 编译安装Debug版本的xorg-server
  • Java基础知识
  • SQL 语句基础(增删改查)
  • 电流互感器的两相星形接线的建模与仿真
  • 撰写学位论文Word图表目录的自动生成
  • 基于单片机的病房呼叫系统设计
  • 个人可以采集视频做网站吗/电商营销的策略与方法
  • 手机端网站怎么做seo/seo搜索引擎优化营销案例
  • 河北汉佳 做网站的公司/seo课程
  • 网站专题建设/一点优化
  • dw 怎么做钓鱼网站/专业郑州企业网站建设
  • 网站备案域名需要解析到备案服务器吗/搜索引擎网站大全