From eaf80660689bdab7c88d657d462ef4e471ccead9 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Thu, 1 Feb 2024 11:23:29 +0100 Subject: [PATCH] Revert "Add `--key` flag for generate commands to specify resource key (#1165)" This reverts commit b28432afed9b3041fc2bd2ad2fc090e27c62d77f. --- cmd/bundle/generate.go | 3 --- cmd/bundle/generate/generate_test.go | 8 ++------ cmd/bundle/generate/job.go | 6 +----- cmd/bundle/generate/pipeline.go | 10 +++------- internal/bundle/generate_job_test.go | 2 +- internal/bundle/generate_pipeline_test.go | 2 +- 6 files changed, 8 insertions(+), 23 deletions(-) diff --git a/cmd/bundle/generate.go b/cmd/bundle/generate.go index 89d7c6ad..ca2f8cce 100644 --- a/cmd/bundle/generate.go +++ b/cmd/bundle/generate.go @@ -6,8 +6,6 @@ import ( ) func newGenerateCommand() *cobra.Command { - var key string - cmd := &cobra.Command{ Use: "generate", Short: "Generate bundle configuration", @@ -17,6 +15,5 @@ func newGenerateCommand() *cobra.Command { cmd.AddCommand(generate.NewGenerateJobCommand()) cmd.AddCommand(generate.NewGeneratePipelineCommand()) - cmd.PersistentFlags().StringVar(&key, "key", "", `resource key to use for the generated configuration`) return cmd } diff --git a/cmd/bundle/generate/generate_test.go b/cmd/bundle/generate/generate_test.go index b29bdef2..f0693646 100644 --- a/cmd/bundle/generate/generate_test.go +++ b/cmd/bundle/generate/generate_test.go @@ -72,18 +72,14 @@ func TestGeneratePipelineCommand(t *testing.T) { srcDir := filepath.Join(root, "src") cmd.Flag("source-dir").Value.Set(srcDir) - - var key string - cmd.Flags().StringVar(&key, "key", "test_pipeline", "") - err := cmd.RunE(cmd, []string{}) require.NoError(t, err) - data, err := os.ReadFile(filepath.Join(configDir, "test_pipeline.yml")) + data, err := os.ReadFile(filepath.Join(configDir, "pipeline_test_pipeline.yml")) require.NoError(t, err) require.Equal(t, fmt.Sprintf(`resources: pipelines: - test_pipeline: + pipeline_test_pipeline: name: test-pipeline libraries: - notebook: diff --git a/cmd/bundle/generate/job.go b/cmd/bundle/generate/job.go index b88b2c17..51e4fbae 100644 --- a/cmd/bundle/generate/job.go +++ b/cmd/bundle/generate/job.go @@ -63,11 +63,7 @@ func NewGenerateJobCommand() *cobra.Command { return err } - jobKey := cmd.Flag("key").Value.String() - if jobKey == "" { - jobKey = textutil.NormalizeString(job.Settings.Name) - } - + jobKey := fmt.Sprintf("job_%s", textutil.NormalizeString(job.Settings.Name)) result := map[string]dyn.Value{ "resources": dyn.V(map[string]dyn.Value{ "jobs": dyn.V(map[string]dyn.Value{ diff --git a/cmd/bundle/generate/pipeline.go b/cmd/bundle/generate/pipeline.go index 955db34b..efe9cc62 100644 --- a/cmd/bundle/generate/pipeline.go +++ b/cmd/bundle/generate/pipeline.go @@ -63,15 +63,11 @@ func NewGeneratePipelineCommand() *cobra.Command { return err } - pipelineKey := cmd.Flag("key").Value.String() - if pipelineKey == "" { - pipelineKey = textutil.NormalizeString(pipeline.Name) - } - + jobKey := fmt.Sprintf("pipeline_%s", textutil.NormalizeString(pipeline.Name)) result := map[string]dyn.Value{ "resources": dyn.V(map[string]dyn.Value{ "pipelines": dyn.V(map[string]dyn.Value{ - pipelineKey: v, + jobKey: v, }), }), } @@ -81,7 +77,7 @@ func NewGeneratePipelineCommand() *cobra.Command { return err } - filename := filepath.Join(configDir, fmt.Sprintf("%s.yml", pipelineKey)) + filename := filepath.Join(configDir, fmt.Sprintf("%s.yml", jobKey)) err = yamlsaver.SaveAsYAML(result, filename, force) if err != nil { return err diff --git a/internal/bundle/generate_job_test.go b/internal/bundle/generate_job_test.go index e9445abc..7c04a828 100644 --- a/internal/bundle/generate_job_test.go +++ b/internal/bundle/generate_job_test.go @@ -46,7 +46,7 @@ func TestAccGenerateFromExistingJobAndDeploy(t *testing.T) { _, err = os.Stat(filepath.Join(bundleRoot, "src", "test.py")) require.NoError(t, err) - matches, err := filepath.Glob(filepath.Join(bundleRoot, "resources", "generated_job_*.yml")) + matches, err := filepath.Glob(filepath.Join(bundleRoot, "resources", "job_generated_job_*.yml")) require.NoError(t, err) require.Len(t, matches, 1) diff --git a/internal/bundle/generate_pipeline_test.go b/internal/bundle/generate_pipeline_test.go index 7b2323e6..85fbbb2f 100644 --- a/internal/bundle/generate_pipeline_test.go +++ b/internal/bundle/generate_pipeline_test.go @@ -47,7 +47,7 @@ func TestAccGenerateFromExistingPipelineAndDeploy(t *testing.T) { _, err = os.Stat(filepath.Join(bundleRoot, "src", "test.py")) require.NoError(t, err) - matches, err := filepath.Glob(filepath.Join(bundleRoot, "resources", "generated_pipeline_*.yml")) + matches, err := filepath.Glob(filepath.Join(bundleRoot, "resources", "pipeline_generated_pipeline_*.yml")) require.NoError(t, err) require.Len(t, matches, 1)