Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --key flag for generate commands to specify resource key #1165

Merged
merged 4 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/bundle/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
)

func newGenerateCommand() *cobra.Command {
var key string

cmd := &cobra.Command{
Use: "generate",
Short: "Generate bundle configuration",
Expand All @@ -15,5 +17,6 @@ func newGenerateCommand() *cobra.Command {

cmd.AddCommand(generate.NewGenerateJobCommand())
cmd.AddCommand(generate.NewGeneratePipelineCommand())
cmd.PersistentFlags().StringVar(&key, "key", "", `Key name to be used for generated resources in the config`)
andrewnester marked this conversation as resolved.
Show resolved Hide resolved
return cmd
}
8 changes: 7 additions & 1 deletion cmd/bundle/generate/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ func NewGenerateJobCommand() *cobra.Command {
return err
}

jobKey := fmt.Sprintf("job_%s", textutil.NormalizeString(job.Settings.Name))
var jobKey string
if cmd.Flag("key").Changed {
andrewnester marked this conversation as resolved.
Show resolved Hide resolved
jobKey = cmd.Flag("key").Value.String()
} else {
jobKey = textutil.NormalizeString(job.Settings.Name)
}

result := map[string]dyn.Value{
"resources": dyn.V(map[string]dyn.Value{
"jobs": dyn.V(map[string]dyn.Value{
Expand Down
12 changes: 9 additions & 3 deletions cmd/bundle/generate/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,17 @@ func NewGeneratePipelineCommand() *cobra.Command {
return err
}

jobKey := fmt.Sprintf("pipeline_%s", textutil.NormalizeString(pipeline.Name))
var pipelineKey string
if cmd.Flag("key").Changed {
pipelineKey = cmd.Flag("key").Value.String()
} else {
pipelineKey = textutil.NormalizeString(pipeline.Name)
}

result := map[string]dyn.Value{
"resources": dyn.V(map[string]dyn.Value{
"pipelines": dyn.V(map[string]dyn.Value{
jobKey: v,
pipelineKey: v,
}),
}),
}
Expand All @@ -77,7 +83,7 @@ func NewGeneratePipelineCommand() *cobra.Command {
return err
}

filename := filepath.Join(configDir, fmt.Sprintf("%s.yml", jobKey))
filename := filepath.Join(configDir, fmt.Sprintf("%s.yml", pipelineKey))
err = yamlsaver.SaveAsYAML(result, filename, force)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/bundle/generate_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", "job_generated_job_*.yml"))
matches, err := filepath.Glob(filepath.Join(bundleRoot, "resources", "generated_job_*.yml"))
require.NoError(t, err)
require.Len(t, matches, 1)

Expand Down
2 changes: 1 addition & 1 deletion internal/bundle/generate_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", "pipeline_generated_pipeline_*.yml"))
matches, err := filepath.Glob(filepath.Join(bundleRoot, "resources", "generated_pipeline_*.yml"))
require.NoError(t, err)
require.Len(t, matches, 1)

Expand Down
Loading