kubernetesノードの情報に位置情報を追加し、kubectlコマンドの "describe node"コマンドでノードの位置を出力します。しかし、私は場所の値を印刷することはできません。 出力はイメージのようです。 output of current code 私は何が間違っているのですか、何をすべきですか?私はそれを逃しましたか? すべてのヘルプは非常にkubernetesノードの情報をkubectnetノード情報に追加してkubectlにそれを表示させます
を理解されるであろう、私はすでにkubernetesに新しい変数
Location string `json:"location"`
を追加/ベンダー/ github.com /グーグル/ cadvisor /情報/ V1/machine.go
と修正Locationの値を設定して渡す対応するファイル。
は、私はまた、/ホーム/ウィリアム/ kubernetesで/home/william/kubernetes/pkg/api/types.go
と
Location string `json:"location" protobuf:"bytes,2,opt,name=location"`
に新しい変数
Location string `json:"location"`
を追加しました/pkg/api/v1/types.go
out.Location = in.Location
/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
}
で機能autoConvert_v1_NodeSystemInfo_To_api_NodeSystemInfoで
とに機能describeNodeに
fmt.Fprintf(out, " Location:\t%s\n", node.Status.NodeInfo.Location)
を追加/ホーム/ 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 node 'を記述するときにもラベルが表示されます。コードの場所を追加すると、k8sの新しいバージョンが出るたびに追加することになります。この種の変更は上流にマージされません。クラウドノードがk8sクラウドプロバイダーでどのように自動的にラベル付けされるかを見ると、ラベルには位置/地域も含まれます – puja
このクラスター内のデバイスはいつでも移動する可能性があるため、デバイス上のGPSを読み取り、 –