pdtpartners / nix-snapshotter

Brings native understanding of Nix packages to containerd
MIT License
532 stars 15 forks source link

unable to initialize unpacker: no unpack platforms defined: invalid argument #100

Closed bergkvist closed 7 months ago

bergkvist commented 11 months ago

Error message:

rpc error: code = InvalidArgument desc = unable to initialize unpacker: no unpack platforms defined: invalid argument

Source of error:

https://github.com/pdtpartners/nix-snapshotter/blob/6eb21bd3429535646da4aa396bb0c1f81a9b72c6/pkg/nix2container/load.go#L51

Environment

$ sudo nano /var/snap/microk8s/current/args/kubelet

# Add this to the end of the file:
# --image-service-endpoint=unix:///run/nix-snapshotter/nix-snapshotter.sock

Starting nix-snapshotter:

$ git clone https://github.com/pdtpartners/nix-snapshotter
$ cd nix-snapshotter
$ sudo "$(nix-build)/bin/nix-snapshotter"

We deploy to microk8s using:

kubectl apply -f "$(nix-build image.nix)"
# image.nix
{ pkgs ? import (builtins.fetchTarball {
    url = "https://github.com/NixOS/nixpkgs/archive/refs/tags/23.05.tar.gz";
    sha256 = "10wn0l08j9lgqcw8177nh2ljrnxdrpri7bp0g7nvrsn9rkawvlbf";
  }) {}
, nix-snapshotter ? import (builtins.fetchTarball {
    url = "https://github.com/pdtpartners/nix-snapshotter/archive/6eb21bd3429535646da4aa396bb0c1f81a9b72c6.tar.gz";
    sha256 = "11sfy3kf046p8kacp7yh8ijjpp6php6q8wxlbya1v5q53h3980v1";
  })
}:
let
  redis-image = nix-snapshotter.default.buildImage {
    name = "abc123-redis";
    tag = "latest";
    config.entrypoint = [ "${pkgs.redis}/bin/redis-server" ];
  };
in
pkgs.writeText "pod.json" (builtins.toJSON rec {
  apiVersion = "v1";
  kind = "Pod";
  metadata.name = "redis";
  metadata.labels.name = metadata.name;
  spec.containers = [{
    inherit (metadata) name;
    args = [ "--protected-mode" "no" ];
    image = "nix:0${redis-image}";
    ports = [{
      name = "client";
      containerPort = 6379;
    }];
  }];
})
elpdt852 commented 11 months ago

Hi @bergkvist, thanks for reporting your issue.

TLDR; It's likely your containerd is not configured correctly. It needs to run with a few config settings for cri, unpack_config and proxy_plugins.nix: https://github.com/pdtpartners/nix-snapshotter/blob/6eb21bd3429535646da4aa396bb0c1f81a9b72c6/script/rootless/create-containerd-config.sh#L17-L19


Investigation

Unpack platforms are defined here: https://github.com/pdtpartners/nix-snapshotter/blob/6eb21bd3429535646da4aa396bb0c1f81a9b72c6/pkg/nix2container/load.go#L29-L33

Which on unix platforms defaults to runtime.GOOS and runtime.GOARCH: https://github.com/containerd/containerd/blob/v1.7.2/platforms/defaults_unix.go#L27-L35

nix-snapshotter.default.buildImage is running code in pkg/nix2container/load.go inside the Nix sandbox, so that's where runtime.GOOS and runtime.GOARCH will get its values from.

The error site on the containerd site will be down this code path:

This means either iu.UnpackPlatforms() or ts.config.UnpackPlatforms is missing the nix snapshotter platform.

iu.UnpackPlatforms() is traced down to:

That's defined by us so that's not going to be incorrect one. So it must be ts.config.UnpackPlatforms which is traced down to:

elpdt852 commented 10 months ago

@bergkvist Do you mind confirming if it's indeed a configuration issue?

bergkvist commented 10 months ago

I did try editing the containerd config, and managed to get rid of this particular error - but in so doing I also somehow managed to corrupt my microk8s instance in a way where the Kubernetes API kept being constantly killed even after removing the config again, and rebooting the server microk8s was running on.

I ended up just creating a new server, and I haven't reinstalled microk8s yet, or had time to look more at this since then. Unfortunately that also means I don't have those new logs/error messages right now.

elpdt852 commented 7 months ago

Please re-open if you were able to reproduce this issue with the suggested containerd config changes.