From 5579f880d0e4d2c10d2ea96c3ce67ad625fcd0b8 Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Tue, 5 Dec 2017 09:29:49 -0700 Subject: [PATCH] Combine ClusterNode and Machine --- apis/cluster.cattle.io/v3/schema/schema.go | 2 + apis/management.cattle.io/v3/machine_types.go | 23 +++++------- apis/management.cattle.io/v3/schema/schema.go | 37 ++++++++++++++++++- apis/management.cattle.io/v3/schema/types.go | 27 ++++++++++++++ 4 files changed, 75 insertions(+), 14 deletions(-) create mode 100644 apis/management.cattle.io/v3/schema/types.go diff --git a/apis/cluster.cattle.io/v3/schema/schema.go b/apis/cluster.cattle.io/v3/schema/schema.go index 8ce0dfe0..3646f5dd 100644 --- a/apis/cluster.cattle.io/v3/schema/schema.go +++ b/apis/cluster.cattle.io/v3/schema/schema.go @@ -30,6 +30,8 @@ func nodeTypes(schemas *types.Schemas) *types.Schemas { &m.Drop{Field: "nodeInfo"}, &m.SliceToMap{Field: "volumesAttached", Key: "devicePath"}, ). + AddMapperForType(&Version, v1.NodeSpec{}, + &m.Move{From: "externalID", To: "externalId"}). AddMapperForType(&Version, v1.Node{}, &m.Embed{Field: "status"}, &m.Drop{Field: "conditions"}, diff --git a/apis/management.cattle.io/v3/machine_types.go b/apis/management.cattle.io/v3/machine_types.go index eac1574e..c68d22da 100644 --- a/apis/management.cattle.io/v3/machine_types.go +++ b/apis/management.cattle.io/v3/machine_types.go @@ -59,12 +59,11 @@ type Machine struct { } type MachineStatus struct { - Conditions []MachineCondition `json:"conditions"` - Node v1.Node `json:"node"` - NodeName string `json:"nodeName"` - ClusterName string `json:"clusterName" norman:"reference[cluster]"` - Requested v1.ResourceList `json:"requested,omitempty"` - Limits v1.ResourceList `json:"limits,omitempty"` + Conditions []MachineCondition `json:"conditions"` + NodeStatus v1.NodeStatus `json:"nodeStatus"` + NodeName string `json:"nodeName"` + Requested v1.ResourceList `json:"requested,omitempty"` + Limits v1.ResourceList `json:"limits,omitempty"` } type MachineCondition struct { @@ -81,13 +80,11 @@ type MachineCondition struct { } type MachineSpec struct { - ClusterName string `norman:"type=reference[cluster]"` - ExternalID string `json:"externalId"` - MachineTemplateName string `norman:"type=reference[machineTemplate]"` - DisplayName string `json:"displayName"` - Description string `json:"description"` - Hostname string `json:"hostname"` - Driver string `json:"driver"` + NodeSpec v1.NodeSpec `json:"nodeSpec"` + ClusterName string `json:"clusterName" norman:"type=reference[cluster]"` + MachineTemplateName string `json:"machineTemplateName" norman:"type=reference[machineTemplate]"` + Description string `json:"description"` + Driver string `json:"driver"` MachineCommonParams `json:",inline"` AmazonEC2Config AmazonEC2Config `json:"amazonEc2Config"` diff --git a/apis/management.cattle.io/v3/schema/schema.go b/apis/management.cattle.io/v3/schema/schema.go index 39e7d625..e02ffe8b 100644 --- a/apis/management.cattle.io/v3/schema/schema.go +++ b/apis/management.cattle.io/v3/schema/schema.go @@ -5,6 +5,8 @@ import ( m "github.com/rancher/norman/types/mapper" "github.com/rancher/types/apis/management.cattle.io/v3" "github.com/rancher/types/factory" + "github.com/rancher/types/mapper" + "k8s.io/api/core/v1" ) var ( @@ -15,11 +17,37 @@ var ( } Schemas = factory.Schemas(&Version). + Init(nodeTypes). Init(machineTypes). Init(authTypes). Init(clusterTypes) ) +func nodeTypes(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.SliceToMap{Field: "volumesAttached", Key: "devicePath"}, + ). + AddMapperForType(&Version, v1.NodeSpec{}, + &m.Move{From: "externalID", To: "externalId"}). + AddMapperForType(&Version, v1.Node{}, + &m.Embed{Field: "status"}, + &m.Drop{Field: "conditions"}, + ). + MustImport(&Version, v1.NodeStatus{}, struct { + IPAddress string + Hostname string + Info NodeInfo + }{}). + MustImport(&Version, v1.Node{}) +} + func clusterTypes(schemas *types.Schemas) *types.Schemas { return schemas. AddMapperForType(&Version, v3.Cluster{}, @@ -62,7 +90,14 @@ func authTypes(schemas *types.Schemas) *types.Schemas { func machineTypes(schemas *types.Schemas) *types.Schemas { return schemas. - AddMapperForType(&Version, v3.Machine{}, m.DisplayName{}). + AddMapperForType(&Version, v3.MachineSpec{}, &m.Embed{Field: "nodeSpec"}). + AddMapperForType(&Version, v3.MachineStatus{}, + &m.Drop{Field: "conditions"}, + &m.Embed{Field: "nodeStatus"}). + AddMapperForType(&Version, v3.Machine{}, + &m.Embed{Field: "status"}, + &m.Move{From: "name", To: "id"}, + &m.Move{From: "nodeName", To: "name"}). AddMapperForType(&Version, v3.MachineDriver{}, m.DisplayName{}). AddMapperForType(&Version, v3.MachineTemplate{}, m.DisplayName{}). MustImport(&Version, v3.Machine{}). diff --git a/apis/management.cattle.io/v3/schema/types.go b/apis/management.cattle.io/v3/schema/types.go new file mode 100644 index 00000000..d0a14ccf --- /dev/null +++ b/apis/management.cattle.io/v3/schema/types.go @@ -0,0 +1,27 @@ +package schema + +type NodeInfo struct { + CPU CPUInfo + Memory MemoryInfo + OS OSInfo + Kubernetes KubernetesInfo +} + +type CPUInfo struct { + Count int64 +} + +type MemoryInfo struct { + MemTotalKiB int64 +} + +type OSInfo struct { + DockerVersion string + KernelVersion string + OperatingSystem string +} + +type KubernetesInfo struct { + KubeletVersion string + KubeProxyVersion string +}