fix(meshcentral): fix config file generation (#2591)

* fix(meshcentral): fix config file generation

* updates

* some fixes

* some more fixes

* fixes

* whoops

* fixes

* see output

* comma

* cleanup
This commit is contained in:
Stavros Kois
2022-05-01 19:43:55 +03:00
committed by GitHub
parent 13a87e138e
commit fa0d3f179d
3 changed files with 85 additions and 5 deletions

View File

@@ -1,7 +1,7 @@
apiVersion: v2
kubeVersion: ">=1.16.0-0"
name: meshcentral
version: 1.1.6
version: 1.1.7
appVersion: "1.0.1"
description: MeshCentral is a full computer management web site
type: application

View File

@@ -74,6 +74,26 @@ questions:
- value: "OnDelete"
description: "(Legacy) OnDelete: ignore .spec.template changes"
# Include{controllerExpert}
- variable: env
group: "Container Configuration"
label: "Image Environment"
schema:
additional_attrs: true
type: dict
attrs:
- variable: hostname
label: "hostname"
description: "Hostname of your meshcentral instance, used to generate self singed certs, eg. mesh.example.com or 192.168.1.100."
schema:
type: string
required: true
default: ""
- variable: reverseProxyUrl
label: "reverseProxyUrl"
description: "HTTPS URL on which you will reach this instance, can't be IP. eg. https://mesh.example.com/"
schema:
type: string
default: ""
# Include{containerConfig}

View File

@@ -3,6 +3,8 @@ image:
pullPolicy: IfNotPresent
tag: v1.0.1@sha256:d8642b3909fcd1dad6b920629dac8e6e3a609230f38c9d62ca01ca67c26a4730
extraArgs: ["--cert", "$hostname"]
securityContext:
readOnlyRootFilesystem: false
runAsNonRoot: false
@@ -11,6 +13,10 @@ podSecurityContext:
runAsUser: 0
runAsGroup: 0
env:
hostname: "test.example.com"
reverseProxyUrl: "https://test.example.com"
service:
main:
ports:
@@ -25,6 +31,10 @@ initContainers:
- name: data
mountPath: "/home/node/meshcentral/meshcentral-data"
env:
- name: hostname
value: "{{ .Values.env.hostname }}"
- name: reverseProxyUrl
value: "{{ .Values.env.reverseProxyUrl }}"
- name: svcPort
value: "{{ .Values.service.main.ports.main.port }}"
- name: "mongodbURL"
@@ -32,19 +42,69 @@ initContainers:
secretKeyRef:
name: mongodbcreds
key: url
command: ["/bin/sh", "-c"]
command: ["/bin/bash", "-c"]
args:
- >
export configfile='/home/node/meshcentral/meshcentral-data/config.json';
export basePath='/home/node/meshcentral/meshcentral-data/truecharts';
mkdir -p $basePath;
if [ -f $configfile ]; then
echo 'Config File exists, skipping...';
echo 'Config File exists, updating values...';
# Update hostname
sed -i 's/^ "cert":.*,$/ "cert": "'$hostname'",/1' $configfile;
export lastreverse=$(cat $basePath/.lastreverse);
if [ ! -z $reverseProxyUrl ]; then
if [[ $lastreverse == "NOT_PROVIDED" ]]; then
# Update reverseProxyUrl
echo "Adding $reverseProxyUrl...";
sed -i 's/^ "_certUrl": "'$lastreverse'",'$/ "certUrl": "'$reverseProxyUrl'",'/1' $configfile;
echo $reverseProxyUrl > $basePath/.lastreverse;
else
echo "Updating $lastreverse to $reverseProxyUrl...";
sed -i 's/^ "certUrl": "'$lastreverse'",'$/ "certUrl": "'$reverseProxyUrl'",'/1' $configfile;
echo $reverseProxyUrl > $basePath/.lastreverse;
fi;
else
echo "Removing reverse proxy url..."
sed -i 's/^ "_?certUrl":.*,$/ "_certUrl": "NOT_PROVIDED",/1' $configfile;
echo "NOT_PROVIDED" > $basePath/.lastreverse;
fi;
export lastport=$(cat $basePath/.lastport);
if [ ! -z $lastport ]; then
# Update port
echo "Updating $lastport to $svcPort...";
sed -i 's/^ "port": '$lastport',$/ "port": '$svcPort',/1' $configfile;
# Save new port.
echo "$svcPort" > $basePath/.lastport;
fi;
else
echo "DO NOT DELETE DOT FILES IN THIS DIR" > $basePath/DO_NOT_DELETE_DOT_FILES_IN_THIS_DIR;
echo 'Creating basic config to $configfile...';
echo '{' >> $configfile;
echo ' "$schema": "http://info.meshcentral.com/downloads/meshcentral-config-schema.json",' >> $configfile
echo ' "$schema": "http://info.meshcentral.com/downloads/meshcentral-config-schema.json",' >> $configfile;
echo ' "settings": {' >> $configfile;
# Save last port used
echo "$svcPort" > $basePath/.lastport;
echo ' "port": '$svcPort',' >> $configfile;
echo ' "mongoDb": "'$mongodbURL'"' >> $configfile;
echo ' "mongoDb": "'$mongodbURL'",' >> $configfile;
echo ' "cert": "'$hostname'"' >> $configfile;
echo ' },' >> $configfile;
echo ' "domains": {' >> $configfile;
echo ' "": {' >> $configfile;
if [ ! -z $reverseProxyUrl ]; then
echo ' "certUrl": "'$reverseProxyUrl'"' >> $configfile;
# Save last reverse url used
echo $reverseProxyUrl > $basePath/.lastreverse;
else
# Underscore in front the the key is making it invisible to meshcentral
echo ' "_certUrl": "NOT_PROVIDED"' >> $configfile;
# Save last reverse url used
echo "NOT_PROVIDED" > $basePath/.lastreverse;
fi;
echo ' }' >> $configfile;
echo ' }' >> $configfile;
echo '}' >> $configfile;
fi;