-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.go
34 lines (29 loc) · 1.13 KB
/
node.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
package node
import (
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/rancher/types/client/management/v3"
)
// Formatter for Node
func Formatter(apiContext *types.APIContext, resource *types.RawResource) {
etcd := convert.ToBool(resource.Values[client.NodeFieldEtcd])
cp := convert.ToBool(resource.Values[client.NodeFieldControlPlane])
worker := convert.ToBool(resource.Values[client.NodeFieldWorker])
if !etcd && !cp && !worker {
resource.Values[client.NodeFieldWorker] = true
}
// add nodeConfig link
if err := apiContext.AccessControl.CanDo(v3.NodeDriverGroupVersionKind.Group, v3.NodeDriverResource.Name, "update", apiContext, resource.Values, apiContext.Schema); err == nil {
resource.Links["nodeConfig"] = apiContext.URLBuilder.Link("nodeConfig", resource)
}
// remove link
nodeTemplateID := resource.Values["nodeTemplateId"]
customConfig := resource.Values["customConfig"]
if nodeTemplateID == nil {
delete(resource.Links, "nodeConfig")
}
if nodeTemplateID == nil && customConfig == nil {
delete(resource.Links, "remove")
}
}