-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathk8s.go
54 lines (42 loc) · 1.27 KB
/
k8s.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
49
50
51
52
53
54
package kunsul
import (
"k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
log "github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
_ "k8s.io/client-go/plugin/pkg/client/auth"
)
func GetIngresses(config *rest.Config) ([]v1beta1.Ingress, error) {
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
return nil, err
}
ingressList, err := clientset.ExtensionsV1beta1().Ingresses("").List(metav1.ListOptions{})
if err != nil {
return nil, err
}
ingressCtrls := ingressList.Items
log.Debugf("DISCOVERED INGRESSES:> there are %s ingresses in the cluster", len(ingressCtrls))
for k, v := range ingressCtrls {
log.Debugf("INGRESS %s:> %s", k, v)
}
return ingressCtrls, nil
}
func GetServices(config *rest.Config) ([]v1.Service, error) {
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
return nil, err
}
servicesList, err := clientset.CoreV1().Services("").List(metav1.ListOptions{})
if err != nil {
return nil, err
}
serviceCtrls := servicesList.Items
log.Debugf("DISCOVERED Services:> there are %s services in the cluster", len(serviceCtrls))
for k, v := range serviceCtrls {
log.Debugf("SERVICE %s:> %s", k, v)
}
return serviceCtrls, nil
}