Skip to content
This repository has been archived by the owner on Dec 1, 2018. It is now read-only.

Commit

Permalink
Merge pull request #2070 from kawych/release-1.5
Browse files Browse the repository at this point in the history
Add an option to read Host ID from node annotation if ExternalID is not available
  • Loading branch information
k8s-ci-robot authored Jul 26, 2018
2 parents bd2bb79 + 19be17e commit 105c0f2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion events/sinks/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (this *SinkFactory) BuildAll(uris flags.Uris) []core.EventSink {
for _, uri := range uris {
sink, err := this.Build(uri)
if err != nil {
glog.Errorf("Failed to create sink: %v", err)
glog.Errorf("Failed to create %v sink: %v", uri, err)
continue
}
result = append(result, sink)
Expand Down
26 changes: 19 additions & 7 deletions metrics/sources/summary/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,10 @@ func (this *summaryMetricsSource) getSystemContainerName(c *stats.ContainerStats

// TODO: The summaryProvider duplicates a lot of code from kubeletProvider, and should be refactored.
type summaryProvider struct {
nodeLister v1listers.NodeLister
reflector *cache.Reflector
kubeletClient *kubelet.KubeletClient
nodeLister v1listers.NodeLister
reflector *cache.Reflector
kubeletClient *kubelet.KubeletClient
hostIDAnnotation string
}

func (this *summaryProvider) GetMetricsSources() []MetricsSource {
Expand Down Expand Up @@ -418,10 +419,14 @@ func (this *summaryProvider) getNodeInfo(node *kube_api.Node) (NodeInfo, error)
if hostname == "" {
hostname = node.Name
}
hostID := node.Spec.ExternalID
if hostID == "" && this.hostIDAnnotation != "" {
hostID = node.Annotations[this.hostIDAnnotation]
}
info := NodeInfo{
NodeName: node.Name,
HostName: hostname,
HostID: node.Spec.ExternalID,
HostID: hostID,
Host: kubelet.Host{
IP: ip,
Port: this.kubeletClient.GetPort(),
Expand All @@ -432,6 +437,12 @@ func (this *summaryProvider) getNodeInfo(node *kube_api.Node) (NodeInfo, error)
}

func NewSummaryProvider(uri *url.URL) (MetricsSourceProvider, error) {
opts := uri.Query()

hostIDAnnotation := ""
if len(opts["host_id_annotation"]) > 0 {
hostIDAnnotation = opts["host_id_annotation"][0]
}
// create clients
kubeConfig, kubeletConfig, err := kubelet.GetKubeConfigs(uri)
if err != nil {
Expand All @@ -446,8 +457,9 @@ func NewSummaryProvider(uri *url.URL) (MetricsSourceProvider, error) {
nodeLister, reflector, _ := util.GetNodeLister(kubeClient)

return &summaryProvider{
nodeLister: nodeLister,
reflector: reflector,
kubeletClient: kubeletClient,
nodeLister: nodeLister,
reflector: reflector,
kubeletClient: kubeletClient,
hostIDAnnotation: hostIDAnnotation,
}, nil
}

0 comments on commit 105c0f2

Please sign in to comment.