我想在kubernetes節點的信息中添加位置信息,並讓kubectl命令「describe節點」打印出節點的位置。但是,我無法打印出位置的值。 輸出看起來像圖像。 output of current code 我做錯了什麼,或者我應該怎麼做,但我錯過了? 任何幫助將是非常讚賞在kubernetes節點信息中添加位置,並讓kubectl將其打印出
我已經在kubernetes增加了新的變數
Location string `json:"location"`
/供應商/ github.com /谷歌/ cadvisor /信息/ V1/machine.go
和修改設置並傳遞Location的值的相應文件。
我也/home/william/kubernetes/pkg/api/types.go
和
Location string `json:"location" protobuf:"bytes,2,opt,name=location"`
在/ home /威廉/ kubernetes
增添了新的變數
Location string `json:"location"`
/pkg/api/v1/types.go
我加了
out.Location = in.Location
在功能autoConvert_v1_NodeSystemInfo_To_api_NodeSystemInfo在/home/william/kubernetes/pkg/api/v1/zz_generated.conversion.go
func autoConvert_v1_NodeSystemInfo_To_api_NodeSystemInfo(in *NodeSystemInfo, out *api.NodeSystemInfo, s conversion.Scope) error {
out.MachineID = in.MachineID
out.SystemUUID = in.SystemUUID
out.Location = in.Location
out.BootID = in.BootID
out.KernelVersion = in.KernelVersion
out.OSImage = in.OSImage
out.ContainerRuntimeVersion = in.ContainerRuntimeVersion
out.KubeletVersion = in.KubeletVersion
out.KubeProxyVersion = in.KubeProxyVersion
out.OperatingSystem = in.OperatingSystem
out.Architecture = in.Architecture
return nil
}
,並添加
fmt.Fprintf(out, " Location:\t%s\n", node.Status.NodeInfo.Location)
在功能describeNode /家/ william/kubernetes/pkg/kubectl/describe.go
func describeNode(node *api.Node, nodeNonTerminatedPodsList *api.PodList, events *api.EventList, canViewPods bool) (string, error) {
return tabbedString(func(out io.Writer) error {
fmt.Fprintf(out, "Name:\t%s\n", node.Name)
fmt.Fprintf(out, "Role:\t%s\n", findNodeRole(node))
printLabelsMultiline(out, "Labels", node.Labels)
printTaintsInAnnotationMultiline(out, "Taints", node.Annotations)
fmt.Fprintf(out, "CreationTimestamp:\t%s\n", node.CreationTimestamp.Time.Format(time.RFC1123Z))
fmt.Fprintf(out, "Phase:\t%v\n", node.Status.Phase)
if len(node.Status.Conditions) > 0 {
fmt.Fprint(out, "Conditions:\n Type\tStatus\tLastHeartbeatTime\tLastTransitionTime\tReason\tMessage\n")
fmt.Fprint(out, " ----\t------\t-----------------\t------------------\t------\t-------\n")
for _, c := range node.Status.Conditions {
fmt.Fprintf(out, " %v \t%v \t%s \t%s \t%v \t%v\n",
c.Type,
c.Status,
c.LastHeartbeatTime.Time.Format(time.RFC1123Z),
c.LastTransitionTime.Time.Format(time.RFC1123Z),
c.Reason,
c.Message)
}
}
addresses := make([]string, 0, len(node.Status.Addresses))
for _, address := range node.Status.Addresses {
addresses = append(addresses, address.Address)
}
printResourceList := func(resourceList api.ResourceList) {
resources := make([]api.ResourceName, 0, len(resourceList))
for resource := range resourceList {
resources = append(resources, resource)
}
sort.Sort(SortableResourceNames(resources))
for _, resource := range resources {
value := resourceList[resource]
fmt.Fprintf(out, " %s:\t%s\n", resource, value.String())
}
}
fmt.Fprintf(out, "Addresses:\t%s\n", strings.Join(addresses, ","))
if len(node.Status.Capacity) > 0 {
fmt.Fprintf(out, "Capacity:\n")
printResourceList(node.Status.Capacity)
}
if len(node.Status.Allocatable) > 0 {
fmt.Fprintf(out, "Allocatable:\n")
printResourceList(node.Status.Allocatable)
}
fmt.Fprintf(out, "System Info:\n")
fmt.Fprintf(out, " Machine ID:\t%s\n", node.Status.NodeInfo.MachineID)
fmt.Fprintf(out, " System UUID:\t%s\n", node.Status.NodeInfo.SystemUUID)
fmt.Fprintf(out, " Location:\t%s\n", node.Status.NodeInfo.Location)
fmt.Fprintf(out, " Boot ID:\t%s\n", node.Status.NodeInfo.BootID)
fmt.Fprintf(out, " Kernel Version:\t%s\n", node.Status.NodeInfo.KernelVersion)
fmt.Fprintf(out, " OS Image:\t%s\n", node.Status.NodeInfo.OSImage)
fmt.Fprintf(out, " Operating System:\t%s\n", node.Status.NodeInfo.OperatingSystem)
fmt.Fprintf(out, " Architecture:\t%s\n", node.Status.NodeInfo.Architecture)
fmt.Fprintf(out, " Container Runtime Version:\t%s\n", node.Status.NodeInfo.ContainerRuntimeVersion)
fmt.Fprintf(out, " Kubelet Version:\t%s\n", node.Status.NodeInfo.KubeletVersion)
fmt.Fprintf(out, " Kube-Proxy Version:\t%s\n", node.Status.NodeInfo.KubeProxyVersion)
if len(node.Spec.PodCIDR) > 0 {
fmt.Fprintf(out, "PodCIDR:\t%s\n", node.Spec.PodCIDR)
}
if len(node.Spec.ExternalID) > 0 {
fmt.Fprintf(out, "ExternalID:\t%s\n", node.Spec.ExternalID)
}
if canViewPods && nodeNonTerminatedPodsList != nil {
if err := describeNodeResource(nodeNonTerminatedPodsList, node, out); err != nil {
return err
}
} else {
fmt.Fprintf(out, "Pods:\tnot authorized\n")
}
if events != nil {
DescribeEvents(events, out)
}
return nil
})
}
也許這不是您希望的答案,但爲何不只是添加標籤'位置= x'並使用'kubectl get node -L location'? –
像我之前的評論一樣,你的用例就是爲什麼有節點標籤。你可以給你的節點添加標籤,當你用'kubectl描述節點'時也會顯示標籤。在代碼中添加位置,每當有新版本的k8s出現時,都要添加它,因爲這種更改不會在上游合併。如果你看看雲節點是如何自動標記在k8s雲提供商的標籤還包括位置/區域 – puja
這是因爲該羣集中的設備可能隨時移動,所以我想要讀取設備上的GPS並自動更新位置值 –