# Copyright 2021 Kontain
# Derived from: 
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: kontain-node-initializer
  namespace: kube-system
  labels:
    app: kontain-init
spec:
  selector:
    matchLabels:
      app: kontain-init
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        name: kontain-node-initializer
        app: kontain-init
    spec:
      containers:
      - image: centos:7    # ubuntu:18.04
        name: node-initializer
        command: ["/scripts/entrypoint.sh"]
        env:
        - name: ROOT_MOUNT_DIR
          value: /root
        - name: KONTAIN_RELEASE_URL
          value: https://github.com/kontainapp/km/releases/download/v0.9.3/kontain_bin.tar.gz
        - name: NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        securityContext:
          privileged: true
        volumeMounts:
        - name: root-mount
          mountPath: /root
        - name: lib-entrypoint
          mountPath: /scripts-lib
        - name: entrypoint
          mountPath: /scripts
        - name: crio-conf
          mountPath: /etc/crio/
        - name: containerd-conf
          mountPath: /etc/containerd/
        - name: dbus
          mountPath: /var/run/dbus
        - name: systemd
          mountPath: /run/systemd
      volumes:
      - name: root-mount
        hostPath:
          path: /
      - name: entrypoint
        configMap:
          name: kontain-install-entrypoint
          defaultMode: 0744
      - name: lib-entrypoint
        configMap:
          name: kontain-install-lib
          defaultMode: 0744
      - name: crio-conf
        hostPath:
          path: /etc/crio/
      - name: containerd-conf
        hostPath:
          path: /etc/containerd/
      - name: dbus
        hostPath:
          path: /var/run/dbus
      - name: systemd
        hostPath:
          path: /run/systemd
