Files
kube-forge/internal/cicd/helm.go

109 lines
3.5 KiB
Go

package cicd
import (
"kube-forge/internal/config"
"kube-forge/internal/helm_client"
"kube-forge/internal/templates"
"time"
go_helm_client "github.com/mittwald/go-helm-client"
)
var HELM_REPOS = [...]config.RepoSettings{
{
Name: "kube-forge",
URL: "https://git.kvazaric.ru/api/v4/projects/41/packages/helm/stable",
},
}
func getArgoCdSpec() go_helm_client.ChartSpec {
appConfig := config.GetConfig()
return go_helm_client.ChartSpec{
ReleaseName: "argo-cd",
ChartName: appConfig.Modules.Cicd.ArgoCd.ChartRef,
Version: appConfig.Modules.Cicd.ArgoCd.ChartVersion,
Namespace: appConfig.Modules.Cicd.Namespace,
CreateNamespace: true,
Atomic: true,
Timeout: time.Second * 600,
ValuesYaml: templates.GetHelmValuesByTemplate("templates/helm-apps/releases/cicd/argo-cd.yml.tmpl"),
}
}
func getArgoRolloutsSpec() go_helm_client.ChartSpec {
appConfig := config.GetConfig()
return go_helm_client.ChartSpec{
ReleaseName: "argo-rollouts",
ChartName: appConfig.Modules.Cicd.Rollouts.ChartRef,
Version: appConfig.Modules.Cicd.Rollouts.ChartVersion,
Namespace: appConfig.Modules.Cicd.Namespace,
CreateNamespace: true,
Atomic: true,
Timeout: time.Second * 600,
ValuesYaml: templates.GetHelmValuesByTemplate("templates/helm-apps/releases/cicd/argo-rollouts.yml.tmpl"),
}
}
func getKeelSpec() go_helm_client.ChartSpec {
appConfig := config.GetConfig()
return go_helm_client.ChartSpec{
ReleaseName: "keel",
ChartName: appConfig.Modules.Cicd.UpdatesOperator.ChartRef,
Version: appConfig.Modules.Cicd.UpdatesOperator.ChartVersion,
Namespace: appConfig.Modules.Cicd.UpdatesOperator.Namespace,
CreateNamespace: true,
Atomic: true,
Timeout: time.Second * 600,
ValuesYaml: templates.GetHelmValuesByTemplate("templates/helm-apps/releases/cicd/keel.yml.tmpl"),
}
}
func getArgoCdIngressSpec() go_helm_client.ChartSpec {
appConfig := config.GetConfig()
return go_helm_client.ChartSpec{
ReleaseName: "argo-cd-ingress",
ChartName: appConfig.Modules.Cicd.ArgoCd.ServiceIngress.ChartRef,
Version: appConfig.Modules.Cicd.ArgoCd.ServiceIngress.ChartVersion,
Namespace: appConfig.Modules.Cicd.Namespace,
CreateNamespace: true,
Atomic: true,
Timeout: time.Second * 600,
ValuesYaml: templates.GetHelmValuesByTemplate("templates/helm-apps/releases/cicd/argo-cd-ingress.yml.tmpl"),
}
}
func addCicdHelmRepos() {
appConfig := config.GetConfig()
for _, repoSettings := range HELM_REPOS {
helm_client.AddHelmRepo(appConfig.Modules.SecretsStorage.Namespace, repoSettings)
}
}
func ApplyCharts() {
addCicdHelmRepos()
appConfig := config.GetConfig()
if appConfig.Modules.Cicd.Enabled {
helm_client.InstallChart(getArgoCdSpec())
if appConfig.Modules.Cicd.ArgoCd.Expose.Type == "ingress" {
helm_client.InstallChart(getArgoCdIngressSpec())
} else {
helm_client.DeleteChart(getArgoCdIngressSpec())
}
if appConfig.Modules.Cicd.Rollouts.Enabled {
helm_client.InstallChart(getArgoRolloutsSpec())
} else {
helm_client.DeleteChart(getArgoRolloutsSpec())
}
if appConfig.Modules.Cicd.UpdatesOperator.Enabled {
helm_client.InstallChart(getKeelSpec())
} else {
helm_client.DeleteChart(getKeelSpec())
}
} else {
helm_client.DeleteChart(getArgoCdIngressSpec())
helm_client.DeleteChart(getArgoCdSpec())
helm_client.DeleteChart(getArgoRolloutsSpec())
helm_client.DeleteChart(getKeelSpec())
}
}