change panic to fatal log
This commit is contained in:
@@ -2,8 +2,6 @@ package kubespray
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"kube-forge/internal/config"
|
||||
"kube-forge/internal/logging"
|
||||
"kube-forge/internal/python"
|
||||
@@ -15,48 +13,6 @@ import (
|
||||
"github.com/apenella/go-ansible/v2/pkg/playbook"
|
||||
)
|
||||
|
||||
func getPlaybookParameters(tags string) playbook.AnsiblePlaybookOptions {
|
||||
cfg := config.GetConfig()
|
||||
|
||||
ansiblePlaybookOptions := playbook.AnsiblePlaybookOptions{
|
||||
Inventory: filepath.Join(cfg.InventoryDir, "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(outFile string) {
|
||||
config := config.GetConfig()
|
||||
var adminDefaultConfigPath = filepath.Join(config.InventoryDir, "artifacts/admin.conf")
|
||||
source, err := os.Open(adminDefaultConfigPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer source.Close()
|
||||
|
||||
destination, err := os.Create(outFile)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer destination.Close()
|
||||
_, err = io.Copy(destination, source)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
logging.Log.Info(fmt.Sprintf("K8s admin config: %s", outFile))
|
||||
}
|
||||
|
||||
func runPlaybook(playbookPath string, tags string) {
|
||||
config := config.GetConfig()
|
||||
var callbackExecute execute.Executor
|
||||
@@ -111,6 +67,6 @@ func runPlaybook(playbookPath string, tags string) {
|
||||
|
||||
err := callbackExecute.Execute(context.Background())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
logging.Log.Fatal(err)
|
||||
}
|
||||
}
|
||||
54
internal/kubespray/utilits.go
Normal file
54
internal/kubespray/utilits.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package kubespray
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"kube-forge/internal/config"
|
||||
"kube-forge/internal/logging"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/apenella/go-ansible/v2/pkg/playbook"
|
||||
)
|
||||
|
||||
func getPlaybookParameters(tags string) playbook.AnsiblePlaybookOptions {
|
||||
cfg := config.GetConfig()
|
||||
|
||||
ansiblePlaybookOptions := playbook.AnsiblePlaybookOptions{
|
||||
Inventory: filepath.Join(cfg.InventoryDir, "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(outFile string) {
|
||||
config := config.GetConfig()
|
||||
var adminDefaultConfigPath = filepath.Join(config.InventoryDir, "artifacts/admin.conf")
|
||||
source, err := os.Open(adminDefaultConfigPath)
|
||||
if err != nil {
|
||||
logging.Log.Fatal(err)
|
||||
}
|
||||
defer source.Close()
|
||||
|
||||
destination, err := os.Create(outFile)
|
||||
if err != nil {
|
||||
logging.Log.Fatal(err)
|
||||
}
|
||||
defer destination.Close()
|
||||
_, err = io.Copy(destination, source)
|
||||
if err != nil {
|
||||
logging.Log.Fatal(err)
|
||||
}
|
||||
logging.Log.Info(fmt.Sprintf("K8s admin config: %s", outFile))
|
||||
}
|
||||
Reference in New Issue
Block a user