@@ -409,9 +409,10 @@ func (this *summaryMetricsSource) getSystemContainerName(c *stats.ContainerStats
409409
410410// TODO: The summaryProvider duplicates a lot of code from kubeletProvider, and should be refactored.
411411type summaryProvider struct {
412- nodeLister v1listers.NodeLister
413- reflector * cache.Reflector
414- kubeletClient * kubelet.KubeletClient
412+ nodeLister v1listers.NodeLister
413+ reflector * cache.Reflector
414+ kubeletClient * kubelet.KubeletClient
415+ hostIDAnnotation string
415416}
416417
417418func (this * summaryProvider ) GetMetricsSources () []MetricsSource {
@@ -442,10 +443,14 @@ func (this *summaryProvider) getNodeInfo(node *kube_api.Node) (NodeInfo, error)
442443 if hostname == "" {
443444 hostname = node .Name
444445 }
446+ hostID := node .Spec .ExternalID
447+ if hostID == "" && this .hostIDAnnotation != "" {
448+ hostID = node .Annotations [this .hostIDAnnotation ]
449+ }
445450 info := NodeInfo {
446451 NodeName : node .Name ,
447452 HostName : hostname ,
448- HostID : node . Spec . ExternalID ,
453+ HostID : hostID ,
449454 Host : kubelet.Host {
450455 IP : ip ,
451456 Port : this .kubeletClient .GetPort (),
@@ -456,6 +461,12 @@ func (this *summaryProvider) getNodeInfo(node *kube_api.Node) (NodeInfo, error)
456461}
457462
458463func NewSummaryProvider (uri * url.URL ) (MetricsSourceProvider , error ) {
464+ opts := uri .Query ()
465+
466+ hostIDAnnotation := ""
467+ if len (opts ["host_id_annotation" ]) > 0 {
468+ hostIDAnnotation = opts ["host_id_annotation" ][0 ]
469+ }
459470 // create clients
460471 kubeConfig , kubeletConfig , err := kubelet .GetKubeConfigs (uri )
461472 if err != nil {
@@ -470,8 +481,9 @@ func NewSummaryProvider(uri *url.URL) (MetricsSourceProvider, error) {
470481 nodeLister , reflector , _ := util .GetNodeLister (kubeClient )
471482
472483 return & summaryProvider {
473- nodeLister : nodeLister ,
474- reflector : reflector ,
475- kubeletClient : kubeletClient ,
484+ nodeLister : nodeLister ,
485+ reflector : reflector ,
486+ kubeletClient : kubeletClient ,
487+ hostIDAnnotation : hostIDAnnotation ,
476488 }, nil
477489}
0 commit comments