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"
}
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
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
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)
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