Add ContainerID into the ContainerStatus (#337)

This commit is contained in:
Robbie Zhang
2018-08-27 15:38:14 -07:00
committed by GitHub
parent b019ec5549
commit 55bc0c3f75
2 changed files with 147 additions and 68 deletions

View File

@@ -3,7 +3,9 @@ package azure
import (
"bytes"
"context"
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
@@ -974,7 +976,7 @@ func containerGroupToPod(cg *aci.ContainerGroup) (*v1.Pod, error) {
RestartCount: c.InstanceView.RestartCount,
Image: c.Image,
ImageID: "",
ContainerID: "",
ContainerID: getContainerID(cg.ID, c.Name),
}
// Add to containerStatuses
@@ -1018,6 +1020,19 @@ func containerGroupToPod(cg *aci.ContainerGroup) (*v1.Pod, error) {
return &p, nil
}
func getContainerID(cgID, containerName string) string {
if cgID == "" {
return ""
}
containerResourceID := fmt.Sprintf("%s/containers/%s", cgID, containerName)
h := sha256.New()
h.Write([]byte(strings.ToUpper(containerResourceID)))
hashBytes := h.Sum(nil)
return fmt.Sprintf("aci://%s", hex.EncodeToString(hashBytes))
}
func aciStateToPodPhase(state string) v1.PodPhase {
switch state {
case "Running":