From 9fe69066223d22fdace49240b8d640ca4331460b Mon Sep 17 00:00:00 2001 From: Harduino Date: Thu, 25 Feb 2021 14:27:15 +0300 Subject: [PATCH 1/2] improve work with Kubernetes --- functions/onprem/orborus/orborus.go | 2 +- functions/onprem/worker/worker.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/functions/onprem/orborus/orborus.go b/functions/onprem/orborus/orborus.go index bf7f2919..a2e3d716 100644 --- a/functions/onprem/orborus/orborus.go +++ b/functions/onprem/orborus/orborus.go @@ -106,7 +106,7 @@ func getThisContainerId() { } if fCol != "" { - cmd := fmt.Sprintf("cat /proc/self/cgroup | grep memory | tail -1 | cut -d/ -f%s", fCol) + cmd := fmt.Sprintf("cat /proc/self/cgroup | grep memory | tail -1 | cut -d/ -f%s | grep -o -E '[0-9A-z]{64}'", fCol) out, err := exec.Command("bash", "-c", cmd).Output() if err == nil { containerId = strings.TrimSpace(string(out)) diff --git a/functions/onprem/worker/worker.go b/functions/onprem/worker/worker.go index dcda8b3e..259b3f06 100644 --- a/functions/onprem/worker/worker.go +++ b/functions/onprem/worker/worker.go @@ -53,7 +53,7 @@ var containerId string // form container id of current running container func getThisContainerId() string { id := "" - cmd := fmt.Sprintf("cat /proc/self/cgroup | grep memory | tail -1 | cut -d/ -f3") + cmd := fmt.Sprintf("cat /proc/self/cgroup | grep memory | tail -1 | cut -d/ -f3 | grep -o -E '[0-9A-z]{64}'") out, err := exec.Command("bash", "-c", cmd).Output() if err == nil { id = strings.TrimSpace(string(out)) @@ -861,6 +861,7 @@ func deployApp(cli *dockerclient.Client, image string, identifier string, env [] } // form container id and use it as network source if it's not empty + containerId = getThisContainerId() if containerId != "" { hostConfig.NetworkMode = container.NetworkMode(fmt.Sprintf("container:%s", containerId)) } else { From 403648a5769d86e5007fd46743902703ce6346e0 Mon Sep 17 00:00:00 2001 From: frikky Date: Fri, 26 Feb 2021 08:06:45 +0100 Subject: [PATCH 2/2] #275: Added check for whether the ID exists or not instead of opening new FD's --- functions/onprem/worker/worker.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/functions/onprem/worker/worker.go b/functions/onprem/worker/worker.go index 259b3f06..7a11bb0c 100644 --- a/functions/onprem/worker/worker.go +++ b/functions/onprem/worker/worker.go @@ -52,6 +52,10 @@ var containerId string // form container id of current running container func getThisContainerId() string { + if len(containerId) > 0 { + return containerId + } + id := "" cmd := fmt.Sprintf("cat /proc/self/cgroup | grep memory | tail -1 | cut -d/ -f3 | grep -o -E '[0-9A-z]{64}'") out, err := exec.Command("bash", "-c", cmd).Output()