-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
48 lines (41 loc) · 1.04 KB
/
main.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
40
41
42
43
44
45
46
47
48
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"os/signal"
"syscall"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)
func main() {
var namespace string
flag.StringVar(&namespace, "namespace", "", "kubernetes namespace for secret")
var secretName string
flag.StringVar(&secretName, "secret", "", "kubernetes secret name")
flag.Parse()
fmt.Printf("reading secret '%s' in namespace '%s'\n", secretName, namespace)
config, err := rest.InClusterConfig()
if err != nil {
log.Fatal(err)
}
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
log.Fatal(err)
}
secret, err := clientset.CoreV1().Secrets(namespace).Get(context.Background(), secretName, metav1.GetOptions{})
if err != nil {
panic(err)
}
log.Println("kubernetes secret Data field")
for key := range secret.Data {
log.Printf("%s = %s\n", key, "****")
}
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
sig := <-sigs
log.Printf("Exiting due to %v", sig)
}