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

Commit

Permalink
Add container labels to the list of labels exported by heapster.
Browse files Browse the repository at this point in the history
This is useful for monitoring based on labels set to container images.
  • Loading branch information
vishh committed Sep 18, 2015
1 parent 6317dd9 commit faf2515
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sinks/api/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package v1

import (
"fmt"
"time"

"k8s.io/heapster/sinks/cache"
Expand Down Expand Up @@ -94,6 +95,12 @@ func (self *decoder) getContainerMetrics(container *cache.ContainerElement, labe
}
labels[LabelContainerName.Key] = container.Name
labels[LabelContainerBaseImage.Key] = container.Image
// Add container specific labels along with existing labels.
containerLabels := util.LabelsToString(container.Labels, ",")
if labels[LabelLabels.Key] != "" {
containerLabels = fmt.Sprintf("%s,%s", labels[LabelLabels.Key], containerLabels)
}
labels[LabelLabels.Key] = containerLabels

if _, exists := labels[LabelHostID.Key]; !exists {
labels[LabelHostID.Key] = container.ExternalID
Expand Down
2 changes: 2 additions & 0 deletions sinks/cache/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ func (rc *realCache) StorePods(pods []source_api.Pod) error {
ce.Metadata = Metadata{
Name: cont.Name,
Hostname: cont.Hostname,
Labels: cont.Spec.Labels,
}
ce.Image = cont.Image
ce.Metadata.LastUpdate = storeSpecAndStats(ce, cont)
Expand Down Expand Up @@ -240,6 +241,7 @@ func (rc *realCache) StoreContainers(containers []source_api.Container) error {
ne.freeContainers[cont.Name] = ce
}
}
ce.Metadata.Labels = cont.Spec.Labels
ce.Image = cont.Image
ce.Metadata.LastUpdate = storeSpecAndStats(ce, cont)
ce.lastUpdated = now
Expand Down

0 comments on commit faf2515

Please # to comment.