#Copyright (c) Cloudneeti. All rights reserved.
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is  furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: cloudneeti-agent-worker
  namespace: cloudneeti
spec:
  schedule: "0 12 * * *"
  jobTemplate:
    metadata:
      labels:
        app: cloudneeti-agent-worker
    spec:
      template:
        spec:
          hostPID: true
          restartPolicy: OnFailure
          containers:
          - name: kube-bench
            image: aquasec/kube-bench:latest
            command: ["/bin/sh", "-c"]
            args: ["kube-bench --benchmark cis-1.5 >> /var/log/kube-bench/kube-bench.log 2>&1"]
            volumeMounts:
            - name: var-lib-etcd
              mountPath: /var/lib/etcd
            - name: var-lib-kubelet
              mountPath: /var/lib/kubelet
            - name: etc-systemd
              mountPath: /etc/systemd
            - name: etc-kubernetes
              mountPath: /etc/kubernetes
              # /usr/bin is mounted to access kubectl / kubelet, for auto-detecting the Kubernetes version.
              # You can omit this mount if you specify --version as part of the command.
            - name: usr-bin
              mountPath: /usr/bin
            - name: kube-bench-log
              mountPath: /var/log/kube-bench
          - name: cloudneeti-agent
            image: cloudneeticorp/cloudneeti-agent:2.6
            env:
              - name: CLUSTER_NAME
                valueFrom:
                  configMapKeyRef:
                    name: cloudneeti-agent-config
                    key: clusterName
              - name: LICENSE_ID
                valueFrom:
                  configMapKeyRef:
                    name: cloudneeti-agent-config
                    key: licenseId
              - name: ACCOUNT_ID
                valueFrom:
                  configMapKeyRef:
                    name: cloudneeti-agent-config
                    key: accountId
              - name: CLOUDNEETI_ENV
                valueFrom:
                  configMapKeyRef:
                    name: cloudneeti-agent-config
                    key: cloudneetiEnvironment
              - name: CLOUDNEETI_APIAPP_ID
                valueFrom:
                  configMapKeyRef:
                    name: cloudneeti-agent-config
                    key: cloudneetiApiAppId
              - name: CLOUDNEETI_API_KEY
                valueFrom:
                  secretKeyRef:
                    name: cloudneeti-agent
                    key: cloudneetiAPIKey
              - name: CLOUDNEETI_APIAPP_SECRET
                valueFrom:
                  secretKeyRef:
                    name: cloudneeti-agent
                    key: cloudneetiAPIAppSecret
            volumeMounts:
            - name: kube-bench-log
              mountPath: /var/log/kube-bench
          volumes:
          - name: var-lib-etcd
            hostPath:
              path: "/var/lib/etcd"
          - name: var-lib-kubelet
            hostPath:
              path: "/var/lib/kubelet"
          - name: etc-systemd
            hostPath:
              path: "/etc/systemd"
          - name: etc-kubernetes
            hostPath:
              path: "/etc/kubernetes"
          - name: usr-bin
            hostPath:
              path: "/usr/bin"
          - name: kube-bench-log
            emptyDir: {}