mirror of
https://github.com/hanzoai/cd.git
synced 2026-10-30 14:56:45 +00:00
Renames local identifiers (argoClientSet/argoDB/argoappv1 etc.) and comments to our own voice. Also fixes real bugs the old wording was masking: update-manifests.sh's image detection still compared against quay.io/argoproj/argocd so it never matched our ghcr.io/hanzoai/cd image; the codegen scripts pointed GOPATH at the upstream import path; start-redis-with-password.sh grepped a manifest filename that no longer exists; generate-actions-list.sh linked generated docs at our own repo now instead of upstream's file layout.
61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
package util
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"os/user"
|
|
"path"
|
|
|
|
"k8s.io/client-go/rest"
|
|
|
|
"k8s.io/client-go/kubernetes"
|
|
"k8s.io/client-go/tools/clientcmd"
|
|
|
|
appclientset "github.com/hanzoai/cd/pkg/client/clientset/versioned"
|
|
)
|
|
|
|
type Kube struct {
|
|
Namespace string
|
|
Context string
|
|
}
|
|
|
|
func getDefaultKubeConfigPath(homeDir string) string {
|
|
return path.Join(homeDir, ".kube", "config")
|
|
}
|
|
|
|
func getKubeConfigPath() string {
|
|
var kubeConfigPath string
|
|
currentUser, _ := user.Current()
|
|
if currentUser != nil {
|
|
kubeConfigPath = os.Getenv("KUBECONFIG")
|
|
if kubeConfigPath == "" {
|
|
kubeConfigPath = getDefaultKubeConfigPath(currentUser.HomeDir)
|
|
}
|
|
}
|
|
return kubeConfigPath
|
|
}
|
|
|
|
func ConnectToK8sAppClientSet() *appclientset.Clientset {
|
|
config, err := clientcmd.BuildConfigFromFlags("", getKubeConfigPath())
|
|
if err != nil {
|
|
log.Panicln("failed to create K8s config")
|
|
}
|
|
return appclientset.NewForConfigOrDie(config)
|
|
}
|
|
|
|
func ConnectToK8sConfig() *rest.Config {
|
|
config, err := clientcmd.BuildConfigFromFlags("", getKubeConfigPath())
|
|
if err != nil {
|
|
log.Panicln("failed to create K8s config")
|
|
}
|
|
return config
|
|
}
|
|
|
|
func ConnectToK8sClientSet() *kubernetes.Clientset {
|
|
config, err := clientcmd.BuildConfigFromFlags("", getKubeConfigPath())
|
|
if err != nil {
|
|
log.Panicln("failed to create K8s config")
|
|
}
|
|
return kubernetes.NewForConfigOrDie(config)
|
|
}
|