From c9f0376594aed5ae0ebc53d3bf2970300406860f Mon Sep 17 00:00:00 2001 From: Mason Malone <651224+MasonM@users.noreply.github.com> Date: Tue, 15 Oct 2024 21:01:52 -0700 Subject: [PATCH] refactor: switch --clusters and --namespaces to be arrays Signed-off-by: Mason Malone <651224+MasonM@users.noreply.github.com> --- hack/db/main.go | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/hack/db/main.go b/hack/db/main.go index 2e377ad87314..8faf2d241789 100644 --- a/hack/db/main.go +++ b/hack/db/main.go @@ -32,7 +32,7 @@ func main() { session, err = createDBSession(dsn) return } - rootCmd.PersistentFlags().StringVarP(&dsn, "dsn", "c", "postgres://postgres@localhost:5432/postgres", "DSN connection string. For MySQL, use 'mysql:password@tcp/argo'.") + rootCmd.PersistentFlags().StringVarP(&dsn, "dsn", "d", "postgres://postgres@localhost:5432/postgres", "DSN connection string. For MySQL, use 'mysql:password@tcp/argo'.") rootCmd.AddCommand(NewMigrateCommand()) rootCmd.AddCommand(NewFakeDataCommand()) @@ -57,14 +57,13 @@ func NewMigrateCommand() *cobra.Command { func NewFakeDataCommand() *cobra.Command { var template string - var seed, rows, numClusters, numNamespaces int + var seed, rows int + var clusters, namespaces []string fakeDataCmd := &cobra.Command{ Use: "fake-archived-workflows", Short: "Insert randomly-generated workflows into argo_archived_workflows, for testing purposes", RunE: func(cmd *cobra.Command, args []string) error { rand.Seed(int64(seed)) - clusters := randomStringArray(numClusters) - namespaces := randomStringArray(numNamespaces) fmt.Printf("Using seed %d\nClusters: %v\nNamespaces: %v\n", seed, clusters, namespaces) instanceIDService := instanceid.NewService("") @@ -85,8 +84,8 @@ func NewFakeDataCommand() *cobra.Command { fakeDataCmd.Flags().StringVar(&template, "template", "@workflow/controller/testdata/dag-exhausted-retries-xfail.yaml", "Workflow definition to use as a template") fakeDataCmd.Flags().IntVar(&seed, "seed", rand.Int(), "Random number seed") fakeDataCmd.Flags().IntVar(&rows, "rows", 10, "Number of rows to insert") - fakeDataCmd.Flags().IntVar(&numClusters, "clusters", 1, "Number of cluster names to autogenerate") - fakeDataCmd.Flags().IntVar(&numNamespaces, "namespaces", 5, "Number of namespaces to autogenerate") + fakeDataCmd.Flags().StringArrayVarP(&clusters, "clusters", "c", []string{"default"}, "Cluster name(s). If multiple given, each Workflow will be randomly assigned to one") + fakeDataCmd.Flags().StringArrayVarP(&namespaces, "namespaces", "n", []string{"argo"}, "Namespace(s). If multiple given, each Workflow will be randomly assigned to one") return fakeDataCmd } @@ -106,14 +105,6 @@ func createDBSession(dsn string) (db.Session, error) { } } -func randomStringArray(length int) []string { - var result []string - for i := 0; i < length; i++ { - result = append(result, rand.String(rand.IntnRange(5, 20))) - } - return result -} - func randomPhase() wfv1.WorkflowPhase { phases := []wfv1.WorkflowPhase{ wfv1.WorkflowSucceeded,