...
1 package kclient
2
3 import (
4 "context"
5 "fmt"
6
7 corev1 "k8s.io/api/core/v1"
8 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9 )
10
11
12 func (c *Client) ListConfigMaps(labelSelector string) ([]corev1.ConfigMap, error) {
13 listOptions := metav1.ListOptions{}
14 if len(labelSelector) > 0 {
15 listOptions = metav1.ListOptions{
16 LabelSelector: labelSelector,
17 }
18 }
19
20 cmList, err := c.KubeClient.CoreV1().ConfigMaps(c.Namespace).List(context.TODO(), listOptions)
21 if err != nil {
22 return nil, fmt.Errorf("unable to get configmap list: %w", err)
23 }
24
25 return cmList.Items, nil
26 }
27
View as plain text