17755: Merge branch 'main' into 17755-add-singularity-to-compute-image
[arvados.git] / lib / config / cmd.go
index 1ea0883ac84730738981cb499fe874983fda6ca5..8e638e6ecb4cc712a7ba08f68c09ea2c33b189fc 100644 (file)
@@ -12,7 +12,6 @@ import (
        "os"
        "os/exec"
 
-       "git.arvados.org/arvados.git/sdk/go/arvados"
        "git.arvados.org/arvados.git/sdk/go/ctxlog"
        "github.com/ghodss/yaml"
        "github.com/sirupsen/logrus"
@@ -91,6 +90,7 @@ func (checkCommand) RunCommand(prog string, args []string, stdin io.Reader, stdo
        flags := flag.NewFlagSet("", flag.ContinueOnError)
        flags.SetOutput(stderr)
        loader.SetupFlags(flags)
+       strict := flags.Bool("strict", true, "Strict validation of configuration file (warnings result in non-zero exit code)")
 
        err = flags.Parse(args)
        if err == flag.ErrHelp {
@@ -119,16 +119,15 @@ func (checkCommand) RunCommand(prog string, args []string, stdin io.Reader, stdo
        if err != nil {
                return 1
        }
+       // Reset() to avoid printing the same warnings twice when they
+       // are logged by both without-legacy and with-legacy loads.
+       logbuf.Reset()
        loader.SkipDeprecated = false
        loader.SkipLegacy = false
        withDepr, err := loader.Load()
        if err != nil {
                return 1
        }
-       problems := false
-       if warnAboutProblems(logger, withDepr) {
-               problems = true
-       }
        cmd := exec.Command("diff", "-u", "--label", "without-deprecated-configs", "--label", "relying-on-deprecated-configs", "/dev/fd/3", "/dev/fd/4")
        for _, obj := range []interface{}{withoutDepr, withDepr} {
                y, _ := yaml.Marshal(obj)
@@ -148,36 +147,23 @@ func (checkCommand) RunCommand(prog string, args []string, stdin io.Reader, stdo
                fmt.Fprintln(stdout, "Your configuration is relying on deprecated entries. Suggest making the following changes.")
                stdout.Write(diff)
                err = nil
-               return 1
+               if *strict {
+                       return 1
+               }
        } else if len(diff) > 0 {
                fmt.Fprintf(stderr, "Unexpected diff output:\n%s", diff)
-               return 1
+               if *strict {
+                       return 1
+               }
        } else if err != nil {
                return 1
        }
        if logbuf.Len() > 0 {
-               return 1
-       }
-
-       if problems {
-               return 1
-       }
-       return 0
-}
-
-func warnAboutProblems(logger logrus.FieldLogger, cfg *arvados.Config) bool {
-       warned := false
-       for id, cc := range cfg.Clusters {
-               if cc.SystemRootToken == "" {
-                       logger.Warnf("Clusters.%s.SystemRootToken is empty; see https://doc.arvados.org/master/install/install-keepstore.html", id)
-                       warned = true
-               }
-               if cc.ManagementToken == "" {
-                       logger.Warnf("Clusters.%s.ManagementToken is empty; see https://doc.arvados.org/admin/management-token.html", id)
-                       warned = true
+               if *strict {
+                       return 1
                }
        }
-       return warned
+       return 0
 }
 
 var DumpDefaultsCommand defaultsCommand