-
Notifications
You must be signed in to change notification settings - Fork 40.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move docker label related functions into labels.go and add pod name, …
…pod namespace and pod uid into docker label
- Loading branch information
1 parent
bffdd24
commit b3585a5
Showing
5 changed files
with
98 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
Copyright 2015 The Kubernetes Authors All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package dockertools | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/golang/glog" | ||
"k8s.io/kubernetes/pkg/api" | ||
) | ||
|
||
// This file contains all docker label related constants and functions, including: | ||
// * label setters and getters | ||
// * label filters (maybe in the future) | ||
|
||
const ( | ||
kubernetesPodNameLabel = "io.kubernetes.pod.name" | ||
kubernetesPodNamespaceLabel = "io.kubernetes.pod.namespace" | ||
kubernetesPodUID = "io.kubernetes.pod.uid" | ||
|
||
kubernetesPodLabel = "io.kubernetes.pod.data" | ||
kubernetesTerminationGracePeriodLabel = "io.kubernetes.pod.terminationGracePeriod" | ||
kubernetesContainerLabel = "io.kubernetes.container.name" | ||
kubernetesContainerRestartCountLabel = "io.kubernetes.container.restartCount" | ||
) | ||
|
||
func newLabels(container *api.Container, pod *api.Pod, restartCount int) map[string]string { | ||
// TODO (random-liu) Move more label initialization here | ||
labels := map[string]string{} | ||
labels[kubernetesPodNameLabel] = pod.Name | ||
labels[kubernetesPodNamespaceLabel] = pod.Namespace | ||
labels[kubernetesPodUID] = string(pod.UID) | ||
|
||
labels[kubernetesContainerRestartCountLabel] = strconv.Itoa(restartCount) | ||
|
||
return labels | ||
} | ||
|
||
func getRestartCountFromLabel(labels map[string]string) (restartCount int, err error) { | ||
if restartCountString, found := labels[kubernetesContainerRestartCountLabel]; found { | ||
restartCount, err = strconv.Atoi(restartCountString) | ||
if err != nil { | ||
// This really should not happen. Just set restartCount to 0 to handle this abnormal case | ||
restartCount = 0 | ||
} | ||
} else { | ||
// Get restartCount from docker label. If there is no restart count label in a container, | ||
// it should be an old container or an invalid container, we just set restart count to 0. | ||
// Do not report error, because there should be many old containers without this label now | ||
glog.V(3).Infof("Container doesn't have label %s, it may be an old or invalid container", kubernetesContainerRestartCountLabel) | ||
} | ||
return restartCount, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b3585a5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TeamCity OSS :: Kubernetes Mesos :: 4 - Smoke Tests Build 2981 outcome was SUCCESS
Summary: Tests passed: 1, ignored: 193 Build time: 00:08:26