/
configmap.go
93 lines (86 loc) · 2.23 KB
/
configmap.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
package client
import (
"github.com/containerum/kube-client/pkg/model"
"github.com/containerum/kube-client/pkg/rest"
)
const (
configMapsPath = "/projects/{project}/namespaces/{namespace}/configmaps"
configMapPath = "/projects/{project}/namespaces/{namespace}/configmaps/{configmap}"
)
// CreateConfigMap -- creates a ConfigMap in provided namespace.
func (client *Client) CreateConfigMap(project, namespace, name string, data model.ConfigMapData) error {
return client.RestAPI.Post(rest.Rq{
URL: rest.URL{
Path: configMapsPath,
Params: rest.P{
"namespace": namespace,
"project": project,
},
},
Body: model.ConfigMap{
Name: name,
Data: data,
},
})
}
// GetConfigMap -- retrieves ConfigMap by name from provided namespace.
func (client *Client) GetConfigMap(project, namespace, name string) (ret model.ConfigMap, err error) {
err = client.RestAPI.Get(rest.Rq{
Result: &ret,
URL: rest.URL{
Path: configMapPath,
Params: rest.P{
"namespace": namespace,
"configmap": name,
"project": project,
},
},
})
return
}
// GetConfigMapList -- returns all ConfigMap`s in namespace.
func (client *Client) GetConfigMapList(project, namespace string) (ret []model.ConfigMap, err error) {
jsonAdaptor := struct {
ConfigMaps *[]model.ConfigMap `json:"configmaps"`
}{&ret}
err = client.RestAPI.Get(rest.Rq{
Result: &jsonAdaptor,
URL: rest.URL{
Path: configMapsPath,
Params: rest.P{
"namespace": namespace,
"project": project,
},
},
})
return
}
// UpdateConfigMap -- rewrites ConfigMap by name in provided namespace.
func (client *Client) UpdateConfigMap(project, namespace, name string, data model.ConfigMapData) error {
return client.RestAPI.Put(rest.Rq{
URL: rest.URL{
Path: configMapPath,
Params: rest.P{
"namespace": namespace,
"configmap": name,
"project": project,
},
},
Body: model.ConfigMap{
Data: data,
},
})
}
// DeleteConfigMap -- deletes ConfigMap by name in provided namespace
func (client *Client) DeleteConfigMap(project, namespace, name string) error {
return client.RestAPI.Delete(rest.Rq{
URL: rest.URL{
Path: configMapPath,
Params: rest.P{
"namespace": namespace,
"configmap": name,
"project": project,
},
},
})
}