Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
solsson committed Jul 13, 2024
1 parent 2c99bc8 commit 3957457
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions registry/node-update/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"bufio"
"context"
"fmt"
"log"
"os"
"os/exec"
"time"

"github.com/containerd/nstools"
"github.com/txn2/txeh"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -22,6 +24,7 @@ const (
prodRegistryIpEnvName = "PROD_REGISTRY_PORT_80_TCP_ADDR"
buildsRegsitryIpEnvName = "BUILDS_REGISTRY_PORT_80_TCP_ADDR"
containerdConfigPath = "/etc/containerd/config.toml"
containerdTargetPid = 1
)

func main() {
Expand Down Expand Up @@ -63,13 +66,21 @@ func main() {
}
fmt.Printf("containerd config updated\n")

fmt.Printf("restarting containerd\n")
cmd := exec.Command("nsenter", "--mount=/proc/1/ns/mnt", "--", "systemctl", "restart", "containerd")
output, err := cmd.CombinedOutput()
if err != nil {
panic(err.Error())
fmt.Printf("containerd restart\n")
if err = nstools.WithNamespaces(containerdTargetPid, func() error {
// Code to run inside the namespace
cmd := exec.Command("systemctl", "restart", "containerd")
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
log.Fatalf("Failed to run command in namespace: %v", err)
}
return nil
}); err != nil {
log.Fatalf("Failed to enter namespaces: %v", err)
}
fmt.Printf("restart output: %s", output)
fmt.Printf("containerd restarted\n")

clientconfig, err := rest.InClusterConfig()
if err != nil {
Expand Down

0 comments on commit 3957457

Please sign in to comment.