-
Notifications
You must be signed in to change notification settings - Fork 556
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: make some of the extensions package public
Moving the loading and validation to the machinery package, so that we can import and use that from other projects. Co-authored-by: Noel Georgi <[email protected]> Signed-off-by: Andrey Smirnov <[email protected]>
- Loading branch information
Showing
19 changed files
with
159 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
package extensions_test | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/siderolabs/talos/pkg/machinery/extensions" | ||
"github.com/siderolabs/talos/pkg/machinery/version" | ||
) | ||
|
||
func TestLoadValidate(t *testing.T) { | ||
ext, err := extensions.Load("testdata/good/extension1") | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, "gvisor", ext.Manifest.Metadata.Name) | ||
|
||
// override Talos version to make it predictable | ||
oldVersion := version.Tag | ||
version.Tag = "v1.0.0" | ||
|
||
t.Cleanup(func() { | ||
version.Tag = oldVersion | ||
}) | ||
|
||
assert.NoError(t, ext.Validate()) | ||
} | ||
|
||
func TestValidateFailures(t *testing.T) { | ||
// override Talos version to make it predictable | ||
oldVersion := version.Tag | ||
version.Tag = "v1.0.0" | ||
|
||
t.Cleanup(func() { | ||
version.Tag = oldVersion | ||
}) | ||
|
||
for _, tt := range []struct { | ||
name string | ||
loadError string | ||
validateError string | ||
}{ | ||
{ | ||
name: "wrongfiles", | ||
loadError: "unexpected file \"a\"", | ||
}, | ||
{ | ||
name: "emptymanifest", | ||
loadError: "unsupported manifest version: \"\"", | ||
}, | ||
{ | ||
name: "norootfs", | ||
loadError: "extension rootfs is missing", | ||
}, | ||
{ | ||
name: "badpaths", | ||
validateError: "path \"/boot/vmlinuz\" is not allowed in extensions", | ||
}, | ||
} { | ||
t.Run(tt.name, func(t *testing.T) { | ||
ext, err := extensions.Load(filepath.Join("testdata/bad", tt.name)) | ||
|
||
if tt.loadError == "" { | ||
require.NoError(t, err) | ||
} else { | ||
assert.EqualError(t, err, tt.loadError) | ||
} | ||
|
||
if err == nil { | ||
err = ext.Validate() | ||
assert.EqualError(t, err, tt.validateError) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions
10
pkg/machinery/extensions/testdata/good/extension1/manifest.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
version: v1alpha1 | ||
metadata: | ||
name: gvisor | ||
version: 20220117.0-v1.0.0 | ||
author: Andrew Rynhard | ||
description: > | ||
This system extension provides gVisor using containerd's runtime handler. | ||
compatibility: | ||
talos: | ||
version: ">= v1.0.0" |
Empty file.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions
1
pkg/machinery/extensions/testdata/good/extension1/rootfs/usr/local/lib/a.so.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a.so |
Oops, something went wrong.