update vault integration
This commit is contained in:
27
internal/kubespray/cluster.go
Normal file
27
internal/kubespray/cluster.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package kubespray
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"kube-forge/internal/config"
|
||||
"kube-forge/internal/secrets_storage"
|
||||
)
|
||||
|
||||
func InstallCluster(tags string) {
|
||||
// runPlaybook("kubespray/project/cluster.yml", tags)
|
||||
|
||||
config := config.GetConfig()
|
||||
if config.Modules.SecretsStorage.Enabled {
|
||||
fmt.Println("## Additional Vault Configuration")
|
||||
secrets_storage.InitVault()
|
||||
secrets_storage.UnsealVault()
|
||||
secrets_storage.AddKubernetesLocalIntegration()
|
||||
}
|
||||
}
|
||||
|
||||
func UpgradeCluster(tags string) {
|
||||
runPlaybook("kubespray/project/upgrade_cluster.yml", tags)
|
||||
}
|
||||
|
||||
func ScaleCluster() {
|
||||
runPlaybook("kubespray/project/scale.yml", "")
|
||||
}
|
||||
75
internal/kubespray/utility.go
Normal file
75
internal/kubespray/utility.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package kubespray
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"kube-forge/internal/config"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/apenella/go-ansible/v2/pkg/execute"
|
||||
"github.com/apenella/go-ansible/v2/pkg/execute/stdoutcallback"
|
||||
"github.com/apenella/go-ansible/v2/pkg/playbook"
|
||||
)
|
||||
|
||||
func getPlaybookParameters(tags string) playbook.AnsiblePlaybookOptions {
|
||||
cfg := config.GetConfig()
|
||||
|
||||
ansiblePlaybookOptions := playbook.AnsiblePlaybookOptions{
|
||||
Inventory: filepath.Join(cfg.WorkDir, "kubespray/inventory/hosts"),
|
||||
Tags: tags,
|
||||
User: cfg.Credentials.User,
|
||||
Become: true,
|
||||
}
|
||||
|
||||
if cfg.Credentials.PrivateKeyFile != "" {
|
||||
ansiblePlaybookOptions.PrivateKey = cfg.Credentials.PrivateKeyFile
|
||||
}
|
||||
|
||||
if cfg.Credentials.AskSudoPassword {
|
||||
ansiblePlaybookOptions.AskBecomePass = true
|
||||
}
|
||||
|
||||
return ansiblePlaybookOptions
|
||||
}
|
||||
|
||||
func CopyK8SAdminConfig(pathInDataDir string) {
|
||||
config := config.GetConfig()
|
||||
dataDir := config.WorkDir
|
||||
var adminDefaultConfigPath = filepath.Join(dataDir, "kubespray/inventory/artifacts/admin.conf")
|
||||
var adminOutConfigPath = filepath.Join(dataDir, pathInDataDir)
|
||||
source, err := os.Open(adminDefaultConfigPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer source.Close()
|
||||
|
||||
destination, err := os.Create(adminOutConfigPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer destination.Close()
|
||||
_, err = io.Copy(destination, source)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func runPlaybook(playbookPath string, tags string) {
|
||||
playbookOptions := getPlaybookParameters(tags)
|
||||
playbookCmd := playbook.NewAnsiblePlaybookCmd(
|
||||
playbook.WithPlaybooks(playbookPath),
|
||||
playbook.WithPlaybookOptions(&playbookOptions),
|
||||
)
|
||||
exec := stdoutcallback.NewDenseStdoutCallbackExecute(
|
||||
execute.NewDefaultExecute(
|
||||
execute.WithCmd(playbookCmd),
|
||||
execute.WithErrorEnrich(playbook.NewAnsiblePlaybookErrorEnrich()),
|
||||
),
|
||||
)
|
||||
|
||||
err := exec.Execute(context.Background())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user