-
Notifications
You must be signed in to change notification settings - Fork 43
/
namespace.go
44 lines (38 loc) · 1.07 KB
/
namespace.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
package api
import (
"github.com/baetyl/baetyl-go/v2/log"
"github.com/baetyl/baetyl-cloud/v2/common"
"github.com/baetyl/baetyl-cloud/v2/models"
)
// CreateNamespace create one namespace
func (api *API) CreateNamespace(c *common.Context) (interface{}, error) {
ns, err := api.NS.Create(&models.Namespace{
Name: c.GetNamespace(),
})
if err != nil {
return ns, err
}
if e := api.InitQuotas(ns.Name); e != nil {
log.L().Error("InitQuotas error", log.Error(e))
}
return ns, nil
}
// GetNamespace get one namespace
func (api *API) GetNamespace(c *common.Context) (interface{}, error) {
res, err := api.NS.Get(c.GetNamespace())
if res == nil {
return nil, common.Error(common.ErrResourceNotFound,
common.Field("type", "namespace"),
common.Field("name", c.GetNamespace()))
}
return res, err
}
func (api *API) DeleteNamespace(c *common.Context) (interface{}, error) {
ns := c.GetNamespace()
_, err := api.NS.Get(ns)
if err != nil {
return nil, err
}
_, err = api.Task.AddTaskWithKey("DeleteNamespaceTask", map[string]interface{}{"ns": ns})
return nil, err
}