mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-29 20:24:31 +00:00
runtime: unify generated config
We don't need to maintain two generated config.go and even have duplicates between them. Signed-off-by: Peng Tao <bergwolf@hyper.sh>
This commit is contained in:
parent
4f7cc18622
commit
e7c42fbc76
@ -559,17 +559,12 @@ define MAKE_KERNEL_VIRTIOFS_NAME
|
||||
$(if $(findstring uncompressed,$1),vmlinux-virtiofs.container,vmlinuz-virtiofs.container)
|
||||
endef
|
||||
|
||||
GENERATED_CONFIG = $(abspath $(CLI_DIR)/config-generated.go)
|
||||
|
||||
GENERATED_FILES += $(GENERATED_CONFIG)
|
||||
GENERATED_FILES += pkg/katautils/config-settings.go
|
||||
|
||||
$(RUNTIME_OUTPUT): $(SOURCES) $(GENERATED_FILES) $(MAKEFILE_LIST) | show-summary
|
||||
$(QUIET_BUILD)(cd $(RUNTIME_DIR)/ && ln -fs $(GENERATED_CONFIG))
|
||||
$(QUIET_BUILD)(cd $(RUNTIME_DIR) && go build $(KATA_LDFLAGS) $(BUILDFLAGS) -o $@ .)
|
||||
|
||||
$(SHIMV2_OUTPUT): $(SOURCES) $(GENERATED_FILES) $(MAKEFILE_LIST)
|
||||
$(QUIET_BUILD)(cd $(SHIMV2_DIR)/ && ln -fs $(GENERATED_CONFIG))
|
||||
$(QUIET_BUILD)(cd $(SHIMV2_DIR)/ && go build $(KATA_LDFLAGS) $(BUILDFLAGS) -o $@ .)
|
||||
|
||||
$(MONITOR_OUTPUT): $(SOURCES) $(GENERATED_FILES) $(MAKEFILE_LIST) .git-commit
|
||||
@ -612,7 +607,6 @@ ifeq ($(shell id -u), 0)
|
||||
endif
|
||||
|
||||
go-test: $(GENERATED_FILES)
|
||||
$(QUIET_BUILD)(cd $(SHIMV2_DIR)/ && ln -fs $(GENERATED_CONFIG))
|
||||
go clean -testcache
|
||||
go test -v -mod=vendor ./...
|
||||
|
||||
@ -621,7 +615,6 @@ check-go-static:
|
||||
$(QUIET_CHECK)../../ci/go-no-os-exit.sh ./virtcontainers
|
||||
|
||||
coverage:
|
||||
$(QUIET_BUILD)(cd $(SHIMV2_DIR)/ && ln -fs $(GENERATED_CONFIG))
|
||||
go test -v -mod=vendor -covermode=atomic -coverprofile=coverage.txt ./...
|
||||
go tool cover -html=coverage.txt -o coverage.html
|
||||
|
||||
@ -668,7 +661,6 @@ clean:
|
||||
$(NETMON_TARGET) \
|
||||
$(MONITOR) \
|
||||
$(SHIMV2) \
|
||||
$(SHIMV2_DIR)/$(notdir $(GENERATED_CONFIG)) \
|
||||
$(TARGET) \
|
||||
.git-commit .git-commit.tmp
|
||||
|
||||
|
@ -1,40 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2018-2019 Intel Corporation
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
// WARNING: This file is auto-generated - DO NOT EDIT!
|
||||
//
|
||||
// Note that some variables are "var" to allow them to be modified
|
||||
// by the tests.
|
||||
package main
|
||||
|
||||
// name is the name of the runtime
|
||||
const name = "@RUNTIME_NAME@"
|
||||
|
||||
// name of the project
|
||||
const project = "@PROJECT_NAME@"
|
||||
|
||||
// prefix used to denote non-standard CLI commands and options.
|
||||
const projectPrefix = "@PROJECT_TYPE@"
|
||||
|
||||
// original URL for this project
|
||||
const projectURL = "@PROJECT_URL@"
|
||||
|
||||
// Project URL's organisation name
|
||||
const projectORG = "@PROJECT_ORG@"
|
||||
|
||||
const defaultRootDirectory = "@PKGRUNDIR@"
|
||||
|
||||
// commit is the git commit the runtime is compiled from.
|
||||
var commit = "@COMMIT@"
|
||||
|
||||
// version is the runtime version.
|
||||
var version = "@VERSION@"
|
||||
|
||||
// Default config file used by stateless systems.
|
||||
var defaultRuntimeConfiguration = "@CONFIG_PATH@"
|
||||
|
||||
// Alternate config file that takes precedence over
|
||||
// defaultRuntimeConfiguration.
|
||||
var defaultSysConfRuntimeConfiguration = "@SYSCONFIG@"
|
@ -12,6 +12,7 @@ import (
|
||||
shimapi "github.com/containerd/containerd/runtime/v2/shim"
|
||||
|
||||
shim "github.com/kata-containers/kata-containers/src/runtime/pkg/containerd-shim-v2"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/pkg/katautils"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/pkg/types"
|
||||
)
|
||||
|
||||
@ -23,7 +24,7 @@ func shimConfig(config *shimapi.Config) {
|
||||
func main() {
|
||||
|
||||
if len(os.Args) == 2 && os.Args[1] == "--version" {
|
||||
fmt.Printf("%s containerd shim: id: %q, version: %s, commit: %v\n", project, types.DefaultKataRuntimeName, version, commit)
|
||||
fmt.Printf("%s containerd shim: id: %q, version: %s, commit: %v\n", katautils.PROJECT, types.DefaultKataRuntimeName, katautils.VERSION, katautils.COMMIT)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
|
@ -61,9 +61,9 @@ type vmContainerCapableDetails struct {
|
||||
|
||||
const (
|
||||
moduleParamDir = "parameters"
|
||||
successMessageCapable = "System is capable of running " + project
|
||||
successMessageCreate = "System can currently create " + project
|
||||
failMessage = "System is not capable of running " + project
|
||||
successMessageCapable = "System is capable of running " + katautils.PROJECT
|
||||
successMessageCreate = "System can currently create " + katautils.PROJECT
|
||||
failMessage = "System is not capable of running " + katautils.PROJECT
|
||||
kernelPropertyCorrect = "Kernel property value correct"
|
||||
|
||||
// these refer to fields in the procCPUINFO file
|
||||
@ -313,7 +313,7 @@ func genericHostIsVMContainerCapable(details vmContainerCapableDetails) error {
|
||||
var kataCheckCLICommand = cli.Command{
|
||||
Name: "check",
|
||||
Aliases: []string{"kata-check"},
|
||||
Usage: "tests if system can run " + project,
|
||||
Usage: "tests if system can run " + katautils.PROJECT,
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "check-version-only",
|
||||
@ -372,14 +372,14 @@ EXAMPLES:
|
||||
|
||||
$ %s check --only-list-releases --include-all-releases
|
||||
`,
|
||||
project,
|
||||
katautils.PROJECT,
|
||||
noNetworkEnvVar,
|
||||
name,
|
||||
name,
|
||||
name,
|
||||
name,
|
||||
name,
|
||||
name,
|
||||
katautils.NAME,
|
||||
katautils.NAME,
|
||||
katautils.NAME,
|
||||
katautils.NAME,
|
||||
katautils.NAME,
|
||||
katautils.NAME,
|
||||
),
|
||||
|
||||
Action: func(context *cli.Context) error {
|
||||
@ -398,7 +398,7 @@ EXAMPLES:
|
||||
if os.Geteuid() == 0 {
|
||||
kataLog.Warn("Not running network checks as super user")
|
||||
} else {
|
||||
err := HandleReleaseVersions(cmd, version, context.Bool("include-all-releases"))
|
||||
err := HandleReleaseVersions(cmd, katautils.VERSION, context.Bool("include-all-releases"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -13,14 +13,16 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/prometheus/procfs"
|
||||
"github.com/urfave/cli"
|
||||
|
||||
"github.com/kata-containers/kata-containers/src/runtime/pkg/katautils"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/pkg/utils"
|
||||
vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers"
|
||||
exp "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/experimental"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/oci"
|
||||
vcUtils "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/prometheus/procfs"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
// Semantic version for the output of the command.
|
||||
@ -169,8 +171,8 @@ func getMetaInfo() MetaInfo {
|
||||
}
|
||||
|
||||
func getRuntimeInfo(configFile string, config oci.RuntimeConfig) RuntimeInfo {
|
||||
runtimeVersionInfo := constructVersionInfo(version)
|
||||
runtimeVersionInfo.Commit = commit
|
||||
runtimeVersionInfo := constructVersionInfo(katautils.VERSION)
|
||||
runtimeVersionInfo.Commit = katautils.COMMIT
|
||||
|
||||
runtimeVersion := RuntimeVersionInfo{
|
||||
Version: runtimeVersionInfo,
|
||||
|
@ -314,8 +314,8 @@ func getExpectedKernel(config oci.RuntimeConfig) KernelInfo {
|
||||
func getExpectedRuntimeDetails(config oci.RuntimeConfig, configFile string) RuntimeInfo {
|
||||
runtimePath, _ := os.Executable()
|
||||
|
||||
runtimeVersionInfo := constructVersionInfo(version)
|
||||
runtimeVersionInfo.Commit = commit
|
||||
runtimeVersionInfo := constructVersionInfo(katautils.VERSION)
|
||||
runtimeVersionInfo.Commit = katautils.COMMIT
|
||||
return RuntimeInfo{
|
||||
Version: RuntimeVersionInfo{
|
||||
Version: runtimeVersionInfo,
|
||||
|
@ -39,18 +39,18 @@ const arch = goruntime.GOARCH
|
||||
var usage = fmt.Sprintf(`%s runtime
|
||||
|
||||
%s is a command line program for running applications packaged
|
||||
according to the Open Container Initiative (OCI).`, name, name)
|
||||
according to the Open Container Initiative (OCI).`, katautils.NAME, katautils.NAME)
|
||||
|
||||
var notes = fmt.Sprintf(`
|
||||
NOTES:
|
||||
|
||||
- Commands starting "%s-" and options starting "--%s-" are `+project+` extensions.
|
||||
- Commands starting "%s-" and options starting "--%s-" are `+katautils.PROJECT+` extensions.
|
||||
|
||||
URL:
|
||||
|
||||
The canonical URL for this project is: %s
|
||||
|
||||
`, projectPrefix, projectPrefix, projectURL)
|
||||
`, katautils.PROJECTPREFIX, katautils.PROJECTPREFIX, katautils.PROJECTURL)
|
||||
|
||||
// kataLog is the logger used to record all messages
|
||||
var kataLog *logrus.Entry
|
||||
@ -82,7 +82,7 @@ var defaultErrorFile = os.Stderr
|
||||
var runtimeFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "config, kata-config",
|
||||
Usage: project + " config file path",
|
||||
Usage: katautils.PROJECT + " config file path",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "log",
|
||||
@ -96,7 +96,7 @@ var runtimeFlags = []cli.Flag{
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "root",
|
||||
Value: defaultRootDirectory,
|
||||
Value: katautils.DEFAULTROOTDIRECTORY,
|
||||
Usage: "root directory for storage of container state (this should be located in tmpfs)",
|
||||
},
|
||||
cli.StringFlag{
|
||||
@ -145,7 +145,7 @@ var savedCLIErrWriter = cli.ErrWriter
|
||||
|
||||
func init() {
|
||||
kataLog = logrus.WithFields(logrus.Fields{
|
||||
"name": name,
|
||||
"name": katautils.NAME,
|
||||
"source": "runtime",
|
||||
"arch": arch,
|
||||
"pid": os.Getpid(),
|
||||
@ -222,7 +222,7 @@ func beforeSubcommands(c *cli.Context) error {
|
||||
var runtimeConfig oci.RuntimeConfig
|
||||
var err error
|
||||
|
||||
katautils.SetConfigOptions(name, defaultRuntimeConfiguration, defaultSysConfRuntimeConfiguration)
|
||||
katautils.SetConfigOptions(katautils.NAME, katautils.DEFAULTRUNTIMECONFIGURATION, katautils.DEFAULTSYSCONFRUNTIMECONFIGURATION)
|
||||
|
||||
handleShowConfig(c)
|
||||
|
||||
@ -302,8 +302,8 @@ func beforeSubcommands(c *cli.Context) error {
|
||||
args := strings.Join(c.Args(), " ")
|
||||
|
||||
fields := logrus.Fields{
|
||||
"version": version,
|
||||
"commit": commit,
|
||||
"version": katautils.VERSION,
|
||||
"commit": katautils.COMMIT,
|
||||
"arguments": `"` + args + `"`,
|
||||
}
|
||||
|
||||
@ -365,14 +365,14 @@ func commandNotFound(c *cli.Context, command string) {
|
||||
func makeVersionString() string {
|
||||
v := make([]string, 0, 3)
|
||||
|
||||
versionStr := version
|
||||
versionStr := katautils.VERSION
|
||||
if versionStr == "" {
|
||||
versionStr = unknown
|
||||
}
|
||||
|
||||
v = append(v, name+" : "+versionStr)
|
||||
v = append(v, katautils.NAME+" : "+versionStr)
|
||||
|
||||
commitStr := commit
|
||||
commitStr := katautils.COMMIT
|
||||
if commitStr == "" {
|
||||
commitStr = unknown
|
||||
}
|
||||
@ -411,7 +411,7 @@ func setCLIGlobals() {
|
||||
func createRuntimeApp(ctx context.Context, args []string) error {
|
||||
app := cli.NewApp()
|
||||
|
||||
app.Name = name
|
||||
app.Name = katautils.NAME
|
||||
app.Writer = defaultOutputFile
|
||||
app.Usage = usage
|
||||
app.CommandNotFound = runtimeCommandNotFound
|
||||
|
@ -57,19 +57,19 @@ var (
|
||||
var testingImpl = &vcmock.VCMock{}
|
||||
|
||||
func init() {
|
||||
if version == "" {
|
||||
if katautils.VERSION == "" {
|
||||
panic("ERROR: invalid build: version not set")
|
||||
}
|
||||
|
||||
if commit == "" {
|
||||
if katautils.COMMIT == "" {
|
||||
panic("ERROR: invalid build: commit not set")
|
||||
}
|
||||
|
||||
if defaultSysConfRuntimeConfiguration == "" {
|
||||
if katautils.DEFAULTSYSCONFRUNTIMECONFIGURATION == "" {
|
||||
panic("ERROR: invalid build: defaultSysConfRuntimeConfiguration not set")
|
||||
}
|
||||
|
||||
if defaultRuntimeConfiguration == "" {
|
||||
if katautils.DEFAULTRUNTIMECONFIGURATION == "" {
|
||||
panic("ERROR: invalid build: defaultRuntimeConfiguration not set")
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ func init() {
|
||||
var err error
|
||||
|
||||
fmt.Printf("INFO: creating test directory\n")
|
||||
testDir, err = ioutil.TempDir("", fmt.Sprintf("%s-", name))
|
||||
testDir, err = ioutil.TempDir("", fmt.Sprintf("%s-", katautils.NAME))
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("ERROR: failed to create test directory: %v", err))
|
||||
}
|
||||
@ -153,8 +153,8 @@ func runUnitTests(m *testing.M) {
|
||||
func TestMain(m *testing.M) {
|
||||
// If the test binary name is kata-runtime.coverage, we've are being asked to
|
||||
// run the coverage-instrumented kata-runtime.
|
||||
if path.Base(os.Args[0]) == name+".coverage" ||
|
||||
path.Base(os.Args[0]) == name {
|
||||
if path.Base(os.Args[0]) == katautils.NAME+".coverage" ||
|
||||
path.Base(os.Args[0]) == katautils.NAME {
|
||||
main()
|
||||
exit(0)
|
||||
}
|
||||
@ -666,9 +666,9 @@ func TestMainBeforeSubCommandsShowCCConfigPaths(t *testing.T) {
|
||||
for i, line := range lines {
|
||||
switch i {
|
||||
case 0:
|
||||
assert.Equal(line, defaultSysConfRuntimeConfiguration)
|
||||
assert.Equal(line, katautils.DEFAULTSYSCONFRUNTIMECONFIGURATION)
|
||||
case 1:
|
||||
assert.Equal(line, defaultRuntimeConfiguration)
|
||||
assert.Equal(line, katautils.DEFAULTRUNTIMECONFIGURATION)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -715,7 +715,7 @@ func testVersionString(assert *assert.Assertions, versionString, expectedVersion
|
||||
foundCommit := false
|
||||
foundOCIVersion := false
|
||||
|
||||
versionRE := regexp.MustCompile(fmt.Sprintf(`%s\s*:\s*%v`, name, expectedVersion))
|
||||
versionRE := regexp.MustCompile(fmt.Sprintf(`%s\s*:\s*%v`, katautils.NAME, expectedVersion))
|
||||
commitRE := regexp.MustCompile(fmt.Sprintf(`%s\s*:\s*%v`, "commit", expectedCommit))
|
||||
|
||||
ociRE := regexp.MustCompile(fmt.Sprintf(`%s\s*:\s*%v`, "OCI specs", expectedOCIVersion))
|
||||
@ -753,37 +753,37 @@ func TestMainMakeVersionString(t *testing.T) {
|
||||
|
||||
v := makeVersionString()
|
||||
|
||||
testVersionString(assert, v, version, commit, specs.Version)
|
||||
testVersionString(assert, v, katautils.VERSION, katautils.COMMIT, specs.Version)
|
||||
}
|
||||
|
||||
func TestMainMakeVersionStringNoVersion(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
savedVersion := version
|
||||
version = ""
|
||||
savedVersion := katautils.VERSION
|
||||
katautils.VERSION = ""
|
||||
|
||||
defer func() {
|
||||
version = savedVersion
|
||||
katautils.VERSION = savedVersion
|
||||
}()
|
||||
|
||||
v := makeVersionString()
|
||||
|
||||
testVersionString(assert, v, unknown, commit, specs.Version)
|
||||
testVersionString(assert, v, unknown, katautils.COMMIT, specs.Version)
|
||||
}
|
||||
|
||||
func TestMainMakeVersionStringNoCommit(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
savedCommit := commit
|
||||
commit = ""
|
||||
savedCommit := katautils.COMMIT
|
||||
katautils.COMMIT = ""
|
||||
|
||||
defer func() {
|
||||
commit = savedCommit
|
||||
katautils.COMMIT = savedCommit
|
||||
}()
|
||||
|
||||
v := makeVersionString()
|
||||
|
||||
testVersionString(assert, v, version, unknown, specs.Version)
|
||||
testVersionString(assert, v, katautils.VERSION, unknown, specs.Version)
|
||||
}
|
||||
|
||||
func TestMainMakeVersionStringNoOCIVersion(t *testing.T) {
|
||||
@ -798,7 +798,7 @@ func TestMainMakeVersionStringNoOCIVersion(t *testing.T) {
|
||||
|
||||
v := makeVersionString()
|
||||
|
||||
testVersionString(assert, v, version, commit, unknown)
|
||||
testVersionString(assert, v, katautils.VERSION, katautils.COMMIT, unknown)
|
||||
}
|
||||
|
||||
func TestMainCreateRuntimeApp(t *testing.T) {
|
||||
@ -824,7 +824,7 @@ func TestMainCreateRuntimeApp(t *testing.T) {
|
||||
defaultOutputFile = savedOutputFile
|
||||
}()
|
||||
|
||||
args := []string{name}
|
||||
args := []string{katautils.NAME}
|
||||
|
||||
err = createRuntimeApp(context.Background(), args)
|
||||
assert.NoError(err, "%v", args)
|
||||
@ -849,7 +849,7 @@ func TestMainCreateRuntimeAppInvalidSubCommand(t *testing.T) {
|
||||
}()
|
||||
|
||||
// calls fatal() so no return
|
||||
_ = createRuntimeApp(context.Background(), []string{name, "i-am-an-invalid-sub-command"})
|
||||
_ = createRuntimeApp(context.Background(), []string{katautils.NAME, "i-am-an-invalid-sub-command"})
|
||||
|
||||
assert.NotEqual(exitStatus, 0)
|
||||
}
|
||||
@ -869,7 +869,7 @@ func TestMainCreateRuntime(t *testing.T) {
|
||||
savedBefore := runtimeBeforeSubcommands
|
||||
savedCommands := runtimeCommands
|
||||
|
||||
os.Args = []string{name, cmd}
|
||||
os.Args = []string{katautils.NAME, cmd}
|
||||
exitFunc = func(status int) { exitStatus = status }
|
||||
|
||||
// disable
|
||||
@ -920,10 +920,10 @@ func TestMainVersionPrinter(t *testing.T) {
|
||||
|
||||
setCLIGlobals()
|
||||
|
||||
err = createRuntimeApp(context.Background(), []string{name, "--version"})
|
||||
err = createRuntimeApp(context.Background(), []string{katautils.NAME, "--version"})
|
||||
assert.NoError(err)
|
||||
|
||||
err = grep(fmt.Sprintf(`%s\s*:\s*%s`, name, version), output)
|
||||
err = grep(fmt.Sprintf(`%s\s*:\s*%s`, katautils.NAME, katautils.VERSION), output)
|
||||
assert.NoError(err)
|
||||
}
|
||||
|
||||
@ -968,7 +968,7 @@ func TestMainFatalWriter(t *testing.T) {
|
||||
|
||||
setCLIGlobals()
|
||||
|
||||
err := createRuntimeApp(context.Background(), []string{name, cmd})
|
||||
err := createRuntimeApp(context.Background(), []string{katautils.NAME, cmd})
|
||||
assert.Error(err)
|
||||
|
||||
re := regexp.MustCompile(
|
||||
|
@ -16,6 +16,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/blang/semver"
|
||||
|
||||
"github.com/kata-containers/kata-containers/src/runtime/pkg/katautils"
|
||||
)
|
||||
|
||||
type ReleaseCmd int
|
||||
@ -29,7 +31,7 @@ type releaseDetails struct {
|
||||
|
||||
const (
|
||||
// A release URL is expected to be prefixed with this value
|
||||
projectAPIURL = "https://api.github.com/repos/" + projectORG
|
||||
projectAPIURL = "https://api.github.com/repos/" + katautils.PROJECTORG
|
||||
|
||||
releasesSuffix = "/releases"
|
||||
downloadsSuffix = releasesSuffix + "/download"
|
||||
@ -37,12 +39,12 @@ const (
|
||||
// Kata 1.x
|
||||
kata1xRepo = "runtime"
|
||||
kataLegacyReleaseURL = projectAPIURL + "/" + kata1xRepo + releasesSuffix
|
||||
kataLegacyDownloadURL = projectURL + "/" + kata1xRepo + downloadsSuffix
|
||||
kataLegacyDownloadURL = katautils.PROJECTURL + "/" + kata1xRepo + downloadsSuffix
|
||||
|
||||
// Kata 2.x or newer
|
||||
kata2xRepo = "kata-containers"
|
||||
kataReleaseURL = projectAPIURL + "/" + kata2xRepo + releasesSuffix
|
||||
kataDownloadURL = projectURL + "/" + kata2xRepo + downloadsSuffix
|
||||
kataDownloadURL = katautils.PROJECTURL + "/" + kata2xRepo + downloadsSuffix
|
||||
|
||||
// Environment variable that can be used to override a release URL
|
||||
ReleaseURLEnvVar = "KATA_RELEASE_URL"
|
||||
@ -377,7 +379,7 @@ func HandleReleaseVersions(cmd ReleaseCmd, currentVersion string, includeAll boo
|
||||
|
||||
currentSemver, err := semver.Make(currentVersion)
|
||||
if err != nil {
|
||||
return fmt.Errorf("BUG: Current version of %s (%s) has invalid SemVer version: %v", name, currentVersion, err)
|
||||
return fmt.Errorf("BUG: Current version of %s (%s) has invalid SemVer version: %v", katautils.NAME, currentVersion, err)
|
||||
}
|
||||
|
||||
releaseURL, err := getReleaseURL(currentSemver)
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/blang/semver"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/pkg/katautils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@ -20,7 +21,7 @@ var expectedReleasesURL string
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
currentSemver, err = semver.Make(version)
|
||||
currentSemver, err = semver.Make(katautils.VERSION)
|
||||
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to create semver for testing: %v", err))
|
||||
@ -307,7 +308,7 @@ func TestDownloadURLIsValid(t *testing.T) {
|
||||
{"foo", true},
|
||||
{"foo bar", true},
|
||||
{"https://google.com", true},
|
||||
{projectURL, true},
|
||||
{katautils.PROJECTURL, true},
|
||||
{validKata1xDownload, false},
|
||||
{validKata2xDownload, false},
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
// Copyright (c) 2018 Intel Corporation
|
||||
// Copyright (c) 2018 HyperHQ Inc.
|
||||
// Copyright (c) 2021 Ant Group
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
@ -8,6 +9,35 @@
|
||||
|
||||
package katautils
|
||||
|
||||
// name is the name of the runtime
|
||||
var NAME = "@RUNTIME_NAME@"
|
||||
|
||||
// name of the project
|
||||
const PROJECT = "@PROJECT_NAME@"
|
||||
|
||||
// prefix used to denote non-standard CLI commands and options.
|
||||
const PROJECTPREFIX = "@PROJECT_TYPE@"
|
||||
|
||||
// original URL for this project
|
||||
const PROJECTURL = "@PROJECT_URL@"
|
||||
|
||||
// Project URL's organisation name
|
||||
const PROJECTORG = "@PROJECT_ORG@"
|
||||
|
||||
const DEFAULTROOTDIRECTORY = "@PKGRUNDIR@"
|
||||
|
||||
// commit is the git commit the runtime is compiled from.
|
||||
var COMMIT = "@COMMIT@"
|
||||
|
||||
// version is the runtime version.
|
||||
var VERSION = "@VERSION@"
|
||||
|
||||
// Default config file used by stateless systems.
|
||||
var DEFAULTRUNTIMECONFIGURATION = "@CONFIG_PATH@"
|
||||
|
||||
// Alternate config file that takes precedence over
|
||||
// defaultRuntimeConfiguration.
|
||||
var DEFAULTSYSCONFRUNTIMECONFIGURATION = "@SYSCONFIG@"
|
||||
var defaultHypervisorPath = "/usr/bin/qemu-system-x86_64"
|
||||
var defaultHypervisorCtlPath = "/usr/bin/acrnctl"
|
||||
var defaultJailerPath = "/usr/bin/jailer"
|
||||
@ -65,9 +95,4 @@ const defaultVMCacheEndpoint string = "/var/run/kata-containers/cache.sock"
|
||||
// Default config file used by stateless systems.
|
||||
var defaultRuntimeConfiguration = "@CONFIG_PATH@"
|
||||
|
||||
// Alternate config file that takes precedence over
|
||||
// defaultRuntimeConfiguration.
|
||||
var defaultSysConfRuntimeConfiguration = "@SYSCONFIG@"
|
||||
|
||||
var name = "kata"
|
||||
var defaultNetmonPath = "/usr/libexec/kata-containers/kata-netmon"
|
||||
|
@ -1343,7 +1343,7 @@ func checkHypervisorConfig(config vc.HypervisorConfig) error {
|
||||
func GetDefaultConfigFilePaths() []string {
|
||||
return []string{
|
||||
// normally below "/etc"
|
||||
defaultSysConfRuntimeConfiguration,
|
||||
DEFAULTSYSCONFRUNTIMECONFIGURATION,
|
||||
|
||||
// normally below "/usr/share"
|
||||
defaultRuntimeConfiguration,
|
||||
@ -1371,7 +1371,7 @@ func getDefaultConfigFile() (string, error) {
|
||||
// SetConfigOptions will override some of the defaults settings.
|
||||
func SetConfigOptions(n, runtimeConfig, sysRuntimeConfig string) {
|
||||
if n != "" {
|
||||
name = n
|
||||
NAME = n
|
||||
}
|
||||
|
||||
if runtimeConfig != "" {
|
||||
@ -1379,6 +1379,6 @@ func SetConfigOptions(n, runtimeConfig, sysRuntimeConfig string) {
|
||||
}
|
||||
|
||||
if sysRuntimeConfig != "" {
|
||||
defaultSysConfRuntimeConfiguration = sysRuntimeConfig
|
||||
DEFAULTSYSCONFRUNTIMECONFIGURATION = sysRuntimeConfig
|
||||
}
|
||||
}
|
||||
|
@ -250,7 +250,7 @@ func testLoadConfiguration(t *testing.T, dir string,
|
||||
|
||||
// override
|
||||
defaultRuntimeConfiguration = testConfig.ConfigPath
|
||||
defaultSysConfRuntimeConfiguration = ""
|
||||
DEFAULTSYSCONFRUNTIMECONFIGURATION = ""
|
||||
|
||||
for _, file := range configFiles {
|
||||
var err error
|
||||
@ -1193,24 +1193,24 @@ func TestGetDefaultConfigFile(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
|
||||
savedConf := defaultRuntimeConfiguration
|
||||
savedSysConf := defaultSysConfRuntimeConfiguration
|
||||
savedSysConf := DEFAULTSYSCONFRUNTIMECONFIGURATION
|
||||
|
||||
defaultRuntimeConfiguration = confDirConfig.ConfigPath
|
||||
defaultSysConfRuntimeConfiguration = sysConfDirConfig.ConfigPath
|
||||
DEFAULTSYSCONFRUNTIMECONFIGURATION = sysConfDirConfig.ConfigPath
|
||||
|
||||
defer func() {
|
||||
defaultRuntimeConfiguration = savedConf
|
||||
defaultSysConfRuntimeConfiguration = savedSysConf
|
||||
DEFAULTSYSCONFRUNTIMECONFIGURATION = savedSysConf
|
||||
|
||||
}()
|
||||
|
||||
got, err := getDefaultConfigFile()
|
||||
assert.NoError(err)
|
||||
// defaultSysConfRuntimeConfiguration has priority over defaultRuntimeConfiguration
|
||||
assert.Equal(got, defaultSysConfRuntimeConfiguration)
|
||||
// DEFAULTSYSCONFRUNTIMECONFIGURATION has priority over defaultRuntimeConfiguration
|
||||
assert.Equal(got, DEFAULTSYSCONFRUNTIMECONFIGURATION)
|
||||
|
||||
// force defaultRuntimeConfiguration to be returned
|
||||
os.Remove(defaultSysConfRuntimeConfiguration)
|
||||
os.Remove(DEFAULTSYSCONFRUNTIMECONFIGURATION)
|
||||
|
||||
got, err = getDefaultConfigFile()
|
||||
assert.NoError(err)
|
||||
|
@ -161,7 +161,7 @@ func findLastParam(key string, params []vc.Param) (string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("no param called %q found", name)
|
||||
return "", fmt.Errorf("no param called %q found", NAME)
|
||||
}
|
||||
|
||||
func TestSetEphemeralStorageType(t *testing.T) {
|
||||
|
@ -61,7 +61,7 @@ func (h *sysLogHook) Fire(e *logrus.Entry) (err error) {
|
||||
}
|
||||
|
||||
func newSystemLogHook(network, raddr string) (*sysLogHook, error) {
|
||||
hook, err := lSyslog.NewSyslogHook(network, raddr, syslog.LOG_INFO, name)
|
||||
hook, err := lSyslog.NewSyslogHook(network, raddr, syslog.LOG_INFO, NAME)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ func init() {
|
||||
var err error
|
||||
|
||||
fmt.Printf("INFO: creating test directory\n")
|
||||
testDir, err = ioutil.TempDir("", fmt.Sprintf("%s-", name))
|
||||
testDir, err = ioutil.TempDir("", fmt.Sprintf("%s-", NAME))
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("ERROR: failed to create test directory: %v", err))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user