migrate from kubespray to library helm client
This commit is contained in:
32
internal/helm_client/chart.go
Normal file
32
internal/helm_client/chart.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package helm_client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"kube-forge/internal/config"
|
||||
"kube-forge/internal/logging"
|
||||
|
||||
go_helm_client "github.com/mittwald/go-helm-client"
|
||||
)
|
||||
|
||||
func InstallChart(chartSpec go_helm_client.ChartSpec) {
|
||||
helmClient := config.GetHelmClient(chartSpec.Namespace)
|
||||
_, error := helmClient.GetRelease(chartSpec.ReleaseName)
|
||||
if error != nil {
|
||||
logging.Log.Infof("Installing %s", chartSpec.ChartName)
|
||||
} else {
|
||||
logging.Log.Infof("Upgrading %s", chartSpec.ChartName)
|
||||
}
|
||||
if _, err := helmClient.InstallOrUpgradeChart(context.Background(), &chartSpec, nil); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func DeleteChart(chartSpec go_helm_client.ChartSpec) {
|
||||
helmClient := config.GetHelmClient(chartSpec.Namespace)
|
||||
_, error := helmClient.GetRelease(chartSpec.ReleaseName)
|
||||
if error != nil {
|
||||
return
|
||||
}
|
||||
logging.Log.Warnf("Uninstalling %s", chartSpec.ChartName)
|
||||
helmClient.UninstallRelease(&chartSpec)
|
||||
}
|
||||
27
internal/helm_client/repo.go
Normal file
27
internal/helm_client/repo.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package helm_client
|
||||
|
||||
import (
|
||||
"kube-forge/internal/config"
|
||||
|
||||
"helm.sh/helm/v3/pkg/repo"
|
||||
)
|
||||
|
||||
func AddHelmRepo(namespace string, repoSettings config.RepoSettings) {
|
||||
helmClient := config.GetHelmClient(namespace)
|
||||
chartRepo := repo.Entry{
|
||||
Name: repoSettings.Name,
|
||||
URL: repoSettings.URL,
|
||||
Username: repoSettings.Username,
|
||||
Password: repoSettings.Password,
|
||||
}
|
||||
|
||||
if err := helmClient.AddOrUpdateChartRepo(chartRepo); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func AddHelmRepos(namespace string, helmRepos []config.RepoSettings) {
|
||||
for _, repoSettings := range helmRepos {
|
||||
AddHelmRepo(namespace, repoSettings)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user