-
Notifications
You must be signed in to change notification settings - Fork 0
/
listSecret.go
39 lines (35 loc) · 892 Bytes
/
listSecret.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"context"
"fmt"
"log"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)
func main() {
config := &rest.Config{
Host: "YOUR-HOST",
}
config.BearerToken = "YOUR-TOKEN"
config.Insecure = true
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
panic(err.Error())
}
secrets, err := clientset.CoreV1().Secrets("").List(context.TODO(), metav1.ListOptions{})
if err != nil {
log.Fatalf("Failed to list secrets: %v", err)
}
fmt.Println("Secrets:")
for _, secret := range secrets.Items {
fmt.Printf("Name: %s\n", secret.Name)
fmt.Printf("Namespace: %s\n", secret.Namespace)
fmt.Println("Data:")
for key := range secret.Data {
fmt.Printf("- %s: %s\n", key, string(secret.Data[key]))
}
fmt.Println("-----")
}
fmt.Println("-----")
}