Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import LXD changes #226

Merged
merged 37 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
270d316
[lxd-import] metrics: Fix label merging in metric sets
monstermunchkin Oct 27, 2023
df66d6e
[lxd-import] test: Check instance type in filesystem metrics
monstermunchkin Oct 30, 2023
363f1f3
[lxd-import] test/includes/certificates: add gen_cert_and_key()
simondeziel Nov 1, 2023
f0b6069
[lxd-import] test/metrics: use gen_cert_and_key function instead of d…
simondeziel Oct 30, 2023
bad53be
[lxd-import] test/remote: use gen_cert_and_key function instead of di…
simondeziel Oct 30, 2023
d3a8274
[lxd-import] test/tls_restrictions: add some double quotes
simondeziel Oct 30, 2023
727e03a
[lxd-import] test/tls_restrictions: fix some comments
simondeziel Oct 30, 2023
14f235f
[lxd-import] test/tls_restrictions: make sure expected failures get t…
simondeziel Oct 31, 2023
4826a3e
[lxd-import] test/tls_restrictions: use gen_cert_and_key function ins…
simondeziel Nov 1, 2023
e5ea42d
[lxd-import] test/tls_restrictions: ensure type=metrics certificates …
simondeziel Oct 30, 2023
2c65ab2
[lxd-import] lxd/device/proxy: Consider routed NIC IPs for wildcard t…
tomponline Nov 4, 2023
aec500e
[lxd-import] lxd/network/driver/bridge: Improve comments for accept_ra
tomponline Nov 4, 2023
c9612b5
[lxd-import] config: Restrict user.* keys
monstermunchkin Oct 31, 2023
d40f730
[lxd-import] test: Validate user.* keys
monstermunchkin Oct 31, 2023
d7049d4
[lxd-import] github: Use Go 1.20 and check for compat with that in go…
simondeziel Oct 31, 2023
80e8271
[lxd-import] github: Removes whitespace
tomponline Nov 5, 2023
9071108
[lxd-import] lxd/incus-doc: Remove noisy log line
tomponline Nov 4, 2023
1894254
[lxd-import] test/lint: Removes openfga model linter.
markylaing Nov 6, 2023
647758e
[lxd-import] test/basic: always use -- with `incus exec`
simondeziel Oct 24, 2023
4337c1c
[lxd-import] test/basic: test with and without "--" separator
simondeziel Nov 6, 2023
477d7c1
[lxd-import] test/clustering: always use -- with `incus exec`
simondeziel Oct 24, 2023
a815cea
[lxd-import] test/config: always use -- with `incus exec`
simondeziel Oct 24, 2023
9dea47f
[lxd-import] test/dev-incus: always use -- with `incus exec`
simondeziel Oct 24, 2023
cf303b8
[lxd-import] test/image_acl: always use -- with `incus exec`
simondeziel Oct 24, 2023
b039833
[lxd-import] test/storage_snapshots: always use -- with `incus exec`
simondeziel Oct 24, 2023
1619b68
[lxd-import] doc/howto/network_ovn_setup: always use -- with `incus e…
simondeziel Oct 24, 2023
c69d5bd
[lxd-import] doc/howto/instances_troubleshoot: always use -- with `lx…
simondeziel Oct 24, 2023
3ed8c3a
[lxd-import] lxd/dev-incus: always use -- with `incus exec`
simondeziel Nov 3, 2023
c9314c8
[lxd-import] doc/requirements: allow linking to Go requirements
simondeziel Oct 31, 2023
5670c23
[lxd-import] doc/installing: link to Go requirements and update Ubunt…
simondeziel Oct 31, 2023
53c4849
[lxd-import] doc/howto/benchmark_performance: link to Go requirements
simondeziel Oct 31, 2023
b48d332
[lxd-import] doc/howto/migrate_from_lxc: link to Go requirements
simondeziel Oct 31, 2023
2766dde
[lxd-import] doc/requirements: Go 1.20 is now the minimum version
simondeziel Nov 6, 2023
4dd424b
[lxd-import] shared/cert: Update code comments about CRL
simondeziel Oct 31, 2023
a0d9779
[lxd-import] lxd/util/http: Check if the CRL was signed by the CA bef…
simondeziel Oct 31, 2023
d91b9dd
[lxd-import] lxc/delete: Include instance name in error message
monstermunchkin Nov 3, 2023
e02e36f
[lxd-import] Update translations
monstermunchkin Nov 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ jobs:
with:
go-version: 1.20.x

