X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/0d11f61ddd0bee6a679956ef2c15b868fa825add..10b08e0c05d176775c4f0cf13f6e77025bb1e636:/lib/config/cmd.go diff --git a/lib/config/cmd.go b/lib/config/cmd.go index 1ca278391a..528d748c86 100644 --- a/lib/config/cmd.go +++ b/lib/config/cmd.go @@ -6,14 +6,16 @@ package config import ( "bytes" + "errors" "flag" "fmt" "io" "os" "os/exec" - "git.curoverse.com/arvados.git/sdk/go/arvados" - "git.curoverse.com/arvados.git/sdk/go/ctxlog" + "git.arvados.org/arvados.git/lib/cmd" + "git.arvados.org/arvados.git/sdk/go/arvados" + "git.arvados.org/arvados.git/sdk/go/ctxlog" "github.com/ghodss/yaml" "github.com/sirupsen/logrus" ) @@ -36,22 +38,11 @@ func (dumpCommand) RunCommand(prog string, args []string, stdin io.Reader, stdou } flags := flag.NewFlagSet("", flag.ContinueOnError) - flags.SetOutput(stderr) loader.SetupFlags(flags) - err = flags.Parse(args) - if err == flag.ErrHelp { - err = nil - return 0 - } else if err != nil { - return 2 + if ok, code := cmd.ParseFlags(flags, prog, args, "", stderr); !ok { + return code } - - if len(flags.Args()) != 0 { - flags.Usage() - return 2 - } - cfg, err := loader.Load() if err != nil { return 1 @@ -88,21 +79,11 @@ func (checkCommand) RunCommand(prog string, args []string, stdin io.Reader, stdo Logger: logger, } - flags := flag.NewFlagSet("", flag.ContinueOnError) - flags.SetOutput(stderr) + flags := flag.NewFlagSet(prog, flag.ContinueOnError) loader.SetupFlags(flags) - - err = flags.Parse(args) - if err == flag.ErrHelp { - err = nil - return 0 - } else if err != nil { - return 2 - } - - if len(flags.Args()) != 0 { - flags.Usage() - return 2 + strict := flags.Bool("strict", true, "Strict validation of configuration file (warnings result in non-zero exit code)") + if ok, code := cmd.ParseFlags(flags, prog, args, "", stderr); !ok { + return code } // Load the config twice -- once without loading deprecated @@ -119,16 +100,43 @@ 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 + + // Check for configured vocabulary validity. + for id, cc := range withDepr.Clusters { + if cc.API.VocabularyPath == "" { + continue + } + vd, err := os.ReadFile(cc.API.VocabularyPath) + if err != nil { + if errors.Is(err, os.ErrNotExist) { + // If the vocabulary path doesn't exist, it might mean that + // the current node isn't the controller; so it's not an + // error. + continue + } + logger.Errorf("Error reading vocabulary file %q for cluster %s: %s\n", cc.API.VocabularyPath, id, err) + continue + } + mk := make([]string, 0, len(cc.Collections.ManagedProperties)) + for k := range cc.Collections.ManagedProperties { + mk = append(mk, k) + } + _, err = arvados.NewVocabulary(vd, mk) + if err != nil { + logger.Errorf("Error loading vocabulary file %q for cluster %s:\n%s\n", cc.API.VocabularyPath, id, err) + continue + } } + 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,37 +156,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 - } else { - 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