Files

43 lines
1.2 KiB
Go
Raw Permalink Normal View History

2026-08-17 10:14:44 -07:00
package cli
import (
"fmt"
"os"
"path/filepath"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/tools/clientcmd"
)
// queueGVR identifies the Queue CRD (kmsvc.io/v1, plural "queues") that the
// queue-operator reconciles -- the declarative source of truth for queues,
// not something management-service's gRPC API manages (design.md §2a).
var queueGVR = schema.GroupVersionResource{Group: "kmsvc.io", Version: "v1", Resource: "queues"}
// newDynamicClient builds a k8s dynamic client from the default kubeconfig
// (KUBECONFIG env var, falling back to ~/.kube/config), the same resolution
// kubectl itself uses.
func newDynamicClient() (dynamic.Interface, error) {
path, err := kubeconfigPath()
if err != nil {
return nil, err
}
cfg, err := clientcmd.BuildConfigFromFlags("", path)
if err != nil {
return nil, fmt.Errorf("load kubeconfig %s: %w", path, err)
}
return dynamic.NewForConfig(cfg)
}
func kubeconfigPath() (string, error) {
if v := os.Getenv("KUBECONFIG"); v != "" {
return v, nil
}
home, err := os.UserHomeDir()
if err != nil {
return "", err
}
return filepath.Join(home, ".kube", "config"), nil
}