kube-forge v2: embede python with ansible (kubespray) and cobra as cli building tool
This commit is contained in:
@@ -2,7 +2,7 @@ package config
|
||||
|
||||
import (
|
||||
"github.com/apenella/go-ansible/pkg/options"
|
||||
"github.com/apenella/go-ansible/pkg/playbook"
|
||||
"github.com/apenella/go-ansible/v2/pkg/playbook"
|
||||
)
|
||||
|
||||
type AnsiblePlaybookConfig struct {
|
||||
|
||||
@@ -2,10 +2,19 @@ package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"kube-forge/internal/files"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/ilyakaznacheev/cleanenv"
|
||||
)
|
||||
|
||||
var (
|
||||
ConfigFile string
|
||||
Output string
|
||||
Password string
|
||||
Verbose bool
|
||||
)
|
||||
|
||||
type Host struct {
|
||||
Hostname string `yaml:"hostname"`
|
||||
Ip string `yaml:"ip"`
|
||||
@@ -15,10 +24,12 @@ type Host struct {
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
WorkDir string
|
||||
KubeconfigFile string `yaml:"kubeconfig_file" env-default:"k8s-admin.conf"`
|
||||
Verbose bool
|
||||
Credentials struct {
|
||||
BaseDir string
|
||||
InventoryDir string
|
||||
Verbose bool
|
||||
KubeconfigFile string
|
||||
InstallationName string `yaml:"installation_name" env-default:"cluster.local"`
|
||||
Credentials struct {
|
||||
User string `yaml:"user"`
|
||||
Password string `yaml:"password"`
|
||||
AskSudoPassword bool `yaml:"ask_sudo_password"`
|
||||
@@ -36,21 +47,37 @@ type Config struct {
|
||||
|
||||
var instance *Config
|
||||
|
||||
func CreateConfig(configPath string, workDir string, password string) *Config {
|
||||
func createConfig(configFile string, out string, password string, verbose bool) *Config {
|
||||
instance = &Config{}
|
||||
instance.WorkDir = workDir
|
||||
|
||||
if err := cleanenv.ReadConfig(configPath, instance); err != nil {
|
||||
if err := cleanenv.ReadConfig(configFile, instance); err != nil {
|
||||
helper, _ := cleanenv.GetDescription(instance, nil)
|
||||
panic(fmt.Sprintf("%s\n%s", helper, err))
|
||||
}
|
||||
|
||||
instance.BaseDir = files.CreateTempDir()
|
||||
instance.InventoryDir = filepath.Join(instance.BaseDir, "inventory")
|
||||
|
||||
files.CreateDirWithAllParents(instance.InventoryDir)
|
||||
|
||||
if out != "" {
|
||||
files.CreateDirWithAllParents(out)
|
||||
instance.KubeconfigFile = filepath.Join(out, "k8s-admin.conf")
|
||||
} else {
|
||||
instance.KubeconfigFile = filepath.Join(files.GetWorkingDir(), "k8s-admin.conf")
|
||||
}
|
||||
|
||||
if password != "" {
|
||||
instance.Credentials.Password = password
|
||||
}
|
||||
|
||||
instance.Verbose = verbose
|
||||
return instance
|
||||
}
|
||||
|
||||
func GetConfig() *Config {
|
||||
if instance == nil {
|
||||
createConfig(ConfigFile, Output, Password, Verbose)
|
||||
}
|
||||
return instance
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
helm_client "github.com/mittwald/go-helm-client"
|
||||
@@ -30,7 +29,7 @@ type ChartSettings struct {
|
||||
|
||||
func GetHelmClient(namespace string) helm_client.Client {
|
||||
config := GetConfig()
|
||||
file, err := os.Open(filepath.Join(config.WorkDir, config.KubeconfigFile))
|
||||
file, err := os.Open(config.KubeconfigFile)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to open file: %s", err)
|
||||
}
|
||||
@@ -46,7 +45,7 @@ func GetHelmClient(namespace string) helm_client.Client {
|
||||
RepositoryConfig: "/tmp/.helmrepo",
|
||||
Debug: true,
|
||||
Linting: true, // Change this to false if you don't want linting.
|
||||
DebugLog: func(format string, v ...interface{}) {
|
||||
DebugLog: func(format string, v ...any) {
|
||||
// Change this to your own logger. Default is 'log.Printf(format, v...)'.
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
)
|
||||
|
||||
var kubernetesConfig *rest.Config
|
||||
|
||||
func GetKubernetesConfig() *rest.Config {
|
||||
appConfig := GetConfig()
|
||||
kubeconfigPath := filepath.Join(appConfig.WorkDir, appConfig.KubeconfigFile)
|
||||
|
||||
kubernetesConfig, err := clientcmd.BuildConfigFromFlags("", kubeconfigPath)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
return kubernetesConfig
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package config
|
||||
|
||||
type Dns struct {
|
||||
Servers []string `yaml:"servers" env-default:"8.8.8.8,8.8.4.4"`
|
||||
DisableHostNameservers bool `yaml:"disable_host_nameservers"`
|
||||
CoreDNSExternalZones []interface{} `yaml:"coredns_external_zones"`
|
||||
Servers []string `yaml:"servers" env-default:"8.8.8.8,8.8.4.4"`
|
||||
DisableHostNameservers bool `yaml:"disable_host_nameservers"`
|
||||
CoreDNSExternalZones []any `yaml:"coredns_external_zones"`
|
||||
}
|
||||
|
||||
type RegistryMirror struct {
|
||||
|
||||
Reference in New Issue
Block a user