forked from rancher/types
/
schema.go
78 lines (71 loc) · 2.2 KB
/
schema.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
package schema
import (
"github.com/rancher/norman/types"
m "github.com/rancher/norman/types/mapper"
"github.com/rancher/types/apis/project.cattle.io/v3"
"github.com/rancher/types/apis/project.cattle.io/v3/schema"
"github.com/rancher/types/factory"
"github.com/rancher/types/mapper"
"k8s.io/api/core/v1"
)
var (
Version = types.APIVersion{
Version: "v3",
Group: "cluster.cattle.io",
Path: "/v3/clusters",
}
Schemas = factory.Schemas(&Version).
Init(namespaceTypes).
Init(nodeTypes).
Init(volumeTypes)
)
func namespaceTypes(schemas *types.Schemas) *types.Schemas {
return schema.NamespaceTypes(&Version, schemas)
}
func nodeTypes(schemas *types.Schemas) *types.Schemas {
return NodeTypes(&Version, schemas)
}
func NodeTypes(version *types.APIVersion, schemas *types.Schemas) *types.Schemas {
return schemas.
AddMapperForType(version, v1.NodeStatus{},
&mapper.NodeAddressMapper{},
&mapper.OSInfo{},
&m.Drop{Field: "addresses"},
&m.Drop{Field: "daemonEndpoints"},
&m.Drop{Field: "images"},
&m.Drop{Field: "nodeInfo"},
&m.Move{From: "conditions", To: "nodeConditions"},
&m.Drop{Field: "phase"},
&m.SliceToMap{Field: "volumesAttached", Key: "devicePath"},
).
AddMapperForType(version, v1.NodeSpec{},
&m.Drop{Field: "externalID"},
&m.Drop{Field: "configSource"},
&m.Move{From: "providerID", To: "providerId"},
&m.Move{From: "podCIDR", To: "podCidr"},
m.Access{Fields: map[string]string{
"podCidr": "r",
"providerId": "r",
"taints": "ru",
"unschedulable": "ru",
}}).
AddMapperForType(version, v1.Node{},
&m.AnnotationField{Field: "description"},
&m.AnnotationField{Field: "publicEndpoints", List: true},
&m.Embed{Field: "status"},
).
MustImport(version, v1.NodeStatus{}, struct {
IPAddress string
Hostname string
Info NodeInfo
}{}).
MustImport(version, v3.PublicEndpoint{}).
MustImport(version, v1.Node{}, struct {
Description string `json:"description"`
PublicEndpoints string `json:"publicEndpoints" norman:"type=array[publicEndpoint],nocreate,noupdate"`
}{})
}
func volumeTypes(schemas *types.Schemas) *types.Schemas {
return schemas.
MustImport(&Version, v1.PersistentVolume{})
}