# Copyright 2021 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.
#
# Description: Example Kubernetes DaemonSet YAML

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: kube-node-tracer
  namespace: <NAMESPACE>                        #Namespace for the pod
  labels:
    app: kube-node-tracer
spec:
  selector:
    matchLabels:
      app: kube-node-tracer
  template:
    metadata:
      labels:
        app: kube-node-tracer
    spec:
      hostNetwork: true                          #Use host network namespace (Note: This is required to collect on node primary NIC)
      hostPID: false                             #User host procress ID namespace
      hostIPC: false                             #Use host IPC namespace 
      containers:
        - name: node-tracer
          image: <KUBE NODE TRACER IMAGE>            
          imagePullPolicy: IfNotPresent
          securityContext:
            privileged: true                    #Execute in priviledged mode to run as root on the host 
          args: ["-N","$(NODE_NAME)","-b","$(GCS_BUCKET)", "-C", "$(FILE_SIZE_MB)", "-W", $(FILE_COUNT)]
          volumeMounts:
            - name: dump
              mountPath: /dump/
              subPathExpr: $(NODE_NAME)
          env:
          #Metadata ENV
          - name: NODE_NAME
            valueFrom:
              fieldRef:
                fieldPath: spec.nodeName
          #TCPdump ENV
          - name: GCS_BUCKET
            value: "<GCS-BUCKET-NAME>"
          - name: FILE_SIZE_MB                  #Optional - Default 100 MB
            value: "100"
          - name: FILE_COUNT                    #Optional - Default 100
            value: "100"
  
      #EmptyDir volume (Default)
      volumes:
        - name: dump
          emptyDir: {}

      #Filestore (NFS) volume - Note: Use this option for a resource constrained clusters (See: examples/pvc_filestore and examples/pv_filestore)
      #volumes:
      #  - name: dump
      #    persistentVolumeClaim:
      #      claimName: fileserver-claim
      #      readOnly: false
        
      tolerations:
        - effect: "NoExecute"
          operator: "Exists"
        - effect: "NoSchedule"
          operator: "Exists"
