Skip to content

Commit

Permalink
updated status call
Browse files Browse the repository at this point in the history
  • Loading branch information
Bianco95 committed Jun 25, 2024
1 parent f908f97 commit 86a3279
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
1 change: 1 addition & 0 deletions pkg/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type PodStatus struct {
PodName string `json:"name"`
PodUID string `json:"UID"`
PodNamespace string `json:"namespace"`
JobID string `json:"JID"`
Containers []v1.ContainerStatus `json:"containers"`
InitContainers []v1.ContainerStatus `json:"initContainers"`
}
Expand Down
17 changes: 9 additions & 8 deletions pkg/docker/Create.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ import (
"path/filepath"
)

type DockerRunStruct struct {
Name string `json:"name"`
Command string `json:"command"`
IsInitContainer bool `json:"isInitContainer"`
GpuArgs string `json:"gpuArgs"`
}

func (h *SidecarHandler) prepareDockerRuns(podData commonIL.RetrievedPodData, w http.ResponseWriter) ([]DockerRunStruct, error) {

var dockerRunStructs []DockerRunStruct
Expand Down Expand Up @@ -490,12 +483,20 @@ func (h *SidecarHandler) CreateHandler(w http.ResponseWriter, r *http.Request) {

log.G(h.Ctx).Info("\u2705 [POD FLOW] Containers created successfully")

createResponse := CreateStruct{PodUID: string(data.Pod.UID), PodJID: dindContainerID}
createResponseBytes, err := json.Marshal(createResponse)
if err != nil {
statusCode = http.StatusInternalServerError
HandleErrorAndRemoveData(h, w, "An error occurred during the json marshal of the returned JID", err, "", "")
return
}

w.WriteHeader(statusCode)

if statusCode != http.StatusOK {
w.Write([]byte("Some errors occurred while creating containers. Check Docker Sidecar's logs"))
} else {
w.Write([]byte("Containers created"))
w.Write(createResponseBytes)
}
}

Expand Down
21 changes: 20 additions & 1 deletion pkg/docker/Status.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,27 @@ func (h *SidecarHandler) StatusHandler(w http.ResponseWriter, r *http.Request) {
podUID := string(pod.UID)
podNamespace := string(pod.Namespace)

resp = append(resp, commonIL.PodStatus{PodName: pod.Name, PodUID: podUID, PodNamespace: podNamespace})
// send a docker command to retrieve the uuid of the dind container
// the command to exec is: docker inspect --format '{{.Id}}' podUID + "_dind"
cmd := []string{"inspect", "--format", "{{.Id}}", podUID + "_dind"}
shell := exec.ExecTask{
Command: "docker",
Args: cmd,
Shell: true,
}
execReturn, err := shell.Execute()
if err != nil {
log.G(h.Ctx).Error(err)
statusCode = http.StatusInternalServerError
break
}

dindUUID := strings.ReplaceAll(execReturn.Stdout, "\n", "")
log.G(h.Ctx).Info("\u2705 [STATUS CALL] UUID of the dind container retrieved successfully: ", dindUUID)

resp = append(resp, commonIL.PodStatus{PodName: pod.Name, PodUID: podUID, PodNamespace: podNamespace, JobID: dindUUID})
for _, container := range pod.Spec.Containers {

containerName := podNamespace + "-" + podUID + "-" + container.Name
cmd := []string{"exec " + podUID + "_dind" + " docker ps -af name=^" + containerName + "$ --format \"{{.Status}}\""}

Expand Down
12 changes: 12 additions & 0 deletions pkg/docker/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package docker

type DockerRunStruct struct {
Name string `json:"name"`
Command string `json:"command"`
IsInitContainer bool `json:"isInitContainer"`
GpuArgs string `json:"gpuArgs"`
}
type CreateStruct struct {
PodUID string `json:"PodUID"`
PodJID string `json:"PodJID"`
}

0 comments on commit 86a3279

Please sign in to comment.