# Copyright 2020 Ciena Corporation
#
# 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: v1
kind: Pod
metadata:
  name: tell-the-secret
spec:
  containers:
    - name: teller
      image: alpine
      command:
        - "/bin/sh"
        - "-c"
        # yamllint disable-line rule:line-length
        - "while true; do date -u '+%Y-%m-%dT%H:%M:%SZ:' ; echo '  environment:'; echo '    - secret: \"'$MY_SECRET'\"' | sed -e 's/ \"$/\"/g'; echo '    - added: \"'$ADDED_SECRET'\"' | sed -e 's/ \"$/\"/g'; echo '  mounts:'; echo '    - secret: \"'$(cat /var/my-secret/secret.txt 2>&1)'\"'; echo '    - added: \"'$(cat /var/my-secret/added-secret.txt 2>&1)'\"'; sleep 3; done"
      env:
        - name: MY_SECRET
          valueFrom:
            secretKeyRef:
              name: the-secret
              key: secret.txt
        - name: ADDED_SECRET
          valueFrom:
            secretKeyRef:
              name: the-secret
              key: added-secret.txt
              optional: true
      volumeMounts:
        - name: my-secret
          mountPath: "/var/my-secret"
          readOnly: true
  volumes:
    - name: my-secret
      secret:
        secretName: the-secret
