-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrawget.go
135 lines (119 loc) · 4.2 KB
/
rawget.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package k8s
import (
"fmt"
"k8s.io/client-go/kubernetes/scheme"
)
// RawAllPods returns all pods in json
func (rc *RawClient) RawAllPods() ([]byte, error) {
p, err := rc.cs.CoreV1().RESTClient().Get().Namespace(rc.ns).Resource("pods").VersionedParams(&rc.listOpts, scheme.ParameterCodec).DoRaw()
return p, err
}
// RawAllNodes returns all nodes in json
func (rc *RawClient) RawAllNodes() ([]byte, error) {
n, err := rc.cs.CoreV1().RESTClient().Get().Resource("nodes").VersionedParams(&rc.listOpts, scheme.ParameterCodec).DoRaw()
return n, err
}
// RawAllSvc returns all services in json
func (rc *RawClient) RawAllSvc() ([]byte, error) {
d, err := rc.cs.CoreV1().RESTClient().Get().Namespace(rc.ns).Resource("services").VersionedParams(&rc.listOpts, scheme.ParameterCodec).DoRaw()
return d, err
}
// RawAllDeployments returns all deployments in json
func (rc *RawClient) RawAllDeployments() ([]byte, error) {
d, err := rc.cs.ExtensionsV1beta1().RESTClient().Get().Namespace(rc.ns).Resource("deployments").VersionedParams(&rc.listOpts, scheme.ParameterCodec).DoRaw()
return d, err
}
// RawAllRS returns all replicasets in json
func (rc *RawClient) RawAllRS() ([]byte, error) {
d, err := rc.cs.ExtensionsV1beta1().RESTClient().Get().Namespace(rc.ns).Resource("replicasets").VersionedParams(&rc.listOpts, scheme.ParameterCodec).DoRaw()
return d, err
}
// RawAllIngress returns all ingresses in json
func (rc *RawClient) RawAllIngress() ([]byte, error) {
d, err := rc.cs.ExtensionsV1beta1().RESTClient().Get().Namespace(rc.ns).Resource("ingresses").VersionedParams(&rc.listOpts, scheme.ParameterCodec).DoRaw()
return d, err
}
// RawAll returns all of a given kind in json
func (rc *RawClient) RawAll(kind string) ([]byte, error) {
var all []byte
var errd error
switch kind {
case "pods":
all, errd = rc.RawAllPods()
if errd != nil {
return all, errd
}
case "nodes":
all, errd = rc.RawAllNodes()
if errd != nil {
return all, errd
}
case "replicasets":
all, errd = rc.RawAllRS()
if errd != nil {
return all, errd
}
case "deployments":
all, errd = rc.RawAllDeployments()
if errd != nil {
return all, errd
}
case "services":
all, errd = rc.RawAllSvc()
if errd != nil {
return all, errd
}
case "ingresses":
all, errd = rc.RawAllIngress()
if errd != nil {
return all, errd
}
default:
return all, fmt.Errorf("No resources found for the given request")
}
return all, nil
}
// RawNodes is a convenience wrapper for SearchFor returning all nodes matching the specified name
func (rc *RawClient) RawNodes(name string) ([]string, error) {
results, err := rc.SearchFor("nodes", name)
return results, err
}
// RawPods is a convenience wrapper for SearchFor returning all pods matching the specified name
func (rc *RawClient) RawPods(name string) ([]string, error) {
results, err := rc.SearchFor("pods", name)
return results, err
}
// RawRS is a convenience wrapper for SearchFor returning all replicasets matching the specified name
func (rc *RawClient) RawRS(name string) ([]string, error) {
results, err := rc.SearchFor("replicasets", name)
return results, err
}
// RawDeployments is a convenience wrapper for SearchFor returning all deployments matching the specified name
func (rc *RawClient) RawDeployments(name string) ([]string, error) {
results, err := rc.SearchFor("deployments", name)
return results, err
}
// RawSvc is a convenience wrapper for SearchFor returning all services matching the specified name
func (rc *RawClient) RawSvc(name string) ([]string, error) {
results, err := rc.SearchFor("services", name)
return results, err
}
// RawIngress is a convenience wrapper for SearchFor returning all ingresses matching the specified name
func (rc *RawClient) RawIngress(name string) ([]string, error) {
results, err := rc.SearchFor("ingresses", name)
return results, err
}
// SearchFor returns resources matching the kind and name specified as an array containing json of each result
func (rc *RawClient) SearchFor(kind, name string) ([]string, error) {
var jsonArray []string
all, err := rc.RawAll(kind)
if err != nil {
return jsonArray, err
}
if rc.exactMatches {
jsonArray = parseExact(all, name)
return jsonArray, nil
}
jsonArray = parseFor(all, name)
return jsonArray, nil
}