Lorenz Brun | d13c1c6 | 2022-03-30 19:58:58 +0200 | [diff] [blame] | 1 | From bf861ce45721791336b617a44844613bb74c677a Mon Sep 17 00:00:00 2001 |
| 2 | From: Lorenz Brun <lorenz@monogon.tech> |
| 3 | Date: Tue, 22 Mar 2022 00:52:48 +0100 |
| 4 | Subject: [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 | |
| 13 | diff --git a/pkg/shim/proc/exec.go b/pkg/shim/proc/exec.go |
| 14 | index 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() { |
| 26 | diff --git a/pkg/shim/proc/init.go b/pkg/shim/proc/init.go |
| 27 | index 6bf090813..76df1101a 100644 |
| 28 | --- a/pkg/shim/proc/init.go |
| 29 | +++ b/pkg/shim/proc/init.go |
| 30 | @@ -152,7 +152,7 @@ func (p *Init) Create(ctx context.Context, r *CreateConfig) (err error) { |
| 31 | 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 | } |
| 39 | diff --git a/pkg/shim/service.go b/pkg/shim/service.go |
| 40 | index 68966afdf..772168052 100644 |
| 41 | --- 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" |
| 49 | |
| 50 | "gvisor.dev/gvisor/pkg/shim/proc" |
| 51 | "gvisor.dev/gvisor/pkg/shim/runsc" |
| 52 | @@ -189,7 +189,7 @@ type service struct { |
| 53 | shimAddress string |
| 54 | } |
| 55 | |
| 56 | -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 | } |
| 72 | |
| 73 | -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) |
| 77 | |
| 78 | - 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 |
| 99 | diff --git a/pkg/shim/service_linux.go b/pkg/shim/service_linux.go |
| 100 | index 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 | } |
| 106 | |
| 107 | -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 | } |
| 112 | -- |
| 113 | 2.25.1 |
| 114 | |