Create Kubernetes clients from bytes instead of filepath (#2663)

Signed-off-by: Daniel Weiße <dw@edgeless.systems>
This commit is contained in:
Daniel Weiße 2023-12-01 09:00:44 +01:00 committed by GitHub
parent 4d6a7fa759
commit a9cc9d8bbc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 94 additions and 33 deletions

View file

@ -48,14 +48,10 @@ func NewUninitialized() *Kubectl {
}
// NewFromConfig returns a Kubectl client using the given kubeconfig.
func NewFromConfig(kubeconfigPath string) (*Kubectl, error) {
clientConfig, err := clientcmd.BuildConfigFromFlags("", kubeconfigPath)
if err != nil {
return nil, fmt.Errorf("creating k8s client from kubeconfig: %w", err)
}
k := &Kubectl{}
if err := k.initialize(clientConfig); err != nil {
return nil, fmt.Errorf("initializing kubectl: %w", err)
func NewFromConfig(kubeconfig []byte) (*Kubectl, error) {
k := NewUninitialized()
if err := k.Initialize(kubeconfig); err != nil {
return nil, err
}
return k, nil
}