In Kubernetes in initContainer I am running following command to replace two values taken from env variables:
initContainers:
- name: init-atsconfigs
image: busybox
command: ['sh', '-c', 'cd /tmp/ats && for i in $(ls *.config); do cat $i > /etc/trafficserver_edit/$i; done; sed -i "s/_AWS_ACCESS_KEY_OVERRIDE_/$AWS_ACCESS_KEY/g" /etc/trafficserver_edit/*.config', 'cd /tmp/ats && for i in $(ls *.config); do cat $i > /etc/trafficserver_edit/$i; done; sed -i "s/_AWS_ACCESS_SECRET_KEY_OVERRIDE_/$AWS_ACCESS_SECRET_KEY/g" /etc/trafficserver_edit/*.config']
File /etc/trafficserver_edit/s3_auth_v4.config
looks like:
access_key=_AWS_ACCESS_KEY_OVERRIDE_
secret_key=_AWS_ACCESS_SECRET_KEY_OVERRIDE_
version=4
v4-region-map=region_map.config
Unfortunately first sed command is zeroing second value in the source file leaving it blank:
access_key=AKIA....
secret_key=
version=4
v4-region-map=region_map.config
How sed command should look like to prevent that?
edit: All failing attempts:
command: ['sh', '-c', 'cd /tmp/ats && for i in $(ls *.config); do cat $i > /etc/trafficserver_edit/$i; done; sed -e "s/_AWS_ACCESS_KEY_OVERRIDE_/$AWS_ACCESS_KEY/g" ; sed -e "s/_AWS_SECRET_KEY_OVERRIDE_/$AWS_ACCESS_SECRET_KEY/g" /etc/trafficserver_edit/*.config']
command: ['sh', '-c', 'cd /tmp/ats && for i in $(ls *.config); do cat $i > /etc/trafficserver_edit/$i; done; sed -i "s/_AWS_ACCESS_KEY_OVERRIDE_/$AWS_ACCESS_KEY/g" /etc/trafficserver_edit/*.config', 'cd /tmp/ats && for i in $(ls *.config); do cat $i > /etc/trafficserver_edit/$i; done; sed -i "s/_AWS_SECRET_KEY_OVERRIDE_/$AWS_ACCESS_SECRET_KEY/g" /etc/trafficserver_edit/*.config']
command: ['sh', '-c', 'cd /tmp/ats && for i in $(ls *.config); do cat $i > /etc/trafficserver_edit/$i; done; sed -i "s/_AWS_ACCESS_KEY_OVERRIDE_/$AWS_ACCESS_KEY/g;s/_AWS_ACCESS_SECRET_KEY_OVERRIDE_/$AWS_ACCESS_SECRET_KEY/g" /etc/trafficserver_edit/*.config
more..
I used envsubst to solve this issue. So in my container I am running a Bash script on start doing:
#!/bin/bash
cp -ar /etc/trafficserver_init/*.config /etc/trafficserver/
envsubst '$AWS_ACCESS_KEY,$AWS_ACCESS_SECRET_KEY' < /tmp/trafficserver_conf/s3_auth_v4.config > /etc/trafficserver/s3_auth_v4.config
envsubst '$AWS_DEFAULT_REGION' < /tmp/trafficserver_conf/region_map.config > /etc/trafficserver/region_map.config
rm -rf /tmp/trafficserver_conf
I have also modified initContainer command to:
command: ['sh', '-c', 'cd /tmp/ats && for i in $(ls *.config); do cat $i > /etc/trafficserver_init/$i; done']