1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
16 "git.arvados.org/arvados.git/lib/cmd"
17 "git.arvados.org/arvados.git/sdk/go/arvados"
18 "git.arvados.org/arvados.git/sdk/go/ctxlog"
19 "github.com/ghodss/yaml"
20 "github.com/sirupsen/logrus"
23 var DumpCommand dumpCommand
25 type dumpCommand struct{}
27 func (dumpCommand) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
31 fmt.Fprintf(stderr, "%s\n", err)
37 Logger: ctxlog.New(stderr, "text", "info"),
40 flags := flag.NewFlagSet("", flag.ContinueOnError)
41 loader.SetupFlags(flags)
43 if ok, code := cmd.ParseFlags(flags, prog, args, "", stderr); !ok {
46 cfg, err := loader.Load()
50 out, err := yaml.Marshal(cfg)
54 _, err = stdout.Write(out)
61 var CheckCommand checkCommand
63 type checkCommand struct{}
65 func (checkCommand) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
67 var logbuf = &bytes.Buffer{}
69 io.Copy(stderr, logbuf)
71 fmt.Fprintf(stderr, "%s\n", err)
75 logger := logrus.New()
82 flags := flag.NewFlagSet(prog, flag.ContinueOnError)
83 loader.SetupFlags(flags)
84 strict := flags.Bool("strict", true, "Strict validation of configuration file (warnings result in non-zero exit code)")
85 if ok, code := cmd.ParseFlags(flags, prog, args, "", stderr); !ok {
89 // Load the config twice -- once without loading deprecated
90 // keys/files, once with -- and then compare the two resulting
91 // configs. This reveals whether the deprecated keys/files
92 // have any effect on the final configuration.
94 // If they do, show the operator how to update their config
95 // such that the deprecated keys/files are superfluous and can
97 loader.SkipDeprecated = true
98 loader.SkipLegacy = true
99 withoutDepr, err := loader.Load()
103 // Reset() to avoid printing the same warnings twice when they
104 // are logged by both without-legacy and with-legacy loads.
106 loader.SkipDeprecated = false
107 loader.SkipLegacy = false
108 withDepr, err := loader.Load()
113 // Check for configured vocabulary validity.
114 for id, cc := range withDepr.Clusters {
115 if cc.API.VocabularyPath == "" {
118 vd, err := os.ReadFile(cc.API.VocabularyPath)
120 if errors.Is(err, os.ErrNotExist) {
121 // If the vocabulary path doesn't exist, it might mean that
122 // the current node isn't the controller; so it's not an
126 logger.Errorf("Error reading vocabulary file %q for cluster %s: %s\n", cc.API.VocabularyPath, id, err)
129 mk := make([]string, 0, len(cc.Collections.ManagedProperties))
130 for k := range cc.Collections.ManagedProperties {
133 _, err = arvados.NewVocabulary(vd, mk)
135 logger.Errorf("Error loading vocabulary file %q for cluster %s:\n%s\n", cc.API.VocabularyPath, id, err)
140 cmd := exec.Command("diff", "-u", "--label", "without-deprecated-configs", "--label", "relying-on-deprecated-configs", "/dev/fd/3", "/dev/fd/4")
141 for _, obj := range []interface{}{withoutDepr, withDepr} {
142 y, _ := yaml.Marshal(obj)
143 pr, pw, err := os.Pipe()
149 io.Copy(pw, bytes.NewBuffer(y))
152 cmd.ExtraFiles = append(cmd.ExtraFiles, pr)
154 diff, err := cmd.CombinedOutput()
155 if bytes.HasPrefix(diff, []byte("--- ")) {
156 fmt.Fprintln(stdout, "Your configuration is relying on deprecated entries. Suggest making the following changes.")
162 } else if len(diff) > 0 {
163 fmt.Fprintf(stderr, "Unexpected diff output:\n%s", diff)
167 } else if err != nil {
170 if logbuf.Len() > 0 {
178 var DumpDefaultsCommand defaultsCommand
180 type defaultsCommand struct{}
182 func (defaultsCommand) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
183 _, err := stdout.Write(DefaultYAML)
185 fmt.Fprintln(stderr, err)