# _helpers.tpl
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "kube-hunter.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "kube-hunter.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "kube-hunter.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
 # cronjob.yaml
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: {{ template "kube-hunter.fullname" . }}
  labels:
    app: {{ template "kube-hunter.name" . }}
    chart: {{ template "kube-hunter.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
  annotations:
{{ toYaml .Values.cronjob.annotations | indent 4 }}
spec:
  schedule: "{{ .Values.cronjob.schedule }}"
  {{- with .Values.cronjob.concurrencyPolicy }}
  concurrencyPolicy: {{ . }}
  {{- end }}
  {{- with .Values.cronjob.failedJobsHistoryLimit }}
  failedJobsHistoryLimit: {{ . }}
  {{- end }}
  {{- with .Values.cronjob.successfulJobsHistoryLimit }}
  successfulJobsHistoryLimit: {{ . }}
  {{- end }}
  jobTemplate:
    metadata:
      labels:
        app: {{ template "kube-hunter.name" . }}
        release: {{ .Release.Name }}
    spec:
      template:
        metadata:
          labels:
            app: {{ template "kube-hunter.name" . }}
            release: {{ .Release.Name }}
          annotations:
{{ toYaml .Values.pod.annotations | indent 12 }}
        spec:
          restartPolicy: Never
{{- if .Values.priorityClassName }}
          priorityClassName: "{{ .Values.priorityClassName }}"
{{- end }}
          containers:
            - name: {{ .Chart.Name }}
              image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
              imagePullPolicy: {{ .Values.image.pullPolicy }}
              command: [ "python", "kube-hunter.py" ]
              args:
                - "--pod"
                {{- with .Values.customArguments }}
{{ toYaml . | indent 16 }}
                {{- end }}
              resources:
{{ toYaml .Values.resources | indent 16 }}
    {{- with .Values.nodeSelector }}
          nodeSelector:
{{ toYaml . | indent 12 }}
    {{- end }}
    {{- with .Values.affinity }}
          affinity:
{{ toYaml . | indent 12 }}
    {{- end }}
    {{- with .Values.tolerations }}
          tolerations:
{{ toYaml . | indent 12 }}:
{{- end }}

# D:efault values for elasticsearch-curator.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

cronjob:
  # At 01:00 every day
  schedule: "0 1 * * *"
  annotations: {}
  concurrencyPolicy: "Forbid"
  failedJobsHistoryLimit: "1"
  successfulJobsHistoryLimit: "1"

customArguments: []

pod:
  annotations: {}

image:
  repository: aquasec/kube-hunter
  tag: 312
  pullPolicy: IfNotPresent

resources: {}
  # We usually recommend not to specify default resources and to leave this as a conscious
  # choice for the user. This also increases chances charts run on environments with little
  # resources, such as Minikube. If you do want to specify resources, uncomment the following
  # lines, adjust them as necessary, and remove the curly braces after 'resources:'.
  # limits:
  #  cpu: 100m
  #  memory: 128Mi
  # requests:
  #  cpu: 100m
  #  memory: 128Mi

priorityClassName: ""
