@@ -4,10 +4,12 @@ import (
4
4
"bufio"
5
5
"context"
6
6
"fmt"
7
+ "log"
7
8
"os"
8
9
"os/exec"
9
10
"time"
10
11
12
+ "github.com/containerd/nstools"
11
13
"github.com/txn2/txeh"
12
14
13
15
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -22,6 +24,7 @@ const (
22
24
prodRegistryIpEnvName = "PROD_REGISTRY_PORT_80_TCP_ADDR"
23
25
buildsRegsitryIpEnvName = "BUILDS_REGISTRY_PORT_80_TCP_ADDR"
24
26
containerdConfigPath = "/etc/containerd/config.toml"
27
+ containerdTargetPid = 1
25
28
)
26
29
27
30
func main () {
@@ -63,13 +66,21 @@ func main() {
63
66
}
64
67
fmt .Printf ("containerd config updated\n " )
65
68
66
- fmt .Printf ("restarting containerd\n " )
67
- cmd := exec .Command ("nsenter" , "--mount=/proc/1/ns/mnt" , "--" , "systemctl" , "restart" , "containerd" )
68
- output , err := cmd .CombinedOutput ()
69
- if err != nil {
70
- panic (err .Error ())
69
+ fmt .Printf ("containerd restart\n " )
70
+ if err = nstools .WithNamespaces (containerdTargetPid , func () error {
71
+ // Code to run inside the namespace
72
+ cmd := exec .Command ("systemctl" , "restart" , "containerd" )
73
+ cmd .Stdin = os .Stdin
74
+ cmd .Stdout = os .Stdout
75
+ cmd .Stderr = os .Stderr
76
+ if err := cmd .Run (); err != nil {
77
+ log .Fatalf ("Failed to run command in namespace: %v" , err )
78
+ }
79
+ return nil
80
+ }); err != nil {
81
+ log .Fatalf ("Failed to enter namespaces: %v" , err )
71
82
}
72
- fmt .Printf ("restart output: %s" , output )
83
+ fmt .Printf ("containerd restarted \n " )
73
84
74
85
clientconfig , err := rest .InClusterConfig ()
75
86
if err != nil {
0 commit comments