kubernetes 忽略舵预安装钩故障

hec6srdp  于 2023-01-08  发布在  Kubernetes
关注(0)|答案(2)|浏览(131)

我有一个预安装挂钩,它创建动态PVC,如下所示

kind: PersistentVolumeClaim
metadata:
  name: my-dynamic-pv
  annotations:
    "helm.sh/resource-policy": keep
    "helm.sh/hook": "pre-install"
spec:
  storageClassName: {{ .Values.persistence.storageClass }}
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

我希望在重新启动时保留相同的PVC,这就是我提供"helm.sh/resource-policy": keep的原因。我可以在第一次启动服务时使用预安装钩子创建PVC。但随后的安装/重新启动失败,错误为Error: persistentvolumeclaims "my-dynamic-pv" already exists
是否有办法忽略此故障并继续安装helm?

h7appiyu

h7appiyu1#

您可以在创建pvc之前使用helm lookup函数检查其是否存在。

{{- $mypvc := (lookup "v1" "PersistentVolumeClaim" .Release.Namespace (printf "my- 
dynamic-pv")) }}
{{- if not $mypvc }}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: my-dynamic-pv
  annotations:
    "helm.sh/resource-policy": keep
    "helm.sh/hook": "pre-install"
spec:
  storageClassName: {{ .Values.persistence.storageClass }}
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
{{- end -}}

更多关于舵查找功能-Helm template functions
我使用的是helm 3.2.1,你可能需要一个比较接近的版本来使用查找功能。

ztyzrc3y

ztyzrc3y2#

helm命令使用--no-hooks标志以忽略挂接。

$ helm install --help | grep "no-hooks"
     
 --no-hooks                     prevent hooks from running during install

$ helm install <NAME> <CHART> --no-hooks

相关问题