- name: Check compatible min Go version
run: |
go mod tidy -go=1.20

- name: Install dependencies
run: |
sudo add-apt-repository ppa:ubuntu-lxc/daily -y --no-update
Expand Down Expand Up @@ -87,7 +91,7 @@ jobs:

- name: Unit tests (all)
run: |
sudo go test ./...
sudo --preserve-env=CGO_CFLAGS,CGO_LDFLAGS,CGO_LDFLAGS_ALLOW,LD_LIBRARY_PATH LD_LIBRARY_PATH=${LD_LIBRARY_PATH} env "PATH=${PATH}" go test ./...

system-tests:
env:
Expand Down Expand Up @@ -234,11 +238,11 @@ jobs:
mkdir -p "$(go env GOPATH)/bin"
curl -sSfL https://dl.min.io/server/minio/release/linux-amd64/minio --output "$(go env GOPATH)/bin/minio"
chmod +x "$(go env GOPATH)/bin/minio"

# Download latest release of openfga server.
curl -s https://api.github.com/repos/openfga/openfga/releases/latest | jq -r '.assets | .[] | .browser_download_url | select(. | test("_linux_amd64.tar.gz$"))' | xargs -I {} curl -L {} -o openfga.tar.gz
tar -xzf openfga.tar.gz -C "$(go env GOPATH)/bin/"

# Download latest release of openfga cli.
curl -s https://api.github.com/repos/openfga/cli/releases/latest | jq -r '.assets | .[] | .browser_download_url | select(. | test("_linux_amd64.tar.gz$"))' | xargs -I {} curl -L {} -o fga.tar.gz
tar -xzf fga.tar.gz -C "$(go env GOPATH)/bin/"
Expand Down Expand Up @@ -393,6 +397,11 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 1.20.x

