{{- if .Values.autolock.enabled }}
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: {{ template "kured.fullname" . }}-lock
  namespace: {{ .Release.Namespace }}
  labels:
    app: {{ template "kured.name" . }}
    chart: {{ template "kured.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  schedule: {{ .Values.autolock.schedulelock | quote }}
  jobTemplate:
    spec:
      template:
        metadata:
          labels:
            app: {{ template "kured.name" . }}
            chart: {{ template "kured.chart" . }}
            release: {{ .Release.Name }}
            heritage: {{ .Release.Service }}
        spec:
          serviceAccountName: {{ template "kured.serviceAccountName" . }}
          containers:
            - name: {{ template "kured.fullname" . }}-lock
              image: "{{ .Values.autolock.image.repository }}:{{ .Values.autolock.image.tag }}"
              command:
                - kubectl
              args:
                - -n 
                - {{ .Release.Namespace }}
                - annotate
                - ds
                - {{ template "kured.fullname" . }}
                - weave.works/kured-node-lock={"nodeID":"manual"}
          restartPolicy: Never
      backoffLimit: 1
{{- end -}}
