X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/a0398ebd1c50b1be2433c109af6bb0d263c54ea5..7591486e80665e7eb0213f0204949139da8652c0:/lib/config/cmd.go diff --git a/lib/config/cmd.go b/lib/config/cmd.go index 347e8519a9..528d748c86 100644 --- a/lib/config/cmd.go +++ b/lib/config/cmd.go @@ -6,12 +6,14 @@ package config import ( "bytes" + "errors" "flag" "fmt" "io" "os" "os/exec" + "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" @@ -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 len(flags.Args()) != 0 { - flags.Usage() - return 2 + if ok, code := cmd.ParseFlags(flags, prog, args, "", stderr); !ok { + return code } - cfg, err := loader.Load() if err != nil { return 1 @@ -88,22 +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) 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 { - err = nil - return 0 - } else if err != nil { - return 2 - } - - if len(flags.Args()) != 0 { - flags.Usage() - return 2 + if ok, code := cmd.ParseFlags(flags, prog, args, "", stderr); !ok { + return code } // Load the config twice -- once without loading deprecated @@ -120,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) @@ -165,28 +172,9 @@ func (checkCommand) RunCommand(prog string, args []string, stdin io.Reader, stdo 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 - } - } - return warned -} - var DumpDefaultsCommand defaultsCommand type defaultsCommand struct{}