Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit a707608

Browse files
author
James O. D. Hunt
committed
kata-check: check for newer release
Update `kata-check` to see if there is a newer version available for download. Useful for users installing static packages (without a package manager). Fixes: #2975. Signed-off-by: James O. D. Hunt <[email protected]>
1 parent 911a495 commit a707608

File tree

5 files changed

+994
-3
lines changed

5 files changed

+994
-3
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ include $(ARCH_FILE)
4343
PROJECT_TYPE = kata
4444
PROJECT_NAME = Kata Containers
4545
PROJECT_TAG = kata-containers
46-
PROJECT_URL = https://github.com/kata-containers
46+
PROJECT_ORG = $(PROJECT_TAG)
47+
PROJECT_URL = https://github.com/$(PROJECT_ORG)
4748
PROJECT_BUG_URL = $(PROJECT_URL)/kata-containers/issues/new
4849

4950
# list of scripts to install
@@ -622,6 +623,7 @@ $(GENERATED_FILES): %: %.in $(MAKEFILE_LIST) VERSION .git-commit
622623
-e "s|@PROXYPATH@|$(PROXYPATH)|g" \
623624
-e "s|@NETMONPATH@|$(NETMONPATH)|g" \
624625
-e "s|@PROJECT_BUG_URL@|$(PROJECT_BUG_URL)|g" \
626+
-e "s|@PROJECT_ORG@|$(PROJECT_ORG)|g" \
625627
-e "s|@PROJECT_URL@|$(PROJECT_URL)|g" \
626628
-e "s|@PROJECT_NAME@|$(PROJECT_NAME)|g" \
627629
-e "s|@PROJECT_TAG@|$(PROJECT_TAG)|g" \

cli/config-generated.go.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ const projectPrefix = "@PROJECT_TYPE@"
2525
// original URL for this project
2626
const projectURL = "@PROJECT_URL@"
2727

28+
// Project URL's organisation name
29+
const projectORG = "@PROJECT_ORG@"
30+
2831
const defaultRootDirectory = "@PKGRUNDIR@"
2932

3033
// commit is the git commit the runtime is compiled from.

cli/kata-check.go

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ const (
7171
genericCPUFlagsTag = "flags" // nolint: varcheck, unused, deadcode
7272
genericCPUVendorField = "vendor_id" // nolint: varcheck, unused, deadcode
7373
genericCPUModelField = "model name" // nolint: varcheck, unused, deadcode
74+
75+
// If set, do not perform any network checks
76+
noNetworkEnvVar = "KATA_CHECK_NO_NETWORK"
7477
)
7578

7679
// variables rather than consts to allow tests to modify them
@@ -307,14 +310,71 @@ var kataCheckCLICommand = cli.Command{
307310
Usage: "tests if system can run " + project,
308311
Flags: []cli.Flag{
309312
cli.BoolFlag{
310-
Name: "verbose, v",
311-
Usage: "display the list of checks performed",
313+
Name: "check-version-only",
314+
Usage: "Only compare the current and latest available versions (requires network, non-root only)",
315+
},
316+
cli.BoolFlag{
317+
Name: "include-all-releases",
318+
Usage: "Don't filter out pre-release release versions",
319+
},
320+
cli.BoolFlag{
321+
Name: "no-network-checks, n",
322+
Usage: "Do not run any checks using the network",
323+
},
324+
cli.BoolFlag{
325+
Name: "only-list-releases",
326+
Usage: "Only list newer available releases (non-root only)",
312327
},
313328
cli.BoolFlag{
314329
Name: "strict, s",
315330
Usage: "perform strict checking",
316331
},
332+
cli.BoolFlag{
333+
Name: "verbose, v",
334+
Usage: "display the list of checks performed",
335+
},
317336
},
337+
Description: fmt.Sprintf(`tests if system can run %s and version is current.
338+
339+
ENVIRONMENT VARIABLES:
340+
341+
- %s: If set to any value, act as if "--no-network-checks" was specified.
342+
343+
EXAMPLES:
344+
345+
- Perform basic checks:
346+
347+
$ %s %s
348+
349+
- Local basic checks only:
350+
351+
$ %s %s --no-network-checks
352+
353+
- Perform further checks:
354+
355+
$ sudo %s %s
356+
357+
- Just check if a newer version is available:
358+
359+
$ %s %s --check-version-only
360+
361+
- List available releases (shows output in format "version;release-date;url"):
362+
363+
$ %s %s --only-list-releases
364+
365+
- List all available releases (includes pre-release versions):
366+
367+
$ %s %s --only-list-releases --include-all-releases
368+
`,
369+
project,
370+
noNetworkEnvVar,
371+
name, checkCmd,
372+
name, checkCmd,
373+
name, checkCmd,
374+
name, checkCmd,
375+
name, checkCmd,
376+
name, checkCmd,
377+
),
318378

319379
Action: func(context *cli.Context) error {
320380
verbose := context.Bool("verbose")
@@ -329,6 +389,28 @@ var kataCheckCLICommand = cli.Command{
329389
span, _ := katautils.Trace(ctx, "kata-check")
330390
defer span.Finish()
331391

392+
if !context.Bool("no-network-checks") && os.Getenv(noNetworkEnvVar) == "" {
393+
cmd := RelCmdCheck
394+
395+
if context.Bool("only-list-releases") {
396+
cmd = RelCmdList
397+
}
398+
399+
if os.Geteuid() == 0 {
400+
kataLog.Warn("Not running network checks as super user")
401+
} else {
402+
403+
err = HandleReleaseVersions(cmd, version, context.Bool("include-all-releases"))
404+
if err != nil {
405+
return err
406+
}
407+
}
408+
}
409+
410+
if context.Bool("check-version-only") || context.Bool("only-list-releases") {
411+
return nil
412+
}
413+
332414
runtimeConfig, ok := context.App.Metadata["runtimeConfig"].(oci.RuntimeConfig)
333415
if !ok {
334416
return errors.New("kata-check: cannot determine runtime config")

0 commit comments

Comments
 (0)