Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 2a1e2f4

Browse files
committed
Merge pull request #78 from feiskyer/label-hyper-pod
Label hyper pods with meta.labels
2 parents ec95ce5 + 94b35b0 commit 2a1e2f4

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

pkg/kubelet/hyper/hyper.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ func (r *runtime) GetPods(all bool) ([]*kubecontainer.Pod, error) {
321321
continue
322322
}
323323

324-
podID := podInfo.PodInfo.Spec.Labels["UID"]
324+
podID := podInfo.PodInfo.Spec.Labels[KEY_API_POD_UID]
325325
podName, podNamespace, err := kubecontainer.ParsePodFullName(podInfo.PodName)
326326
if err != nil {
327327
glog.V(5).Infof("Hyper: pod %s is not managed by kubelet", podInfo.PodName)
@@ -599,9 +599,15 @@ func (r *runtime) buildHyperPod(pod *api.Pod, restartCount int, pullSecrets []ap
599599
specMap[KEY_RESOURCE] = podResource
600600
glog.V(5).Infof("Hyper: pod limit vcpu=%v mem=%vMiB", podResource[KEY_VCPU], podResource[KEY_MEMORY])
601601

602+
// Setup labels
603+
podLabels := map[string]string{KEY_API_POD_UID: string(pod.UID)}
604+
for k, v := range pod.Labels {
605+
podLabels[k] = v
606+
}
607+
specMap[KEY_LABELS] = podLabels
608+
602609
// other params required
603610
specMap[KEY_ID] = kubecontainer.BuildPodFullName(pod.Name, pod.Namespace)
604-
specMap[KEY_LABELS] = map[string]string{"UID": string(pod.UID)}
605611
specMap[KEY_TTY] = false
606612

607613
// Cap hostname at 63 chars (specification is 64bytes which is 63 chars and the null terminating char).
@@ -655,7 +661,7 @@ func (r *runtime) getPodSpec(podFullName string) (string, error) {
655661
return string(spec), nil
656662
}
657663

658-
func (r *runtime) GetPodStartCount(podID string) (int, error) {
664+
func (r *runtime) GetPodRestartCount(podID string) (int, error) {
659665
containers, err := r.hyperClient.ListContainers()
660666
if err != nil {
661667
return 0, err
@@ -829,7 +835,7 @@ func (r *runtime) SyncPod(pod *api.Pod, podStatus api.PodStatus, internalPodStat
829835
podID, err := r.hyperClient.GetPodIDByName(podFullName)
830836
if err == nil && len(podID) > 0 {
831837
// Update pod restart count
832-
restartCount, err = r.GetPodStartCount(podID)
838+
restartCount, err = r.GetPodRestartCount(podID)
833839
if err != nil {
834840
glog.Errorf("Hyper: get pod startcount failed: %v", err)
835841
return err

pkg/kubelet/hyper/hyperclient.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,13 @@ const (
7474
KEY_VOLUME_SOURCE = "source"
7575
KEY_VOLUMES = "volumes"
7676
KEY_WORKDIR = "workdir"
77-
TYPE_CONTAINER = "container"
78-
TYPE_POD = "pod"
79-
VOLUME_TYPE_VFS = "vfs"
77+
78+
KEY_API_POD_UID = "k8s.hyper.sh/uid"
79+
80+
TYPE_CONTAINER = "container"
81+
TYPE_POD = "pod"
82+
83+
VOLUME_TYPE_VFS = "vfs"
8084
)
8185

8286
type HyperClient struct {

0 commit comments

Comments
 (0)