# Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
#
# 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.
#
# Contains Injection details required by the sidecar injector deployment to add proper sidecars, volume Mounts etc

apiVersion: v1
kind: ConfigMap
metadata:
  name: sidecar-injector-webhook-configmap
data:
  sidecarconfig.yaml: |
    initContainers:
      - name: copy-scripts
        image: busybox
        command: ['sh', '-c']
        args: ['cp /scripts/filebeat.yml /etc/pre-install/filebeat.yml; chown 1000 /etc/pre-install/filebeat.yml;']
        securityContext:
          runAsUser: 0
        volumeMounts:
          - name: scripts
            mountPath: /scripts/filebeat.yml
            subPath: filebeat.yml
          - name: filebeat-yaml
            mountPath: /etc/pre-install
    containers:
      - name: filebeat-sidecar
        image: docker.elastic.co/beats/filebeat:7.2.0
        volumeMounts:
          - name: filebeat-yaml
            mountPath: /usr/share/filebeat/filebeat.yml
            subPath: filebeat.yml
            readOnly: false
        env:
          - name: NODE_NAME
            valueFrom:
              fieldRef:
                fieldPath: spec.nodeName
          - name: POD_NAME
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
          - name: POD_IP
            valueFrom:
              fieldRef:
                fieldPath: status.podIP
    volumes:
      - name: scripts
        configMap:
          name: filebeat-yaml
      - name: filebeat-yaml
        emptyDir: {}
    env:
      - name: NODE_NAME
        valueFrom:
          fieldRef:
            fieldPath: spec.nodeName
      - name: POD_NAME
        valueFrom:
          fieldRef:
            fieldPath: metadata.name
      - name: NAMESPACE
        valueFrom:
          fieldRef:
            fieldPath: metadata.namespace
      - name: POD_IP
        valueFrom:
          fieldRef:
            fieldPath: status.podIP

