Skip to content

Commit

Permalink
feat: Add support for compiling NetBSD & OpenBSD (#851)
Browse files Browse the repository at this point in the history
Reviewed-by: Alexander Jung <[email protected]>
Approved-by: Alexander Jung <[email protected]>
  • Loading branch information
nderjung authored Feb 13, 2025
2 parents e9174bb + a8e0d5b commit b6f0b36
Show file tree
Hide file tree
Showing 18 changed files with 392 additions and 21 deletions.
4 changes: 3 additions & 1 deletion .goreleaser-stable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ version: 2
#! .goreleaser.yaml
#@ binaries = {
#@ "kraft": {
#@ "netbsd": ["amd64", "arm64"],
#@ "openbsd": ["amd64", "arm64"],
#@ "darwin": ["amd64", "arm64"],
#@ "freebsd": ["amd64", "arm64"],
#@ "linux": ["amd64", "arm64"],
Expand Down Expand Up @@ -263,7 +265,7 @@ archives:
#@ for os, archs in binaries["runu"].items():
#@ for arch in archs:
- id: #@ "archive-runu-{}-{}".format(os, arch)
format: tar.gz
formats: tar.gz
name_template: runu_{{ .Version }}_{{ .Os }}_{{ .Arch }}
builds:
- #@ "runu-{}-{}".format(os, arch)
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ YTT_VERSION ?= v0.51.0
YTT ?= $(GO) run carvel.dev/ytt/cmd/ytt@$(YTT_VERSION)
GORELEASER_VERSION ?= v2.7.0
GORELEASER ?= $(GO) run github.com/goreleaser/goreleaser/v2@$(GORELEASER_VERSION)
GINKGO_VERSION ?= v2.22.0
GINKGO_VERSION ?= v2.22.2
GINKGO ?= $(GO) run github.com/onsi/ginkgo/v2/ginkgo@$(GINKGO_VERSION)

# Misc
Expand Down Expand Up @@ -255,7 +255,7 @@ test: test-unit test-framework test-e2e test-cloud-e2e ## Run all tests.
test-unit: GOTEST_EXCLUDE := third_party/ test/ hack/ buildenvs/ dist/ docs/ tools/
test-unit: GOTEST_PKGS := $(foreach pkg,$(filter-out $(GOTEST_EXCLUDE),$(wildcard */)),$(pkg)...)
test-unit: ## Run unit tests.
$(GINKGO) -v -p -randomize-all -tags "containers_image_storage_stub,containers_image_openpgp" $(GOTEST_PKGS)
$(GINKGO) -v -p -randomize-all -tags "containers_image_storage_stub,containers_image_openpgp" $(GOTEST_PKGS)

.PHONY: test-e2e
test-e2e: kraft ## Run CLI end-to-end tests.
Expand Down
17 changes: 17 additions & 0 deletions exec/process_netbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors.
// Licensed under the BSD-3-Clause License (the "License").
// You may not use this file expect in compliance with the License.
package exec

import (
"syscall"
)

func hostAttributes() *syscall.SysProcAttr {
// the Setpgid flag is used to prevent the child process from exiting when
// the parent is killed
return &syscall.SysProcAttr{
Setpgid: true,
}
}
17 changes: 17 additions & 0 deletions exec/process_openbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors.
// Licensed under the BSD-3-Clause License (the "License").
// You may not use this file expect in compliance with the License.
package exec

import (
"syscall"
)

func hostAttributes() *syscall.SysProcAttr {
// the Setpgid flag is used to prevent the child process from exiting when
// the parent is killed
return &syscall.SysProcAttr{
Setpgid: true,
}
}
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/Masterminds/semver v1.5.0
github.com/Masterminds/semver/v3 v3.3.1
github.com/acorn-io/baaah v0.0.0-20230522221318-afcc93619e30
github.com/anchore/stereoscope v0.0.12
github.com/anchore/stereoscope v0.0.13
github.com/briandowns/spinner v1.23.2
github.com/charmbracelet/bubbles v0.20.0
github.com/charmbracelet/bubbletea v1.3.0
Expand All @@ -27,7 +27,7 @@ require (
github.com/containerd/platforms v1.0.0-rc.1
github.com/containers/image/v5 v5.34.0
github.com/cpuguy83/go-md2man/v2 v2.0.6
github.com/cyphar/filepath-securejoin v0.3.6
github.com/cyphar/filepath-securejoin v0.4.1
github.com/dgraph-io/badger/v3 v3.2103.5
github.com/docker/cli v27.5.1+incompatible
github.com/docker/docker v27.5.1+incompatible
Expand Down Expand Up @@ -58,7 +58,7 @@ require (
github.com/onsi/gomega v1.36.2
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0
github.com/opencontainers/runc v1.2.3
github.com/opencontainers/runc v1.2.5-0.20250205120131-de92f4b40dd5
github.com/opencontainers/runtime-spec v1.2.0
github.com/opencontainers/selinux v1.11.1
github.com/pkg/errors v0.9.1
Expand Down Expand Up @@ -248,7 +248,7 @@ require (
github.com/sigstore/sigstore v1.8.12 // indirect
github.com/skeema/knownhosts v1.3.0 // indirect
github.com/smallstep/pkcs7 v0.1.1 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/afero v1.12.0 // indirect
github.com/stefanberger/go-pkcs11uri v0.0.0-20230803200340-78284954bff6 // indirect
github.com/sylabs/sif/v2 v2.20.2 // indirect
github.com/sylabs/squashfs v1.0.4 // indirect
Expand Down Expand Up @@ -293,7 +293,7 @@ require (
google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250102185135-69823020774d // indirect
google.golang.org/protobuf v1.36.3 // indirect
google.golang.org/protobuf v1.36.4 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
k8s.io/component-base v0.32.1 // indirect
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ github.com/anchore/go-struct-converter v0.0.0-20221118182256-c68fdcfa2092 h1:aM1
github.com/anchore/go-struct-converter v0.0.0-20221118182256-c68fdcfa2092/go.mod h1:rYqSE9HbjzpHTI74vwPvae4ZVYZd1lue2ta6xHPdblA=
github.com/anchore/go-testutils v0.0.0-20200925183923-d5f45b0d3c04 h1:VzprUTpc0vW0nnNKJfJieyH/TZ9UYAnTZs5/gHTdAe8=
github.com/anchore/go-testutils v0.0.0-20200925183923-d5f45b0d3c04/go.mod h1:6dK64g27Qi1qGQZ67gFmBFvEHScy0/C8qhQhNe5B5pQ=
github.com/anchore/stereoscope v0.0.12 h1:ovUWeyeZGml6pTGiu/uha/rCbToANFPu+cnhLbeperY=
github.com/anchore/stereoscope v0.0.12/go.mod h1:cmb/MGya7ccOd6fZZEREuhdSH2kFALBMrkY/66Sfv1o=
github.com/anchore/stereoscope v0.0.13 h1:9Ivkh7k+vOeG3JHrt44jOg/8UdZrCvMsSjLQ7trHBig=
github.com/anchore/stereoscope v0.0.13/go.mod h1:QfhhFc2pezp5aX/dVJ5qnBFpBUv5+KUTphwaQLxMUig=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
Expand Down Expand Up @@ -377,8 +377,8 @@ github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfv
github.com/cyberphone/json-canonicalization v0.0.0-20231217050601-ba74d44ecf5f h1:eHnXnuK47UlSTOQexbzxAZfekVz6i+LKRdj1CU5DPaM=
github.com/cyberphone/json-canonicalization v0.0.0-20231217050601-ba74d44ecf5f/go.mod h1:uzvlm1mxhHkdfqitSA92i7Se+S9ksOn3a3qmv/kyOCw=
github.com/cyphar/filepath-securejoin v0.2.2/go.mod h1:FpkQEhXnPnOthhzymB7CGsFk2G9VLXONKD9G7QGMM+4=
github.com/cyphar/filepath-securejoin v0.3.6 h1:4d9N5ykBnSp5Xn2JkhocYDkOpURL/18CYMpo6xB9uWM=
github.com/cyphar/filepath-securejoin v0.3.6/go.mod h1:Sdj7gXlvMcPZsbhwhQ33GguGLDGQL7h7bg04C/+u9jI=
github.com/cyphar/filepath-securejoin v0.4.1 h1:JyxxyPEaktOD+GAnqIqTf9A8tHyAG22rowi7HkoSU1s=
github.com/cyphar/filepath-securejoin v0.4.1/go.mod h1:Sdj7gXlvMcPZsbhwhQ33GguGLDGQL7h7bg04C/+u9jI=
github.com/d2g/dhcp4 v0.0.0-20170904100407-a1d1b6c41b1c/go.mod h1:Ct2BUK8SB0YC1SMSibvLzxjeJLnrYEVLULFNiHY9YfQ=
github.com/d2g/dhcp4client v1.0.0/go.mod h1:j0hNfjhrt2SxUOw55nL0ATM/z4Yt3t2Kd1mW34z5W5s=
github.com/d2g/dhcp4server v0.0.0-20181031114812-7d4a0a7f59a5/go.mod h1:Eo87+Kg/IX2hfWJfwxMzLyuSZyxSoAug2nGa1G2QAi8=
Expand Down Expand Up @@ -971,8 +971,8 @@ github.com/opencontainers/runc v0.1.1/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59P
github.com/opencontainers/runc v1.0.0-rc8.0.20190926000215-3e425f80a8c9/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U=
github.com/opencontainers/runc v1.0.0-rc9/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U=
github.com/opencontainers/runc v1.0.0-rc93/go.mod h1:3NOsor4w32B2tC0Zbl8Knk4Wg84SM2ImC1fxBuqJ/H0=
github.com/opencontainers/runc v1.2.3 h1:fxE7amCzfZflJO2lHXf4y/y8M1BoAqp+FVmG19oYB80=
github.com/opencontainers/runc v1.2.3/go.mod h1:nSxcWUydXrsBZVYNSkTjoQ/N6rcyTtn+1SD5D4+kRIM=
github.com/opencontainers/runc v1.2.5-0.20250205120131-de92f4b40dd5 h1:zD27DZt1QmdjGqxHsCDMObGyDJu+Sexp9LA0kIdm654=
github.com/opencontainers/runc v1.2.5-0.20250205120131-de92f4b40dd5/go.mod h1:sSb4y8/LK8sTpWYcStm5vPCTvW4E3xWdg/IB4Em4Qks=
github.com/opencontainers/runtime-spec v0.1.2-0.20190507144316-5b71a03e2700/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/opencontainers/runtime-spec v1.0.1/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/opencontainers/runtime-spec v1.0.2-0.20190207185410-29686dbc5559/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
Expand Down Expand Up @@ -1129,8 +1129,8 @@ github.com/spdx/tools-golang v0.5.3 h1:ialnHeEYUC4+hkm5vJm4qz2x+oEJbS0mAMFrNXdQr
github.com/spdx/tools-golang v0.5.3/go.mod h1:/ETOahiAo96Ob0/RAIBmFZw6XN0yTnyr/uFZm2NTMhI=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
github.com/spf13/afero v1.12.0 h1:UcOPyRBYczmFn6yvphxkn9ZEOY65cpwGKb5mL36mrqs=
github.com/spf13/afero v1.12.0/go.mod h1:ZTlWwG4/ahT8W7T0WQ5uYmjI9duaLQGy3Q2OAl4sk/4=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v0.0.2-0.20171109065643-2da4a54c5cee/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
Expand Down Expand Up @@ -1724,8 +1724,8 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.36.3 h1:82DV7MYdb8anAVi3qge1wSnMDrnKK7ebr+I0hHRN1BU=
google.golang.org/protobuf v1.36.3/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
google.golang.org/protobuf v1.36.4 h1:6A3ZDJHn/eNqc1i+IdefRzy/9PokBTPvcqMySR7NNIM=
google.golang.org/protobuf v1.36.4/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
3 changes: 3 additions & 0 deletions initrd/ociimage.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build !openbsd && !netbsd
// +build !openbsd,!netbsd

// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors.
// Licensed under the BSD-3-Clause License (the "License").
Expand Down
36 changes: 36 additions & 0 deletions initrd/ociimage_netbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors.
// Licensed under the BSD-3-Clause License (the "License").
// You may not use this file except in compliance with the License.
package initrd

import (
"context"
)

type ociimage struct{}

// NewFromOCIImage creates a new initrd from a remote container image.
func NewFromOCIImage(ctx context.Context, path string, opts ...InitrdOption) (Initrd, error) {
return nil, nil
}

// Build implements Initrd.
func (initrd *ociimage) Name() string {
return "OCI image"
}

// Build implements Initrd.
func (initrd *ociimage) Build(ctx context.Context) (string, error) {
return "", nil
}

// Env implements Initrd.
func (initrd *ociimage) Env() []string {
return nil
}

// Args implements Initrd.
func (initrd *ociimage) Args() []string {
return nil
}
36 changes: 36 additions & 0 deletions initrd/ociimage_openbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors.
// Licensed under the BSD-3-Clause License (the "License").
// You may not use this file except in compliance with the License.
package initrd

import (
"context"
)

type ociimage struct{}

// NewFromOCIImage creates a new initrd from a remote container image.
func NewFromOCIImage(ctx context.Context, path string, opts ...InitrdOption) (Initrd, error) {
return nil, nil
}

// Build implements Initrd.
func (initrd *ociimage) Name() string {
return "OCI image"
}

// Build implements Initrd.
func (initrd *ociimage) Build(ctx context.Context) (string, error) {
return "", nil
}

// Env implements Initrd.
func (initrd *ociimage) Env() []string {
return nil
}

// Args implements Initrd.
func (initrd *ociimage) Args() []string {
return nil
}
3 changes: 3 additions & 0 deletions initrd/ociimage_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build !openbsd && !netbsd
// +build !openbsd,!netbsd

// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2023, Unikraft GmbH and The KraftKit Authors.
// Licensed under the BSD-3-Clause License (the "License").
Expand Down
18 changes: 15 additions & 3 deletions machine/network/register_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,23 @@
// You may not use this file except in compliance with the License.
package network

var defaultStrategyName = ""
import (
"context"
"errors"

networkv1alpha1 "kraftkit.sh/api/network/v1alpha1"
)

var defaultStrategyName = "bridge"

// hostSupportedStrategies returns the map of known supported drivers for the
// given host.
// Currently stubbed out for FreeBSD.
func hostSupportedStrategies() map[string]*Strategy {
return map[string]*Strategy{}
return map[string]*Strategy{
"bridge": {
NewNetworkV1alpha1: func(ctx context.Context, opts ...any) (networkv1alpha1.NetworkService, error) {
return nil, errors.New("network service is not supported on freeBSD")
},
},
}
}
26 changes: 26 additions & 0 deletions machine/network/register_netbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors.
// Licensed under the BSD-3-Clause License (the "License").
// You may not use this file except in compliance with the License.
package network

import (
"context"
"errors"

networkv1alpha1 "kraftkit.sh/api/network/v1alpha1"
)

var defaultStrategyName = "bridge"

// hostSupportedStrategies returns the map of known supported drivers for the
// given host.
func hostSupportedStrategies() map[string]*Strategy {
return map[string]*Strategy{
"bridge": {
NewNetworkV1alpha1: func(ctx context.Context, opts ...any) (networkv1alpha1.NetworkService, error) {
return nil, errors.New("network service is not supported on netBSD")
},
},
}
}
26 changes: 26 additions & 0 deletions machine/network/register_openbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors.
// Licensed under the BSD-3-Clause License (the "License").
// You may not use this file except in compliance with the License.
package network

import (
"context"
"errors"

networkv1alpha1 "kraftkit.sh/api/network/v1alpha1"
)

var defaultStrategyName = "bridge"

// hostSupportedStrategies returns the map of known supported drivers for the
// given host.
func hostSupportedStrategies() map[string]*Strategy {
return map[string]*Strategy{
"bridge": {
NewNetworkV1alpha1: func(ctx context.Context, opts ...any) (networkv1alpha1.NetworkService, error) {
return nil, errors.New("network service is not supported on openBSD")
},
},
}
}
9 changes: 9 additions & 0 deletions machine/platform/register_netbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors.
// Licensed under the BSD-3-Clause License (the "License").
// You may not use this file except in compliance with the License.
package platform

func unixVariantStrategies() map[Platform]*Strategy {
return map[Platform]*Strategy{}
}
9 changes: 9 additions & 0 deletions machine/platform/register_openbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors.
// Licensed under the BSD-3-Clause License (the "License").
// You may not use this file except in compliance with the License.
package platform

func unixVariantStrategies() map[Platform]*Strategy {
return map[Platform]*Strategy{}
}
3 changes: 3 additions & 0 deletions oci/handler/containerd.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build !openbsd && !netbsd
// +build !openbsd,!netbsd

// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors.
// Licensed under the BSD-3-Clause License (the "License").
Expand Down
Loading

0 comments on commit b6f0b36

Please sign in to comment.