Skip to content

Commit 8ed412a

Browse files
authored
support: template --output-dir some_dir (#587)
* support: template --output-dir some_dir * update docs for output-dir support * go mod tidy * whoops :) * skip empty objects * use yaml encoder to set indentation * handle namespace; lowercase; .yaml in --output-dir * .yaml everywhere * more .yml -> .yaml :)
1 parent 25c5e84 commit 8ed412a

File tree

68 files changed

+259
-100
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+259
-100
lines changed

cmd/root.go

+16-8
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var (
3939
runAll bool
4040
// dryRun contains the boolean flag to run as dry run
4141
dryRun bool
42-
// courseFile is the name and path of the course.yml file
42+
// courseFile is the name and path of the course.yaml file
4343
courseFile string
4444
// onlyRun contains the list of releases to install
4545
onlyRun []string
@@ -59,6 +59,8 @@ var (
5959
importRepository string
6060
// additionalHelmArgs is a list of arguments to add to all helm commands
6161
additionalHelmArgs []string
62+
// templateOutputDir
63+
templateOutputDir string
6264
)
6365

6466
func init() {
@@ -69,16 +71,19 @@ func init() {
6971
rootCmd.PersistentFlags().BoolVar(&noColor, "no-color", false, "If true, don't colorize output.")
7072
rootCmd.PersistentFlags().StringSliceVar(&additionalHelmArgs, "helm-args", nil, "Additional arguments to pass to helm commands. Can be passed multiple times. used more than once. WARNING: Setting this will completely override any helm_args in the course.")
7173

72-
plotCmd.PersistentFlags().BoolVar(&continueOnError, "continue-on-error", false, "If true, continue plotting releases even if one or more has errors.")
73-
updateCmd.PersistentFlags().BoolVar(&continueOnError, "continue-on-error", false, "If true, continue plotting releases even if one or more has errors.")
74-
diffCmd.PersistentFlags().BoolVar(&continueOnError, "continue-on-error", false, "If true, continue plotting releases even if one or more has errors.")
74+
plotCmd.PersistentFlags().BoolVar(&continueOnError, "continue-on-error", false, "If true, continue to plot releases even if one or more has errors.")
75+
updateCmd.PersistentFlags().BoolVar(&continueOnError, "continue-on-error", false, "If true, continue to update releases even if one or more has errors.")
76+
diffCmd.PersistentFlags().BoolVar(&continueOnError, "continue-on-error", false, "If true, continue to diff releases even if one or more has errors.")
7577

7678
convertCmd.Flags().BoolVarP(&inPlaceConvert, "in-place", "i", false, "If specified, will update the file in place, otherwise outputs to stdout.")
7779

7880
importCmd.Flags().StringVar(&importNamespace, "namespace", "", "Namespace that contains the release to be imported.")
7981
importCmd.Flags().StringVar(&importRelease, "release_name", "", "The name of the release to import.")
8082
importCmd.Flags().StringVar(&importRepository, "repository", "", "The helm repository for the imported release.")
8183

84+
templateCmd.Flags().StringVar(&templateOutputDir, "output-dir", "", "path to the base output directory (eg, ~/myproject/manifests)")
85+
// templateCmd.PersistentFlags().BoolVar(&continueOnError, "continue-on-error", false, "If true, continue to template releases even if one or more has errors.")
86+
8287
rootCmd.AddCommand(
8388
plotCmd,
8489
convertCmd,
@@ -164,12 +169,15 @@ var templateCmd = &cobra.Command{
164169
color.Red(err.Error())
165170
os.Exit(1)
166171
}
167-
tmpl, err := client.TemplateAll()
172+
tmpl, err := client.TemplateAll(templateOutputDir)
168173
if err != nil {
169174
color.Red(err.Error())
170175
os.Exit(1)
171176
}
172-
fmt.Println(tmpl)
177+
178+
if len(templateOutputDir) < 1 {
179+
fmt.Println(tmpl)
180+
}
173181
},
174182
}
175183

@@ -372,9 +380,9 @@ func getCourseFilePath(args []string) string {
372380
courseFile = os.Getenv("RECKONER_COURSE_FILE") // environment variable override
373381

374382
// if the environment variable was unset or zero-length,
375-
// try default value of 'course.yml'
383+
// try default value of 'course.yaml'
376384
if len(courseFile) == 0 {
377-
courseFile = "course.yml" // default course file
385+
courseFile = "course.yaml" // default course file
378386
}
379387

380388
// allow cli argument to override everything else

cmd/root_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ func TestGetCourseFilePath(t *testing.T) {
2929
{
3030
name: "empty path, expect default",
3131
path: []string{},
32-
want: "course.yml",
32+
want: "course.yaml",
3333
},
3434
{
35-
name: "single course.yml specified, expect mirror",
36-
path: []string{"testdata/course.yml"},
37-
want: "testdata/course.yml",
35+
name: "single course.yaml specified, expect mirror",
36+
path: []string{"testdata/course.yaml"},
37+
want: "testdata/course.yaml",
3838
},
3939
{
40-
name: "multiple course.yml specified, expect first",
41-
path: []string{"testdata/course.yml", "second_course.yml"},
42-
want: "testdata/course.yml",
40+
name: "multiple course.yaml specified, expect first",
41+
path: []string{"testdata/course.yaml", "second_course.yaml"},
42+
want: "testdata/course.yaml",
4343
},
4444
}
4545
for _, tt := range tests {
File renamed without changes.
File renamed without changes.

cmd/validation_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestValidateArgs(t *testing.T) {
5454
runAll: false,
5555
onlyRun: []string{"rbac-manager"},
5656
},
57-
want: "testdata/course.yml",
57+
want: "testdata/course.yaml",
5858
wantErr: false,
5959
},
6060
{
@@ -63,13 +63,13 @@ func TestValidateArgs(t *testing.T) {
6363
args: []string{},
6464
runAll: true,
6565
},
66-
want: "testdata/course.yml",
66+
want: "testdata/course.yaml",
6767
wantErr: false,
6868
},
6969
{
7070
name: "length of args = 2",
7171
args: args{
72-
args: []string{"testdata/course.yml", "course.yml"},
72+
args: []string{"testdata/course.yaml", "course.yaml"},
7373
runAll: false,
7474
onlyRun: []string{"rbac-manager"},
7575
},
@@ -107,22 +107,22 @@ func TestValidateCourseFilePath(t *testing.T) {
107107
wantErr: true,
108108
},
109109
{
110-
name: "course.yml does not exist",
110+
name: "course.yaml does not exist",
111111
args: args{
112-
args: []string{"course.yml"},
112+
args: []string{"course.yaml"},
113113
runAll: true,
114114
},
115115
want: "",
116116
wantErr: true,
117117
},
118118
{
119-
name: "course.yml exists, pass onlyrun with success",
119+
name: "course.yaml exists, pass onlyrun with success",
120120
args: args{
121-
args: []string{"testdata/course.yml"},
121+
args: []string{"testdata/course.yaml"},
122122
runAll: false,
123123
onlyRun: []string{"rbac-manager"},
124124
},
125-
want: "testdata/course.yml",
125+
want: "testdata/course.yaml",
126126
wantErr: false,
127127
},
128128
}

docs/README.md

+3-3

docs/usage.md

+34-29

end_to_end_testing/course_files/testing_in_folder/test_files_in_folders.yml end_to_end_testing/course_files/testing_in_folder/test_files_in_folders.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ charts:
1010
repository: fairwinds-incubator
1111
chart: basic-demo
1212
files:
13-
- subfolder/yaml_values.yml
13+
- subfolder/yaml_values.yaml

end_to_end_testing/course_files/testing_in_folder/testing_in_subfolder/22_testing_relative_hook_location.yml end_to_end_testing/course_files/testing_in_folder/testing_in_subfolder/22_testing_relative_hook_location.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ charts:
1111
chart: basic-demo
1212
hooks:
1313
pre_install:
14-
- kubectl apply -f ../subfolder/relative_hook_namespace.yml
14+
- kubectl apply -f ../subfolder/relative_hook_namespace.yaml

end_to_end_testing/tests/01_basic.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "2"
22
name: Basic Functionality
33
vars:
4-
course: ../course_files/01_test_basic.yml
4+
course: ../course_files/01_test_basic.yaml
55
namespace: 01-infra
66
release: first-chart
77
testcases:

end_to_end_testing/tests/02_namespace_creation.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "2"
22
name: Namespace Creation
33
vars:
4-
course: ../course_files/02_test_create_namespace.yml
4+
course: ../course_files/02_test_create_namespace.yaml
55
namespace: 02-farglebargle
66
release: namespace-test
77
testcases:

end_to_end_testing/tests/03_test_env_var.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "2"
22
name: Environment Variable Interpolation
33
vars:
4-
course: ../course_files/03_test_env_var.yml
4+
course: ../course_files/03_test_env_var.yaml
55
namespace: 03-infra
66
testcases:
77
- name: 03 - plot without var

end_to_end_testing/tests/04_bad_chart.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "2"
22
name: Bad Chart
33
vars:
4-
course: ../course_files/04_test_failed_chart.yml
4+
course: ../course_files/04_test_failed_chart.yaml
55
namespace: 04-test
66
release: bad-chart
77
testcases:

end_to_end_testing/tests/05_exit_post_install.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "2"
22
name: Exit on Failed Post Install
33
vars:
4-
course: ../course_files/05_test_exit_on_post_install_hook.yml
4+
course: ../course_files/05_test_exit_on_post_install_hook.yaml
55
namespace: 05-infra
66
release: basic-demo
77
testcases:

end_to_end_testing/tests/06_exit_pre_install.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "2"
22
name: Exit on Failed Pre Install
33
vars:
4-
course: ../course_files/06_test_exit_on_pre_install_hook.yml
4+
course: ../course_files/06_test_exit_on_pre_install_hook.yaml
55
namespace: 06-infra
66
release: basic-demo
77
testcases:

end_to_end_testing/tests/07_good_hooks.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "2"
22
name: Successful Hooks
33
vars:
4-
course: ../course_files/07_test_good_hooks.yml
4+
course: ../course_files/07_test_good_hooks.yaml
55
namespace: 07-redis-test-namespace
66
release: should-install
77
testcases:

end_to_end_testing/tests/08_multi_chart.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "2"
22
name: Multiple Charts in Multiple Namespaces
33
vars:
4-
course: ../course_files/08_test_multi_chart.yml
4+
course: ../course_files/08_test_multi_chart.yaml
55
testcases:
66
- name: 08 - plot course
77
steps:

end_to_end_testing/tests/09_one_of_multi_chart.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "2"
22
name: One of Multiple Charts
33
vars:
4-
course: ../course_files/09_test_multi_chart.yml
4+
course: ../course_files/09_test_multi_chart.yaml
55
testcases:
66
- name: 09 - plot course -o first-chart-09
77
steps:

end_to_end_testing/tests/10_git_charts.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "2"
22
name: Charts from Git Repos
33
vars:
4-
course: ../course_files/10_test_git_chart.yml
4+
course: ../course_files/10_test_git_chart.yaml
55
testcases:
66
- name: 10 - plot course
77
steps:

end_to_end_testing/tests/11_stop_after_first_failure.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "2"
22
name: Stop After First Failure
33
vars:
4-
course: ../course_files/11_test_after_first_failure.yml
4+
course: ../course_files/11_test_after_first_failure.yaml
55
namespace: 11-test
66
testcases:
77
- name: 11 - test stop after first failure

0 commit comments

Comments
 (0)