forked from viliproject/vili
-
Notifications
You must be signed in to change notification settings - Fork 0
/
namespaces.go
85 lines (77 loc) · 2.02 KB
/
namespaces.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
package kube
import (
"bytes"
"encoding/json"
"net/url"
"github.com/airware/vili/kube/unversioned"
"github.com/airware/vili/kube/v1"
)
// Namespaces is the default namespaces service instance
var Namespaces = &NamespacesService{}
// NamespacesService is the kubernetes service to interace with namespaces
type NamespacesService struct {
}
// List fetches the list of namespaces
func (s *NamespacesService) List(query *url.Values) (*v1.NamespaceList, *unversioned.Status, error) {
client, err := getDefaultClient()
if err != nil {
return nil, nil, err
}
resp := &v1.NamespaceList{}
path := "namespaces"
if query != nil {
path += "?" + query.Encode()
}
status, err := client.makeRequest("GET", path, nil, resp)
if status != nil || err != nil {
return nil, status, err
}
return resp, nil, nil
}
// Get fetches the namespace with `name`
func (s *NamespacesService) Get(name string) (*v1.Namespace, *unversioned.Status, error) {
client, err := getDefaultClient()
if err != nil {
return nil, nil, err
}
resp := &v1.Namespace{}
status, err := client.makeRequest("GET", "namespaces/"+name, nil, resp)
if status != nil || err != nil {
return nil, status, err
}
return resp, nil, nil
}
// Create creates a namespace
func (s *NamespacesService) Create(data *v1.Namespace) (*v1.Namespace, *unversioned.Status, error) {
client, err := getDefaultClient()
if err != nil {
return nil, nil, err
}
dataBytes, err := json.Marshal(data)
if err != nil {
return nil, nil, err
}
resp := &v1.Namespace{}
status, err := client.makeRequest(
"POST",
"namespaces",
bytes.NewReader(dataBytes),
resp,
)
if status != nil || err != nil {
return nil, status, err
}
return resp, nil, nil
}
// Delete deletes the namespace with `name`
func (s *NamespacesService) Delete(name string) (*unversioned.Status, error) {
client, err := getDefaultClient()
if err != nil {
return nil, err
}
status, err := client.makeRequest("DELETE", "namespaces/"+name, nil, nil)
if status != nil || err != nil {
return status, err
}
return nil, nil
}