# Example YAML configuration for the sidecar pattern.

# It defines a main application container which writes
# the current date to a log file every five seconds.

# The sidecar container is nginx serving that log file.
# (In practice, your sidecar is likely to be a log collection
# container that uploads to external storage.)

# To run:
#   kubectl apply -f sample-sidecar.yaml

apiVersion: v1
kind: Pod
metadata:
  name: pod-with-sidecar
  namespace: default
spec:
  # Create a volume called 'lacework-shared' that the
  # app and sidecar share.  This allows us to pass lacework binaries to the app container.
  volumes:
  - name: lacework-shared 
    emptyDir: {}
  # Lacework container
  initContainers:
  - name: lacework-sidecar
    # Simple sidecar: display log files using nginx.
    # In reality, this sidecar would be a custom image
    # that uploads logs to a third-party or storage service.
    image: 950194951070.dkr.ecr.us-west-2.amazonaws.com/galen-lw-sidecar
    command: ["/bin/sh"]
    args: ["-c", "cp -R /shared/* /lacework"]

    # Mount the pod's shared log file into the sidecar
    # container. In this case, nginx will serve the files
    # in this directory.
    volumeMounts:
    - name: lacework-shared
      mountPath: /lacework # nginx-specific mount path
  # In the sidecar pattern, there is a main application
  # container and a sidecar container.
  containers:

  # Main application container
  - name: app-container
    # Simple application: write the current date
    # to the log file every five seconds
    image: 950194951070.dkr.ecr.us-west-2.amazonaws.com/simple-nginx
    command: ["/shared/lacework.sh","/docker-entrypoint.sh"]
    args: ["nginx","-g","daemon off;"]

    # Mount the pod's shared log file into the app 
    # container. The app writes logs here.
    volumeMounts:
    - name: lacework-shared
      mountPath: /shared
