Files
zeekay bcbea6fbf4 hack: drop Argo wording, fix stale upstream-fork paths it left behind
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.
2026-09-05 01:11:22 -07:00

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)
}