Skip to content

Commit

Permalink
Allow peribolos to dump a fully functional config
Browse files Browse the repository at this point in the history
It is not often intended when using --dump to want only the org snippet
for any deployment of peribolos that does not use the bazel
metaprogramming that is used in kubernetes/org repo. In those cases,
dumping the full config instead of the snippet is more useful.

Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
  • Loading branch information
stevekuznetsov committed Apr 18, 2019
1 parent 45bb1a8 commit 3251fb1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
18 changes: 17 additions & 1 deletion prow/cmd/peribolos/main.go
Expand Up @@ -47,6 +47,7 @@ type options struct {
config string
confirm bool
dump string
dumpFull bool
jobConfig string
maximumDelta float64
minAdmins int
Expand Down Expand Up @@ -84,6 +85,7 @@ func (o *options) parseArgs(flags *flag.FlagSet, args []string) error {
flags.IntVar(&o.tokensPerHour, "tokens", defaultTokens, "Throttle hourly token consumption (0 to disable)")
flags.IntVar(&o.tokenBurst, "token-burst", defaultBurst, "Allow consuming a subset of hourly tokens in a short burst")
flags.StringVar(&o.dump, "dump", "", "Output current config of this org if set")
flags.BoolVar(&o.dumpFull, "dump-full", false, "Output current config of the org as a valid input config file instead of a snippet")
flags.BoolVar(&o.ignoreSecretTeams, "ignore-secret-teams", false, "Do not dump or update secret teams if set")
flags.BoolVar(&o.fixOrg, "fix-org", false, "Change org metadata if set")
flags.BoolVar(&o.fixOrgMembers, "fix-org-members", false, "Add/remove org members if set")
Expand Down Expand Up @@ -119,6 +121,10 @@ func (o *options) parseArgs(flags *flag.FlagSet, args []string) error {
return fmt.Errorf("--config-path=%s and --dump=%s cannot both be set", o.config, o.dump)
}

if o.dumpFull && o.dump == "" {
return errors.New("--dump-full can't be used without --dump")
}

if o.fixTeamMembers && !o.fixTeams {
return fmt.Errorf("--fix-team-members requires --fix-teams")
}
Expand Down Expand Up @@ -160,7 +166,17 @@ func main() {
if err != nil {
logrus.WithError(err).Fatalf("Dump %s failed to collect current data.", o.dump)
}
out, err := yaml.Marshal(ret)
var output interface{}
if o.dumpFull {
output = struct {
Orgs map[string]*org.Config `json:"orgs,omitempty"`
}{
Orgs: map[string]*org.Config{o.dump: ret},
}
} else {
output = ret
}
out, err := yaml.Marshal(output)
if err != nil {
logrus.WithError(err).Fatalf("Dump %s failed to marshal output.", o.dump)
}
Expand Down
4 changes: 4 additions & 0 deletions prow/cmd/peribolos/main_test.go
Expand Up @@ -59,6 +59,10 @@ func TestOptions(t *testing.T) {
name: "--maximum-removal-delta too low",
args: []string{"--config-path=foo", "--maximum-removal-delta=-0.1"},
},
{
name: "reject --dump-full-config without --dump",
args: []string{"--config-path=foo", "--dump-full-config"},
},
{
name: "maximal delta",
args: []string{"--config-path=foo", "--maximum-removal-delta=1"},
Expand Down

0 comments on commit 3251fb1

Please sign in to comment.