github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/internal/utils/clientgo/secret.go (about)

     1  package clientgo
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/caos/orbos/mntr"
     8  	v1 "k8s.io/api/core/v1"
     9  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    10  )
    11  
    12  func GetSecret(name, namespace string) (*v1.Secret, error) {
    13  	conf, err := GetClusterConfig(mntr.Monitor{}, "")
    14  	if err != nil {
    15  		return nil, err
    16  	}
    17  
    18  	clientset, err := getClientSet(conf)
    19  	if err != nil {
    20  		return nil, err
    21  	}
    22  
    23  	secret, err := clientset.CoreV1().Secrets(namespace).Get(context.Background(), name, metav1.GetOptions{})
    24  	if err != nil {
    25  		return nil, err
    26  	}
    27  	if secret == nil {
    28  		return nil, fmt.Errorf("secret %s not found in namespace %s", name, namespace)
    29  	}
    30  
    31  	return secret, nil
    32  }