如何在子图表中检查父图表配置映射已更改?

问题描述 投票:0回答:1

我正在尝试使用 sha256sum 来检测 ConfigMap 中的更改并触发 pod 重新启动。 ConfigMap 由集群中的父图表部署。环境部分一切正常,但第二个校验和有问题。我不明白正确的道路应该是什么样子。

子图的deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "test-project.fullname" . }}
  labels:
    app.kubernetes.io/name: {{ include "test-project.name" . }}
    helm.sh/chart: {{ include "test-project.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
  replicas: {{ .Values.replicaCount }}
  strategy:
    rollingUpdate:
      maxUnavailable: 0
      maxSurge: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "test-project.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app.kubernetes.io/name: {{ include "test-project.name" . }}
        app.kubernetes.io/instance: {{ .Release.Name }}
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
        checksum/config1: {{ include (print $.Files.Get "configmaps/myproduct.yaml") . | sha256sum }} //error line
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            {{- if not .Values.security.useSSLConnection }}
            - name: http
              containerPort: {{ .Values.springboot.server.port | default 8080 }}
              protocol: TCP
            {{- else }}
            - name: https
              containerPort: {{ .Values.springboot.server.port | default 8080 }}
              protocol: TCP
            {{- end }}
          readinessProbe:
            httpGet:
              path: {{ .Values.readiness.path | default "/actuator/ready" }}
              port: {{ .Values.springboot.actuator.port | default "http" }}
              scheme: HTTP{{ if $.Values.security.useSSLConnection }}S{{ end }}
            initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds | default 10 }}
            periodSeconds: {{ .Values.readiness.periodSeconds | default 10 }}
            timeoutSeconds: {{ .Values.readiness.timeoutSeconds | default 1 }}
            successThreshold: {{ .Values.readiness.successThreshold | default 1 }}
            failureThreshold: {{ .Values.readiness.failureThreshold | default 3 }}
          livenessProbe:
            httpGet:
              path: {{ .Values.liveness.path | default "/actuator/alive" }}
              port: {{ .Values.springboot.actuator.port | default "http" }}
              scheme: HTTP{{ if $.Values.security.useSSLConnection }}S{{ end }}
            initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds | default 300 }}
            periodSeconds: {{ .Values.liveness.periodSeconds | default 10 }}
            timeoutSeconds: {{ .Values.liveness.timeoutSeconds | default 1 }}
            successThreshold: {{ .Values.liveness.successThreshold | default 1 }}
            failureThreshold: {{ .Values.liveness.failureThreshold | default 3 }}
          env:
            - name: MY_PRODJECT
              valueFrom:
                configMapKeyRef:
                  name: my-product
                  key: prj-version
            - name: ACTUATOR_PORT
              value: "{{ .Values.springboot.actuator.port }}"
            - name: USE_SSL
              value: "{{ .Values.security.useSSLConnection }}"
            - name: CRL_ENABLED
              value: "{{ .Values.security.CRLEnabled }}"

来自父图表的 ConfigMap myproduct.yaml:

apiVersion: v1
kind: ConfigMap
metadata:
  name: my-product
  namespace: {{ .Release.Namespace }}
data:
  prj-version: "0.3"
kubernetes kubernetes-helm
1个回答
0
投票

@Matvey Nefedov - 我也遇到了同样的问题,您能提供适合您的解决方案吗?

© www.soinside.com 2019 - 2024. All rights reserved.