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

     1  package k8s
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/stretchr/testify/require"
     7  	appsv1 "k8s.io/api/apps/v1"
     8  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     9  
    10  	"github.com/terraform-modules-krish/terratest/modules/testing"
    11  )
    12  
    13  // ListDaemonSets will look for daemonsets in the given namespace that match the given filters and return them. This will
    14  // fail the test if there is an error.
    15  func ListDaemonSets(t testing.TestingT, options *KubectlOptions, filters metav1.ListOptions) []appsv1.DaemonSet {
    16  	daemonset, err := ListDaemonSetsE(t, options, filters)
    17  	require.NoError(t, err)
    18  	return daemonset
    19  }
    20  
    21  // ListDaemonSetsE will look for daemonsets in the given namespace that match the given filters and return them.
    22  func ListDaemonSetsE(t testing.TestingT, options *KubectlOptions, filters metav1.ListOptions) ([]appsv1.DaemonSet, error) {
    23  	clientset, err := GetKubernetesClientFromOptionsE(t, options)
    24  	if err != nil {
    25  		return nil, err
    26  	}
    27  	resp, err := clientset.AppsV1().DaemonSets(options.Namespace).List(context.Background(), filters)
    28  	if err != nil {
    29  		return nil, err
    30  	}
    31  	return resp.Items, nil
    32  }
    33  
    34  // GetDaemonSet returns a Kubernetes daemonset resource in the provided namespace with the given name. This will
    35  // fail the test if there is an error.
    36  func GetDaemonSet(t testing.TestingT, options *KubectlOptions, daemonSetName string) *appsv1.DaemonSet {
    37  	daemonset, err := GetDaemonSetE(t, options, daemonSetName)
    38  	require.NoError(t, err)
    39  	return daemonset
    40  }
    41  
    42  // GetDaemonSetE returns a Kubernetes daemonset resource in the provided namespace with the given name.
    43  func GetDaemonSetE(t testing.TestingT, options *KubectlOptions, daemonSetName string) (*appsv1.DaemonSet, error) {
    44  	clientset, err := GetKubernetesClientFromOptionsE(t, options)
    45  	if err != nil {
    46  		return nil, err
    47  	}
    48  	return clientset.AppsV1().DaemonSets(options.Namespace).Get(context.Background(), daemonSetName, metav1.GetOptions{})
    49  }