69 lines
2.0 KiB
Bash
69 lines
2.0 KiB
Bash
metricLabel="[Metric]"
|
|
|
|
# Copies vmagent config file to the configured metric path.
|
|
function cmdMetricPreparation() {
|
|
printSection "Preparation..."
|
|
|
|
mkdir -p -- "$(dirname -- "$metricVmagentPath")" || return 1
|
|
cp -f -- "$appAssetsPath/metric/vmagent.yml" "$metricVmagentPath/vmagent.yml"
|
|
|
|
printDotText "preparation" "$labelDone"
|
|
}
|
|
|
|
# Renders the Metric Kubernetes YAML manifest via Helm.
|
|
function cmdMetricYamlRender() {
|
|
local templateFile="templates/$metricKube.yaml"
|
|
|
|
printSection "Render YAML file | Helm"
|
|
printDotText "Template" "$appAssetsPath/k3s/$templateFile"
|
|
[[ -f "$appAssetsPath/k3s/$templateFile" ]] || {
|
|
printDanger "Template file not found"
|
|
return 1
|
|
}
|
|
|
|
local varsFile
|
|
varsFile=$(mktemp "/tmp/$metricKube.vars.XXXXXX.yaml") || {
|
|
printDotText "render" "$labelFail"
|
|
printDanger "Create temp variables file"
|
|
return 1
|
|
}
|
|
printDotText "Variables" "$varsFile"
|
|
trap 'rm -f -- "$varsFile"' RETURN
|
|
cat > "$varsFile" <<EOF
|
|
metricHelm: true
|
|
namespace: $k3sNamespace
|
|
metric: $metricKube
|
|
metricApiUrl: $metricApiUrl
|
|
metricPromPath: $metricPromPath
|
|
metricVmagentPath: $metricVmagentPath
|
|
EOF
|
|
|
|
printDotText "Result" "$metricYaml"
|
|
mkdir -p -- "$(dirname -- "$metricYaml")" || return 1
|
|
fileBackup "$metricYaml"
|
|
helm template stack "$appAssetsPath/k3s" -f "$varsFile" --show-only "$templateFile" > "$metricYaml" || {
|
|
printDotText "render" "$labelFail"
|
|
printDanger "Render failed"
|
|
return 1
|
|
}
|
|
|
|
printDotText "render" "$labelDone"
|
|
}
|
|
|
|
function cmdMetricxUpdate() {
|
|
cmdMetricYamlRender || return 1
|
|
cmdK3sYamlApplyEx "$metricYaml" || return 1
|
|
}
|
|
|
|
# Installs Metric components into Kubernetes.
|
|
function cmdMetricInstall() {
|
|
cmdMetricPreparation || return 1
|
|
cmdMetricYamlRender || return 1
|
|
cmdK3sYamlApplyEx "$metricYaml" || return 1
|
|
}
|
|
|
|
# Uninstalls Metric Kubernetes resources.
|
|
function cmdMetricUninstall() {
|
|
"$k3sCmd" kubectl delete -f "$metricYaml"
|
|
}
|