I am working on a bash script to dynamically change the key within my Kubernetes secrets. I am able to use sed to change the values, but the output file is changed to a new line format. How do you have sed just replace word in file without breaking the file format?
Here is an example of the original chart:
apiVersion: v1
kind: Secret
metadata:
name: configs
namespace: {{Namespace}}
stringData:
DOMAIN: {{Domain}}
DB_USER: postgres
DB_PASS: {{DBpass}}
This is my current script:
original_yaml=$(cat chart.yam)
# create new yaml file.
modified_yaml=$(echo "$original_yaml" |
sed "s/{{Namespace}}/$name/" |
sed "s/{{NODE_COOKIE}}/$node_cookiee/" |
sed "s/{{HubDomain}}/$hub_domain/" |
sed "s/{{DBpass}}/$db_pass/" |
sed "s/{{SmtpServer}}/$mail_server/" |
sed "s/{{SmtpPort}}/$mail_port/" |
sed "s/{{SmtpUser}}/$mail_user/" |
sed "s/{{SmtpPass}}/$mail_pass/" |
sed "s/{{UserEmail}}/$mail_email/"|
)
echo $modified_yaml > render.yam
Here is an example of the resulting output in the render.yaml file:
apiVersion: v1 kind: Secret metadata: name: configs namespace: x stringData: DB_USER: postgres DB_PASS: x