- name: Install dependencies
run: |
sudo apt-get install aspell aspell-en
Expand Down
7 changes: 6 additions & 1 deletion cmd/incus/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ func (c *cmdDelete) Run(cmd *cobra.Command, args []string) error {

// Process with deletion.
for _, resource := range resources {
connInfo, err := resource.server.GetConnectionInfo()
if err != nil {
return err
}

if c.flagInteractive {
err := c.promptDelete(resource.name)
if err != nil {
Expand Down Expand Up @@ -141,7 +146,7 @@ func (c *cmdDelete) Run(cmd *cobra.Command, args []string) error {

err = c.doDelete(resource.server, resource.name)
if err != nil {
return err
return fmt.Errorf(i18n.G("Failed deleting instance %q in project %q: %w"), resource.name, connInfo.Project, err)
}
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/incusd/dev_incus.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func findContainerForPid(pid int32, s *state.State) (instance.Container, error)
* 1. Walk up the process tree until you see something that looks like
* an lxc monitor process and extract its name from there.
*
* 2. If this fails, it may be that someone did an `lxc exec foo bash`,
* 2. If this fails, it may be that someone did an `incus exec foo -- bash`,
* so the process isn't actually a descendant of the container's
* init. In this case we just look through all the containers until
* we find an init with a matching pid namespace. This is probably
Expand Down
2 changes: 1 addition & 1 deletion doc/howto/benchmark_performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ If you run this tool repeatedly with different configurations, you can compare t
## Get the tool

If the `incus-benchmark` tool isn't provided with your installation, you can build it from source.
Make sure that you have `go` (version 1.20 or later) installed and install the tool with the following command:
Make sure that you have `go` (see {ref}`requirements-go`) installed and install the tool with the following command:

go install github.com/lxc/incus/incus-benchmark@latest

Expand Down
2 changes: 1 addition & 1 deletion doc/howto/instances_troubleshoot.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Console log:
Now that the container has started, you can check it and see that things are not running as well as expected:

```{terminal}
:input: incus exec systemd bash
:input: incus exec systemd -- bash

[root@systemd ~]# ls
[root@systemd ~]# mount
Expand Down
2 changes: 1 addition & 1 deletion doc/howto/migrate_from_lxc.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ However, this tool does not migrate any of the LXC container configuration.
## Get the tool

If the tool isn't provided alongside your Incus installation, you can build it yourself.
Make sure that you have `go` (version 1.18 or later) installed and get the tool with the following command:
Make sure that you have `go` ({ref}`requirements-go`) installed and get the tool with the following command:

go install github.com/lxc/incus/cmd/lxc-to-incus@latest

Expand Down
2 changes: 1 addition & 1 deletion doc/howto/network_ovn_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ In addition, you can add any number of servers to the Incus cluster that run onl
incus launch images:ubuntu/22.04 c3 --network my-ovn
incus launch images:ubuntu/22.04 c4 --network my-ovn
incus list
incus exec c4 bash
incus exec c4 -- bash
ping <IP of c1>
ping <nameserver>
ping6 -n www.example.com
Expand Down
8 changes: 5 additions & 3 deletions doc/installing.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,14 @@ To download a specific build:
Follow these instructions if you want to build and install Incus from the source code.

We recommend having the latest versions of `liblxc` (>= 4.0.0 required)
available for Incus development. Additionally, Incus requires Golang 1.18 or
later to work. On Ubuntu, you can get those with:
available for Incus development. Additionally, Incus requires a modern Golang (see {ref}`requirements-go`)
version to work. On Ubuntu, you can get those with:

```bash
sudo apt update
sudo apt install acl attr autoconf automake dnsmasq-base git golang libacl1-dev libcap-dev liblxc1 liblxc-dev libsqlite3-dev libtool libudev-dev liblz4-dev libuv1-dev make pkg-config rsync squashfs-tools tar tcl xz-utils ebtables
sudo apt install acl attr autoconf automake dnsmasq-base git libacl1-dev libcap-dev liblxc1 liblxc-dev libsqlite3-dev libtool libudev-dev liblz4-dev libuv1-dev make pkg-config rsync squashfs-tools tar tcl xz-utils ebtables
command -v snap >/dev/null || sudo apt-get install snapd
sudo snap install --classic go
```

```{note}
Expand Down
3 changes: 2 additions & 1 deletion doc/requirements.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Requirements

(requirements-go)=
## Go

Incus requires Go 1.18 or higher and is only tested with the Golang compiler.
Incus requires Go 1.20 or higher and is only tested with the Golang compiler.

We recommend having at least 2GiB of RAM to allow the build to complete.

Expand Down
1 change: 0 additions & 1 deletion internal/server/config/generate/incus_doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ func parse(path string, outputJSONPath string, excludedPaths []string) (*doc, er

// Only process go files
if !info.IsDir() && filepath.Ext(path) != ".go" {
log.Printf("Skipping non-golang file: %v", path)
return nil
}

Expand Down
9 changes: 9 additions & 0 deletions internal/server/config/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"reflect"
"sort"
"strconv"
"strings"
"unicode"

internalInstance "github.com/lxc/incus/internal/instance"
"github.com/lxc/incus/shared/util"
Expand Down Expand Up @@ -184,6 +186,13 @@ func (m *Map) update(values map[string]string) ([]string, error) {
func (m *Map) set(name string, value string, initial bool) (bool, error) {
// Bypass schema for user.* keys
if internalInstance.IsUserConfig(name) {
for _, r := range strings.TrimPrefix(name, "user.") {
// Only allow letters, digits, and punctuation characters.
if !unicode.In(r, unicode.Letter, unicode.Digit, unicode.Punct) {
return false, fmt.Errorf("Invalid key name")
}
}

current, ok := m.values[name]
if ok && value == current {
// Value is unchanged
Expand Down
3 changes: 2 additions & 1 deletion internal/server/device/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ func (d *proxy) setupNAT() error {
return err
}

if nicType != "bridged" {
// Check if the instance has a NIC with a static IP that is reachable from the host.
if !util.ValueInSlice(nicType, []string{"bridged", "routed"}) {
continue
}

Expand Down
2 changes: 1 addition & 1 deletion internal/server/instance/drivers/driver_lxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8351,7 +8351,7 @@ func (d *lxc) getFSStats() (*metrics.MetricSet, error) {
FSType string
}

out := metrics.NewMetricSet(map[string]string{"project": d.project.Name, "name": d.name})
out := metrics.NewMetricSet(nil)

mounts, err := os.ReadFile("/proc/mounts")
if err != nil {
Expand Down
16 changes: 13 additions & 3 deletions internal/server/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,24 @@ func (m *MetricSet) AddSamples(metricType MetricType, samples ...Sample) {
m.set[metricType] = append(m.set[metricType], samples...)
}

// Merge merges two MetricSets.
// Merge merges two MetricSets. Missing labels from m's samples are added to all samples in n.
func (m *MetricSet) Merge(metricSet *MetricSet) {
if metricSet == nil {
return
}

for k := range metricSet.set {
m.set[k] = append(m.set[k], metricSet.set[k]...)
for metricType := range metricSet.set {
for _, sample := range metricSet.set[metricType] {
// Add missing labels from m.
for k, v := range m.labels {
_, ok := sample.Labels[k]
if !ok {
sample.Labels[k] = v
}
}

m.set[metricType] = append(m.set[metricType], sample)
}
}
}

Expand Down
18 changes: 18 additions & 0 deletions internal/server/metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,22 @@ func TestMetricSet_FilterSamples(t *testing.T) {

// Should no longer contain the sample.
require.Equal(t, []Sample{}, m.set[CPUSecondsTotal])

m = NewMetricSet(map[string]string{"project": "default"})
m.AddSamples(CPUSecondsTotal, Sample{Value: 10})

n := NewMetricSet(map[string]string{"name": "jammy"})
n.AddSamples(CPUSecondsTotal, Sample{Value: 20})

m.Merge(n)

for _, sample := range m.set[CPUSecondsTotal] {
hasKeys := []string{}

for k := range sample.Labels {
hasKeys = append(hasKeys, k)
}

require.Contains(t, hasKeys, "project")
}
}
10 changes: 9 additions & 1 deletion internal/server/network/driver_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -1052,13 +1052,21 @@ func (n *bridge) setup(oldConfig map[string]string) error {
return err
}

// First set accept_ra to 2 for everything.
// First set accept_ra to 2 for all interfaces (if not disabled).
// This ensures that the host can still receive IPv6 router advertisements even with
// forwarding enabled (which enable below), as the default is to ignore router adverts
// when forward is enabled, and this could render the host unreachable if it uses
// SLAAC generated IPs.
for _, entry := range entries {
// Check that IPv6 router advertisement acceptance is enabled currently.
// If its set to 0 then we don't want to enable, and if its already set to 2 then
// we don't need to do anything.
content, err := os.ReadFile(fmt.Sprintf("/proc/sys/net/ipv6/conf/%s/accept_ra", entry.Name()))
if err == nil && string(content) != "1\n" {
continue
}

// If IPv6 router acceptance is enabled (set to 1) then we now set it to 2.
err = localUtil.SysctlSet(fmt.Sprintf("net/ipv6/conf/%s/accept_ra", entry.Name()), "2")
if err != nil && !os.IsNotExist(err) {
return err
Expand Down
4 changes: 4 additions & 0 deletions internal/server/util/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ func CheckTrustState(cert x509.Certificate, trustedCerts map[string]x509.Certifi
crl := networkCert.CRL()

if crl != nil {
if crl.CheckSignatureFrom(ca) != nil {
return false, "" // CRL not signed by CA
}

for _, revoked := range crl.RevokedCertificates {
if cert.SerialNumber.Cmp(revoked.SerialNumber) == 0 {
return false, "" // Certificate is revoked, so not trusted anymore.
Expand Down
11 changes: 8 additions & 3 deletions po/ber.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: lxd\n"
"Report-Msgid-Bugs-To: lxc-devel@lists.linuxcontainers.org\n"
"POT-Creation-Date: 2023-10-30 10:05+0800\n"
"POT-Creation-Date: 2023-11-10 21:45-0500\n"
"PO-Revision-Date: 2022-03-10 15:10+0000\n"
"Last-Translator: Anonymous <noreply@weblate.org>\n"
"Language-Team: Berber <https://hosted.weblate.org/projects/linux-containers/"
Expand Down Expand Up @@ -2363,6 +2363,11 @@ msgstr ""
msgid "Failed converting token operation to join token: %w"
msgstr ""

#: cmd/incus/delete.go:149
#, c-format
msgid "Failed deleting instance %q in project %q: %w"
msgstr ""

#: cmd/incus/storage_volume.go:511
#, c-format
msgid "Failed deleting source volume after copy: %w"
Expand Down Expand Up @@ -6073,7 +6078,7 @@ msgstr ""
msgid "Stopping instance failed!"
msgstr ""

#: cmd/incus/delete.go:115
#: cmd/incus/delete.go:120
#, c-format
msgid "Stopping the instance failed: %s"
msgstr ""
Expand Down Expand Up @@ -6328,7 +6333,7 @@ msgstr ""
msgid "The following unknown volumes have been found:"
msgstr ""

#: cmd/incus/delete.go:99
#: cmd/incus/delete.go:104
msgid "The instance is currently running, stop it first or pass --force"
msgstr ""

Expand Down
11 changes: 8 additions & 3 deletions po/bg.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: lxd\n"
"Report-Msgid-Bugs-To: lxc-devel@lists.linuxcontainers.org\n"
"POT-Creation-Date: 2023-10-30 10:05+0800\n"
"POT-Creation-Date: 2023-11-10 21:45-0500\n"
"PO-Revision-Date: 2022-03-10 15:09+0000\n"
"Last-Translator: Anonymous <noreply@weblate.org>\n"
"Language-Team: Bulgarian <https://hosted.weblate.org/projects/linux-"
Expand Down Expand Up @@ -2363,6 +2363,11 @@ msgstr ""
msgid "Failed converting token operation to join token: %w"
msgstr ""

#: cmd/incus/delete.go:149
#, c-format
msgid "Failed deleting instance %q in project %q: %w"
msgstr ""

#: cmd/incus/storage_volume.go:511
#, c-format
msgid "Failed deleting source volume after copy: %w"
Expand Down Expand Up @@ -6073,7 +6078,7 @@ msgstr ""
msgid "Stopping instance failed!"
msgstr ""

#: cmd/incus/delete.go:115
#: cmd/incus/delete.go:120
#, c-format
msgid "Stopping the instance failed: %s"
msgstr ""
Expand Down Expand Up @@ -6328,7 +6333,7 @@ msgstr ""
msgid "The following unknown volumes have been found:"
msgstr ""

#: cmd/incus/delete.go:99
#: cmd/incus/delete.go:104
msgid "The instance is currently running, stop it first or pass --force"
msgstr ""

Expand Down
11 changes: 8 additions & 3 deletions po/ca.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: lxd\n"
"Report-Msgid-Bugs-To: lxc-devel@lists.linuxcontainers.org\n"
"POT-Creation-Date: 2023-10-30 10:05+0800\n"
"POT-Creation-Date: 2023-11-10 21:45-0500\n"
"PO-Revision-Date: 2022-03-10 15:10+0000\n"
"Last-Translator: Anonymous <noreply@weblate.org>\n"
"Language-Team: Catalan <https://hosted.weblate.org/projects/linux-containers/"
Expand Down Expand Up @@ -2363,6 +2363,11 @@ msgstr ""
msgid "Failed converting token operation to join token: %w"
msgstr ""

#: cmd/incus/delete.go:149
#, c-format
msgid "Failed deleting instance %q in project %q: %w"
msgstr ""

#: cmd/incus/storage_volume.go:511
#, c-format
msgid "Failed deleting source volume after copy: %w"
Expand Down Expand Up @@ -6073,7 +6078,7 @@ msgstr ""
msgid "Stopping instance failed!"
msgstr ""

#: cmd/incus/delete.go:115
#: cmd/incus/delete.go:120
#, c-format
msgid "Stopping the instance failed: %s"
msgstr ""
Expand Down Expand Up @@ -6328,7 +6333,7 @@ msgstr ""
msgid "The following unknown volumes have been found:"
msgstr ""

#: cmd/incus/delete.go:99
#: cmd/incus/delete.go:104
msgid "The instance is currently running, stop it first or pass --force"
msgstr ""

Expand Down
Loading
Loading