github.com/terraform-modules-krish/terratest@v0.29.0/modules/k8s/secret.go (about)

     1  package k8s
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/terraform-modules-krish/terratest/modules/testing"
     7  	"github.com/stretchr/testify/require"
     8  	corev1 "k8s.io/api/core/v1"
     9  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    10  )
    11  
    12  // GetSecret returns a Kubernetes secret resource in the provided namespace with the given name. The namespace used
    13  // is the one provided in the KubectlOptions. This will fail the test if there is an error.
    14  func GetSecret(t testing.TestingT, options *KubectlOptions, secretName string) *corev1.Secret {
    15  	secret, err := GetSecretE(t, options, secretName)
    16  	require.NoError(t, err)
    17  	return secret
    18  }
    19  
    20  // GetSecretE returns a Kubernetes secret resource in the provided namespace with the given name. The namespace used
    21  // is the one provided in the KubectlOptions.
    22  func GetSecretE(t testing.TestingT, options *KubectlOptions, secretName string) (*corev1.Secret, error) {
    23  	clientset, err := GetKubernetesClientFromOptionsE(t, options)
    24  	if err != nil {
    25  		return nil, err
    26  	}
    27  	return clientset.CoreV1().Secrets(options.Namespace).Get(context.Background(), secretName, metav1.GetOptions{})
    28  }