Loading
close

云产品安装完成状态检查

time 更新时间:2024-04-01 17:41:12

说明

云产品 chart 包中 template/job-hooks.yaml 文件用于定义云产品安装时的必要检查,云产品 chart 包开始部署后,会开始检查此 job 运行状态,当此 job 运行完成后,云产品会标记成已安装的状态。

注意:若不定义安装资源检查会导致云产品安装失败。且此任务最多运行时间为30分钟,超过会导致云产品安装超时而失败。

示例

使用通用模板

ECP 为云产品准备了一套通用的模板来定义此 job,使用此模板时,需要在云产品 chart 的 requirments.yaml 中定义依赖 helm-toolkit,之后直接在 values.yaml 中填写固定格式的依赖检查即可,如下所示。

requirements.yaml:

dependencies:
  - name: helm-toolkit
    repository: http://charts.easystack.io:8090
    version: 5.0.1

job-hooks.yaml:

{{- $envAll := . }}
{{- include "helm-toolkit.snippets.job_hook" $envAll }}

values.yaml:

images:
  tags:
    hook: hub.easystack.io/production/escloud-linux-source-busybox:latest
    dep_check: hub.easystack.io/production/kubernetes-entrypoint:v0.2.1
  pullPolicy: "IfNotPresent"
  job_pull_policy: "Always"

dependencies:
  posthook:
    services:
    - service: dashboard_api
      endpoint: internal
    - service: dashboard_web
      endpoint: internal

endpoints:
  cluster_domain_suffix: cluster.local
  dashboard_api:
    hosts:
      default: dashboard-api
      public: dashboard-api
  dashboard_web:
    hosts:
      default: dashboard-web
      public: dashboard-web

部署后,job-hooks.yaml 会被渲染为类似如下的 job:

apiVersion: batch/v1
kind: Job
metadata:
  name: mycloud-product-ecpbackendcheck-1634803477
spec:
  backoffLimit: 128
  completions: 1
  parallelism: 1
  template:
    metadata:
      creationTimestamp: null
      labels:
        component: ecpbackendcheck
    spec:
      containers:
      - command:
        - echo
        - done
        image: hub.easystack.io/production/escloud-linux-source-busybox:latest
        imagePullPolicy: IfNotPresent
        name: iam-ecpbackendcheck
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      initContainers:
      - command:
        - kubernetes-entrypoint
        env:
        - name: POD_NAME
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: metadata.name
        - name: NAMESPACE
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: metadata.namespace
        - name: INTERFACE_NAME
          value: eth0
        - name: DEPENDENCY_SERVICE
          value: mycloud-product:dashboard-api,mycloud-product:dashboard-web
        - name: DEPENDENCY_JOBS
        - name: DEPENDENCY_DAEMONSET
        - name: DEPENDENCY_CONTAINER
        - name: COMMAND
          value: echo done
        image: hub.easystack.io/production/kubernetes-entrypoint:v0.2.1
        imagePullPolicy: IfNotPresent
        name: init
      nodeSelector:
        cloud-product: enabled
      restartPolicy: OnFailure

自定义检查Job

检查Job也可以自行定义,添加更多需要检查的内容,无需添加 helm-toolkit 的依赖,如下所示,使用集群中 kubernetes-entrypoint 镜像完成了对 mycloud-product namespace 下 dashboard-api 和 dashboard-web service 的就绪检查:

{{- $envAll := . -}}
{{- $releaseName := $envAll.Release.Name }}
{{- $releaseTime := $envAll.Release.Time.Seconds }}
{{- $check := "ecpbackendcheck" }}
---
apiVersion: batch/v1
kind: Job
metadata:
  name: {{ $releaseName }}-{{ $check }}-{{ $releaseTime }}
  annotations:
    ecp: "true"
spec:
  template:
    metadata:
      labels:
        release_group: {{ $envAll.Values.release_group | default $envAll.Release.Name }}
        application: {{ $releaseName }}
        component: {{ $check }}
    spec:
      restartPolicy: OnFailure
      nodeSelector:
        {{ $envAll.Values.labels.node_selector_key }}: {{ $envAll.Values.labels.node_selector_value }}
      containers:
        - name: init
          image: {{ tuple .Values.images.tags "dep_check" . | include "helm-toolkit.utils.update_image" }}
          imagePullPolicy: {{ .Values.images.pull_policy }}
          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.name
            - name: NAMESPACE
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.namespace
            - name: INTERFACE_NAME
              value: eth0
            - name: DEPENDENCY_SERVICE
              value: mycloud-product:dashboard-api,mycloud-product:dashboard-web
            - name: DEPENDENCY_JOBS
            - name: DEPENDENCY_DAEMONSET
            - name: DEPENDENCY_CONTAINER
            - name: COMMAND
              value: "echo done"
此篇文章对你是否有帮助?
没帮助
locked-file

您暂无权限访问该产品