|
| 1 | +// Copyright 2015 Google Inc. All Rights Reserved. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package node |
| 16 | + |
| 17 | +import ( |
| 18 | + "log" |
| 19 | + |
| 20 | + "github.com/kubernetes/dashboard/client" |
| 21 | + "github.com/kubernetes/dashboard/resource/common" |
| 22 | + "k8s.io/kubernetes/pkg/api" |
| 23 | + k8sClient "k8s.io/kubernetes/pkg/client/unversioned" |
| 24 | +) |
| 25 | + |
| 26 | +// NodeDetail is a presentation layer view of Kubernetes Node resource. This means it is Node plus |
| 27 | +// additional augmented data we can get from other sources. |
| 28 | +type NodeDetail struct { |
| 29 | + ObjectMeta common.ObjectMeta `json:"objectMeta"` |
| 30 | + TypeMeta common.TypeMeta `json:"typeMeta"` |
| 31 | + |
| 32 | + // Container images of the Node. |
| 33 | + ContainerImages []string `json:"containerImages"` |
| 34 | + |
| 35 | + // External ID of the node assigned by some machine database (e.g. a cloud provider). |
| 36 | + ExternalID string `json:"externalID"` |
| 37 | + |
| 38 | + // PodCIDR represents the pod IP range assigned to the node. |
| 39 | + PodCIDR string `json:"podCIDR"` |
| 40 | + |
| 41 | + // ID of the node assigned by the cloud provider. |
| 42 | + ProviderID string `json:"providerID"` |
| 43 | + |
| 44 | + // Unschedulable controls node schedulability of new pods. By default node is schedulable. |
| 45 | + Unschedulable bool `json:"unschedulable"` |
| 46 | + |
| 47 | + // Set of ids/uuids to uniquely identify the node. |
| 48 | + NodeInfo api.NodeSystemInfo `json:"nodeInfo"` |
| 49 | + |
| 50 | + // CPU limit specified (core number). |
| 51 | + CPUCapacity int64 `json:"cpuCapacity"` |
| 52 | + |
| 53 | + // Memory limit specified (bytes). |
| 54 | + MemoryCapacity int64 `json:"memoryCapacity"` |
| 55 | +} |
| 56 | + |
| 57 | +// GetNodeDetail gets node details. |
| 58 | +func GetNodeDetail(client k8sClient.Interface, heapsterClient client.HeapsterClient, name string) ( |
| 59 | + *NodeDetail, error) { |
| 60 | + log.Printf("Getting details of %s node", name) |
| 61 | + |
| 62 | + node, err := client.Nodes().Get(name) |
| 63 | + if err != nil { |
| 64 | + return nil, err |
| 65 | + } |
| 66 | + |
| 67 | + nodeDetails := toNodeDetail(*node) |
| 68 | + return &nodeDetails, nil |
| 69 | +} |
| 70 | + |
| 71 | +func toNodeDetail(node api.Node) NodeDetail { |
| 72 | + cpuCapacity, _ := node.Status.Capacity.Cpu().AsInt64() |
| 73 | + memoryCapacity, _ := node.Status.Capacity.Memory().AsInt64() |
| 74 | + |
| 75 | + return NodeDetail{ |
| 76 | + ObjectMeta: common.NewObjectMeta(node.ObjectMeta), |
| 77 | + TypeMeta: common.NewTypeMeta(common.ResourceKindNode), |
| 78 | + ContainerImages: getContainerImages(node), |
| 79 | + ExternalID: node.Spec.ExternalID, |
| 80 | + ProviderID: node.Spec.ProviderID, |
| 81 | + PodCIDR: node.Spec.PodCIDR, |
| 82 | + Unschedulable: node.Spec.Unschedulable, |
| 83 | + NodeInfo: node.Status.NodeInfo, |
| 84 | + CPUCapacity: cpuCapacity, |
| 85 | + MemoryCapacity: memoryCapacity, |
| 86 | + } |
| 87 | +} |
0 commit comments