blob: a1a2dc77cf118f8b8453f4f0bf2c3005a9a465d6 [file] [log] [blame]
Lorenz Brun65702192023-08-31 16:27:38 +02001From 2aaae27bbcdae1c917441932fb79b6f6b6e0ebcd Mon Sep 17 00:00:00 2001
2From: Tim Windelschmidt <tim@monogon.tech>
3Date: Tue, 12 Sep 2023 14:33:58 +0200
Lorenz Brund13c1c62022-03-30 19:58:58 +02004Subject: [PATCH] containerd 1.6 compatibility
5
6---
7 pkg/shim/proc/exec.go | 2 +-
8 pkg/shim/proc/init.go | 2 +-
9 pkg/shim/service.go | 17 +++++++++--------
10 pkg/shim/service_linux.go | 2 +-
11 4 files changed, 12 insertions(+), 11 deletions(-)
12
13diff --git a/pkg/shim/proc/exec.go b/pkg/shim/proc/exec.go
14index da2e21598..d0d14dd24 100644
15--- a/pkg/shim/proc/exec.go
16+++ b/pkg/shim/proc/exec.go
17@@ -238,7 +238,7 @@ func (e *execProcess) start(ctx context.Context) error {
18 if err != nil {
19 return fmt.Errorf("failed to retrieve console master: %w", err)
20 }
21- if e.console, err = e.parent.Platform.CopyConsole(ctx, console, e.stdio.Stdin, e.stdio.Stdout, e.stdio.Stderr, &e.wg); err != nil {
22+ if e.console, err = e.parent.Platform.CopyConsole(ctx, console, e.id, e.stdio.Stdin, e.stdio.Stdout, e.stdio.Stderr, &e.wg); err != nil {
23 return fmt.Errorf("failed to start console copy: %w", err)
24 }
25 } else if !e.stdio.IsNull() {
26diff --git a/pkg/shim/proc/init.go b/pkg/shim/proc/init.go
Lorenz Brun65702192023-08-31 16:27:38 +020027index fcdc8e2bc..f2aaf6c2a 100644
Lorenz Brund13c1c62022-03-30 19:58:58 +020028--- a/pkg/shim/proc/init.go
29+++ b/pkg/shim/proc/init.go
Lorenz Brun65702192023-08-31 16:27:38 +020030@@ -155,7 +155,7 @@ func (p *Init) Create(ctx context.Context, r *CreateConfig) (err error) {
Lorenz Brund13c1c62022-03-30 19:58:58 +020031 if err != nil {
32 return fmt.Errorf("failed to retrieve console master: %w", err)
33 }
34- console, err = p.Platform.CopyConsole(ctx, console, r.Stdin, r.Stdout, r.Stderr, &p.wg)
35+ console, err = p.Platform.CopyConsole(ctx, console, r.ID, r.Stdin, r.Stdout, r.Stderr, &p.wg)
36 if err != nil {
37 return fmt.Errorf("failed to start console copy: %w", err)
38 }
39diff --git a/pkg/shim/service.go b/pkg/shim/service.go
Lorenz Brun65702192023-08-31 16:27:38 +020040index a6904e1ae..964a152c9 100644
Lorenz Brund13c1c62022-03-30 19:58:58 +020041--- a/pkg/shim/service.go
42+++ b/pkg/shim/service.go
43@@ -50,7 +50,7 @@ import (
44 "github.com/sirupsen/logrus"
45 "golang.org/x/sys/unix"
46 "gvisor.dev/gvisor/pkg/cleanup"
47- "gvisor.dev/gvisor/pkg/shim/runtimeoptions/v14"
48+ v14 "gvisor.dev/gvisor/pkg/shim/runtimeoptions/v14"
Lorenz Brun65702192023-08-31 16:27:38 +020049
Lorenz Brund13c1c62022-03-30 19:58:58 +020050 "gvisor.dev/gvisor/pkg/shim/proc"
51 "gvisor.dev/gvisor/pkg/shim/runsc"
52@@ -189,7 +189,7 @@ type service struct {
Lorenz Brun65702192023-08-31 16:27:38 +020053
54 var _ shim.Shim = (*service)(nil)
55
Lorenz Brund13c1c62022-03-30 19:58:58 +020056-func (s *service) newCommand(ctx context.Context, containerdBinary, containerdAddress string) (*exec.Cmd, error) {
57+func (s *service) newCommand(ctx context.Context, id, containerdBinary, containerdAddress string) (*exec.Cmd, error) {
58 ns, err := namespaces.NamespaceRequired(ctx)
59 if err != nil {
60 return nil, err
61@@ -204,6 +204,7 @@ func (s *service) newCommand(ctx context.Context, containerdBinary, containerdAd
62 }
63 args := []string{
64 "-namespace", ns,
65+ "-id", id,
66 "-address", containerdAddress,
67 "-publish-binary", containerdBinary,
68 }
69@@ -219,14 +220,14 @@ func (s *service) newCommand(ctx context.Context, containerdBinary, containerdAd
70 return cmd, nil
71 }
Lorenz Brun65702192023-08-31 16:27:38 +020072
Lorenz Brund13c1c62022-03-30 19:58:58 +020073-func (s *service) StartShim(ctx context.Context, id, containerdBinary, containerdAddress, containerdTTRPCAddress string) (string, error) {
74- log.L.Debugf("StartShim, id: %s, binary: %q, address: %q", id, containerdBinary, containerdAddress)
75+func (s *service) StartShim(ctx context.Context, opts shim.StartOpts) (string, error) {
76+ log.L.Debugf("StartShim, id: %s, binary: %q, address: %q", opts.ID, opts.ContainerdBinary, opts.Address)
Lorenz Brun65702192023-08-31 16:27:38 +020077
Lorenz Brund13c1c62022-03-30 19:58:58 +020078- cmd, err := s.newCommand(ctx, containerdBinary, containerdAddress)
79+ cmd, err := s.newCommand(ctx, opts.ID, opts.ContainerdBinary, opts.Address)
80 if err != nil {
81 return "", err
82 }
83- address, err := shim.SocketAddress(ctx, containerdAddress, id)
84+ address, err := shim.SocketAddress(ctx, opts.Address, opts.ID)
85 if err != nil {
86 return "", err
87 }
88@@ -280,8 +281,8 @@ func (s *service) StartShim(ctx context.Context, id, containerdBinary, container
89 if err := shim.WriteAddress(shimAddressPath, address); err != nil {
90 return "", err
91 }
92- if err := shim.SetScore(cmd.Process.Pid); err != nil {
93- return "", fmt.Errorf("failed to set OOM Score on shim: %w", err)
94+ if err := shim.AdjustOOMScore(cmd.Process.Pid); err != nil {
95+ return "", fmt.Errorf("failed to adjust OOM score for shim: %w", err)
96 }
97 cu.Release()
98 return address, nil
99diff --git a/pkg/shim/service_linux.go b/pkg/shim/service_linux.go
100index fb2f8b062..52c82ca90 100644
101--- a/pkg/shim/service_linux.go
102+++ b/pkg/shim/service_linux.go
103@@ -33,7 +33,7 @@ type linuxPlatform struct {
104 epoller *console.Epoller
105 }
Lorenz Brun65702192023-08-31 16:27:38 +0200106
Lorenz Brund13c1c62022-03-30 19:58:58 +0200107-func (p *linuxPlatform) CopyConsole(ctx context.Context, console console.Console, stdin, stdout, stderr string, wg *sync.WaitGroup) (console.Console, error) {
108+func (p *linuxPlatform) CopyConsole(ctx context.Context, console console.Console, id, stdin, stdout, stderr string, wg *sync.WaitGroup) (console.Console, error) {
109 if p.epoller == nil {
110 return nil, fmt.Errorf("uninitialized epoller")
111 }
Lorenz Brun65702192023-08-31 16:27:38 +0200112--
1132.41.0
Lorenz Brund13c1c62022-03-30 19:58:58 +0200114