From 8ed412a47c719c274bb7b19e3a3a9164a56414d3 Mon Sep 17 00:00:00 2001 From: intrand Date: Tue, 10 May 2022 15:05:41 -0500 Subject: [PATCH] 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 :) --- cmd/root.go | 24 ++-- cmd/root_test.go | 14 +- cmd/testdata/{course.yml => course.yaml} | 0 cmd/testdata/{coursev2.yml => coursev2.yaml} | 0 cmd/validation_test.go | 16 +-- docs/README.md | 6 +- docs/usage.md | 63 ++++---- .../{01_test_basic.yml => 01_test_basic.yaml} | 0 ...pace.yml => 02_test_create_namespace.yaml} | 0 ..._test_env_var.yml => 03_test_env_var.yaml} | 0 ...ed_chart.yml => 04_test_failed_chart.yaml} | 0 ...=> 05_test_exit_on_post_install_hook.yaml} | 0 ... => 06_test_exit_on_pre_install_hook.yaml} | 0 ...good_hooks.yml => 07_test_good_hooks.yaml} | 0 ...lti_chart.yml => 08_test_multi_chart.yaml} | 0 ...lti_chart.yml => 09_test_multi_chart.yaml} | 0 ...t_git_chart.yml => 10_test_git_chart.yaml} | 0 ...e.yml => 11_test_after_first_failure.yaml} | 0 ...e.yml => 12_test_after_first_failure.yaml} | 0 ...yml => 13_test_bad_schema_repository.yaml} | 0 ...ecret.yml => 13_test_lint_bad_secret.yaml} | 0 ...cret.yml => 13_test_lint_good_secret.yaml} | 0 ...chema.yml => 13_test_required_schema.yaml} | 0 ...ault_namespace_annotation_and_labels.yaml} | 0 ...rite_namespace_annotation_and_labels.yaml} | 0 ...ml => 17_test_dont_overwrite_ns_meta.yaml} | 0 ...trong_typing.yml => 18_strong_typing.yaml} | 0 ...ering.yml => 20_test_strong_ordering.yaml} | 0 .../{21_test_diff.yml => 21_test_diff.yaml} | 0 ...ironment_variable_namespace_on_chart.yaml} | 0 ...no_context.yml => 24_test_no_context.yaml} | 0 ...25_test_import.yml => 25_test_import.yaml} | 0 ...yml => 26_test_shell_executor_secret.yaml} | 0 ...rite_namespace_annotation_and_labels.yaml} | 0 ...space.yml => relative_hook_namespace.yaml} | 0 .../{yaml_values.yml => yaml_values.yaml} | 0 ...folders.yml => test_files_in_folders.yaml} | 2 +- ...=> 22_testing_relative_hook_location.yaml} | 2 +- end_to_end_testing/tests/01_basic.yaml | 2 +- .../tests/02_namespace_creation.yaml | 2 +- end_to_end_testing/tests/03_test_env_var.yaml | 2 +- end_to_end_testing/tests/04_bad_chart.yaml | 2 +- .../tests/05_exit_post_install.yaml | 2 +- .../tests/06_exit_pre_install.yaml | 2 +- end_to_end_testing/tests/07_good_hooks.yaml | 2 +- end_to_end_testing/tests/08_multi_chart.yaml | 2 +- .../tests/09_one_of_multi_chart.yaml | 2 +- end_to_end_testing/tests/10_git_charts.yaml | 2 +- .../tests/11_stop_after_first_failure.yaml | 2 +- .../12_continue_after_first_failure.yaml | 2 +- end_to_end_testing/tests/13_schema.yaml | 16 +-- end_to_end_testing/tests/14_folders.yaml | 2 +- .../tests/15_namespace_management.yaml | 2 +- ...=> 16_namespace_management_overwrite.yaml} | 2 +- ...17_namespace_managment_dont_overwrite.yaml | 2 +- .../tests/18_strong_typing.yaml | 2 +- .../tests/20_strong_ordering.yaml | 2 +- end_to_end_testing/tests/21_diff.yaml | 2 +- .../tests/22_test_relative_hooks.yaml | 2 +- ..._chart_namespace_environment_variable.yaml | 2 +- end_to_end_testing/tests/24_no_context.yaml | 2 +- end_to_end_testing/tests/25_import.yaml | 2 +- .../tests/26_shell_executor_secret.yaml | 2 +- go.mod | 4 +- go.sum | 6 +- pkg/reckoner/plot.go | 20 ++- pkg/reckoner/split.go | 136 ++++++++++++++++++ ...example-course.yml => example-course.yaml} | 2 +- 68 files changed, 259 insertions(+), 100 deletions(-) rename cmd/testdata/{course.yml => course.yaml} (100%) rename cmd/testdata/{coursev2.yml => coursev2.yaml} (100%) rename end_to_end_testing/course_files/{01_test_basic.yml => 01_test_basic.yaml} (100%) rename end_to_end_testing/course_files/{02_test_create_namespace.yml => 02_test_create_namespace.yaml} (100%) rename end_to_end_testing/course_files/{03_test_env_var.yml => 03_test_env_var.yaml} (100%) rename end_to_end_testing/course_files/{04_test_failed_chart.yml => 04_test_failed_chart.yaml} (100%) rename end_to_end_testing/course_files/{05_test_exit_on_post_install_hook.yml => 05_test_exit_on_post_install_hook.yaml} (100%) rename end_to_end_testing/course_files/{06_test_exit_on_pre_install_hook.yml => 06_test_exit_on_pre_install_hook.yaml} (100%) rename end_to_end_testing/course_files/{07_test_good_hooks.yml => 07_test_good_hooks.yaml} (100%) rename end_to_end_testing/course_files/{08_test_multi_chart.yml => 08_test_multi_chart.yaml} (100%) rename end_to_end_testing/course_files/{09_test_multi_chart.yml => 09_test_multi_chart.yaml} (100%) rename end_to_end_testing/course_files/{10_test_git_chart.yml => 10_test_git_chart.yaml} (100%) rename end_to_end_testing/course_files/{11_test_after_first_failure.yml => 11_test_after_first_failure.yaml} (100%) rename end_to_end_testing/course_files/{12_test_after_first_failure.yml => 12_test_after_first_failure.yaml} (100%) rename end_to_end_testing/course_files/{13_test_bad_schema_repository.yml => 13_test_bad_schema_repository.yaml} (100%) rename end_to_end_testing/course_files/{13_test_lint_bad_secret.yml => 13_test_lint_bad_secret.yaml} (100%) rename end_to_end_testing/course_files/{13_test_lint_good_secret.yml => 13_test_lint_good_secret.yaml} (100%) rename end_to_end_testing/course_files/{13_test_required_schema.yml => 13_test_required_schema.yaml} (100%) rename end_to_end_testing/course_files/{15_test_default_namespace_annotation_and_labels.yml => 15_test_default_namespace_annotation_and_labels.yaml} (100%) rename end_to_end_testing/course_files/{16_test_overwrite_namespace_annotation_and_labels.yml => 16_test_overwrite_namespace_annotation_and_labels.yaml} (100%) rename end_to_end_testing/course_files/{17_test_dont_overwrite_ns_meta.yml => 17_test_dont_overwrite_ns_meta.yaml} (100%) rename end_to_end_testing/course_files/{18_strong_typing.yml => 18_strong_typing.yaml} (100%) rename end_to_end_testing/course_files/{20_test_strong_ordering.yml => 20_test_strong_ordering.yaml} (100%) rename end_to_end_testing/course_files/{21_test_diff.yml => 21_test_diff.yaml} (100%) rename end_to_end_testing/course_files/{23_test_environment_variable_namespace_on_chart.yml => 23_test_environment_variable_namespace_on_chart.yaml} (100%) rename end_to_end_testing/course_files/{24_test_no_context.yml => 24_test_no_context.yaml} (100%) rename end_to_end_testing/course_files/{25_test_import.yml => 25_test_import.yaml} (100%) rename end_to_end_testing/course_files/{26_test_shell_executor_secret.yml => 26_test_shell_executor_secret.yaml} (100%) rename end_to_end_testing/course_files/{test_does_not_overwrite_namespace_annotation_and_labels.yml => test_does_not_overwrite_namespace_annotation_and_labels.yaml} (100%) rename end_to_end_testing/course_files/testing_in_folder/subfolder/{relative_hook_namespace.yml => relative_hook_namespace.yaml} (100%) rename end_to_end_testing/course_files/testing_in_folder/subfolder/{yaml_values.yml => yaml_values.yaml} (100%) rename end_to_end_testing/course_files/testing_in_folder/{test_files_in_folders.yml => test_files_in_folders.yaml} (87%) rename end_to_end_testing/course_files/testing_in_folder/testing_in_subfolder/{22_testing_relative_hook_location.yml => 22_testing_relative_hook_location.yaml} (80%) rename end_to_end_testing/tests/{16_namespace_management_overwrite.yml => 16_namespace_management_overwrite.yaml} (98%) create mode 100644 pkg/reckoner/split.go rename reckoner/{example-course.yml => example-course.yaml} (98%) diff --git a/cmd/root.go b/cmd/root.go index b8050356..68d1f628 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -39,7 +39,7 @@ var ( runAll bool // dryRun contains the boolean flag to run as dry run dryRun bool - // courseFile is the name and path of the course.yml file + // courseFile is the name and path of the course.yaml file courseFile string // onlyRun contains the list of releases to install onlyRun []string @@ -59,6 +59,8 @@ var ( importRepository string // additionalHelmArgs is a list of arguments to add to all helm commands additionalHelmArgs []string + // templateOutputDir + templateOutputDir string ) func init() { @@ -69,9 +71,9 @@ func init() { rootCmd.PersistentFlags().BoolVar(&noColor, "no-color", false, "If true, don't colorize output.") 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.") - plotCmd.PersistentFlags().BoolVar(&continueOnError, "continue-on-error", false, "If true, continue plotting releases even if one or more has errors.") - updateCmd.PersistentFlags().BoolVar(&continueOnError, "continue-on-error", false, "If true, continue plotting releases even if one or more has errors.") - diffCmd.PersistentFlags().BoolVar(&continueOnError, "continue-on-error", false, "If true, continue plotting releases even if one or more has errors.") + plotCmd.PersistentFlags().BoolVar(&continueOnError, "continue-on-error", false, "If true, continue to plot releases even if one or more has errors.") + updateCmd.PersistentFlags().BoolVar(&continueOnError, "continue-on-error", false, "If true, continue to update releases even if one or more has errors.") + diffCmd.PersistentFlags().BoolVar(&continueOnError, "continue-on-error", false, "If true, continue to diff releases even if one or more has errors.") convertCmd.Flags().BoolVarP(&inPlaceConvert, "in-place", "i", false, "If specified, will update the file in place, otherwise outputs to stdout.") @@ -79,6 +81,9 @@ func init() { importCmd.Flags().StringVar(&importRelease, "release_name", "", "The name of the release to import.") importCmd.Flags().StringVar(&importRepository, "repository", "", "The helm repository for the imported release.") + templateCmd.Flags().StringVar(&templateOutputDir, "output-dir", "", "path to the base output directory (eg, ~/myproject/manifests)") + // templateCmd.PersistentFlags().BoolVar(&continueOnError, "continue-on-error", false, "If true, continue to template releases even if one or more has errors.") + rootCmd.AddCommand( plotCmd, convertCmd, @@ -164,12 +169,15 @@ var templateCmd = &cobra.Command{ color.Red(err.Error()) os.Exit(1) } - tmpl, err := client.TemplateAll() + tmpl, err := client.TemplateAll(templateOutputDir) if err != nil { color.Red(err.Error()) os.Exit(1) } - fmt.Println(tmpl) + + if len(templateOutputDir) < 1 { + fmt.Println(tmpl) + } }, } @@ -372,9 +380,9 @@ func getCourseFilePath(args []string) string { courseFile = os.Getenv("RECKONER_COURSE_FILE") // environment variable override // if the environment variable was unset or zero-length, - // try default value of 'course.yml' + // try default value of 'course.yaml' if len(courseFile) == 0 { - courseFile = "course.yml" // default course file + courseFile = "course.yaml" // default course file } // allow cli argument to override everything else diff --git a/cmd/root_test.go b/cmd/root_test.go index 9ab0e75a..a308e5f5 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -29,17 +29,17 @@ func TestGetCourseFilePath(t *testing.T) { { name: "empty path, expect default", path: []string{}, - want: "course.yml", + want: "course.yaml", }, { - name: "single course.yml specified, expect mirror", - path: []string{"testdata/course.yml"}, - want: "testdata/course.yml", + name: "single course.yaml specified, expect mirror", + path: []string{"testdata/course.yaml"}, + want: "testdata/course.yaml", }, { - name: "multiple course.yml specified, expect first", - path: []string{"testdata/course.yml", "second_course.yml"}, - want: "testdata/course.yml", + name: "multiple course.yaml specified, expect first", + path: []string{"testdata/course.yaml", "second_course.yaml"}, + want: "testdata/course.yaml", }, } for _, tt := range tests { diff --git a/cmd/testdata/course.yml b/cmd/testdata/course.yaml similarity index 100% rename from cmd/testdata/course.yml rename to cmd/testdata/course.yaml diff --git a/cmd/testdata/coursev2.yml b/cmd/testdata/coursev2.yaml similarity index 100% rename from cmd/testdata/coursev2.yml rename to cmd/testdata/coursev2.yaml diff --git a/cmd/validation_test.go b/cmd/validation_test.go index 87266bd7..08e49b71 100644 --- a/cmd/validation_test.go +++ b/cmd/validation_test.go @@ -54,7 +54,7 @@ func TestValidateArgs(t *testing.T) { runAll: false, onlyRun: []string{"rbac-manager"}, }, - want: "testdata/course.yml", + want: "testdata/course.yaml", wantErr: false, }, { @@ -63,13 +63,13 @@ func TestValidateArgs(t *testing.T) { args: []string{}, runAll: true, }, - want: "testdata/course.yml", + want: "testdata/course.yaml", wantErr: false, }, { name: "length of args = 2", args: args{ - args: []string{"testdata/course.yml", "course.yml"}, + args: []string{"testdata/course.yaml", "course.yaml"}, runAll: false, onlyRun: []string{"rbac-manager"}, }, @@ -107,22 +107,22 @@ func TestValidateCourseFilePath(t *testing.T) { wantErr: true, }, { - name: "course.yml does not exist", + name: "course.yaml does not exist", args: args{ - args: []string{"course.yml"}, + args: []string{"course.yaml"}, runAll: true, }, want: "", wantErr: true, }, { - name: "course.yml exists, pass onlyrun with success", + name: "course.yaml exists, pass onlyrun with success", args: args{ - args: []string{"testdata/course.yml"}, + args: []string{"testdata/course.yaml"}, runAll: false, onlyRun: []string{"rbac-manager"}, }, - want: "testdata/course.yml", + want: "testdata/course.yaml", wantErr: false, }, } diff --git a/docs/README.md b/docs/README.md index d65773ea..f1ffb1df 100644 --- a/docs/README.md +++ b/docs/README.md @@ -27,7 +27,7 @@ Check out the [documentation at docs.fairwinds.com](https://reckoner.docs.fairwi ## Quickstart -In course.yml, write: +In course.yaml, write: ```yaml namespace: default @@ -48,7 +48,7 @@ charts: Then run: ```shell -reckoner plot course.yml --run-all +reckoner plot course.yaml --run-all ``` Grafana and Polaris should now be installed on your cluster! @@ -59,7 +59,7 @@ Grafana and Polaris should now be installed on your cluster! If you're already using Helm but want to start using `reckoner`, you can use `reckoner import` to facilitate your migration. -We recommend carefully examining the output of a `reckoner diff` before relying on any imported course.yml definitions. +We recommend carefully examining the output of a `reckoner diff` before relying on any imported course.yaml definitions. ## Join the Fairwinds Open Source Community diff --git a/docs/usage.md b/docs/usage.md index 303d5cff..31148897 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -185,10 +185,10 @@ Given the file structure: │ │ └── tests │ │ └── test-connection.yaml │ └── values.yaml -└── course.yml +└── course.yaml ``` -This section of the course.yml will deploy that local chart. +This section of the course.yaml will deploy that local chart. ``` charts: my-release-name: @@ -217,7 +217,7 @@ When you wish to manage annotations or labels for the namespaces you are install `namespace_management` blocks can be defined at the top level or at the chart level. By default, the top level `default` metadata will be used for all namespaces and any `metadata.annotations` or `metadata.labels` set in the charts will be additive. However, if `settings.overwrite` is `True` then the `metadata` block from the chart will replace any matching labels or annotation values. -Keep in mind, chart level `metadata` properties _cannot_ remove or delete any course level properties, only overwrite the value. For this reason, it's best if you don't set course level namespace metadata unless you truly want it applied to _all_ namespaces defined in this course.yml. +Keep in mind, chart level `metadata` properties _cannot_ remove or delete any course level properties, only overwrite the value. For this reason, it's best if you don't set course level namespace metadata unless you truly want it applied to _all_ namespaces defined in this course.yaml. Example: ```yaml @@ -266,6 +266,7 @@ secrets: ## CLI Usage ```text +$ reckoner --help Usage: reckoner [OPTIONS] COMMAND [ARGS]... Options: @@ -285,8 +286,9 @@ Commands: ``` You can add `--help` to any `Command` and get output like the one below: + ```text -$> reckoner plot --help +$ reckoner plot --help Usage: reckoner plot [OPTIONS] COURSE_FILE Install charts with given arguments as listed in yaml file argument @@ -327,8 +329,9 @@ Options: ``` Or + ``` -# reckoner update --help +$ reckoner update --help Usage: reckoner update [OPTIONS] COURSE_FILE Checks to see if anything will be changed, if so, update the release, @@ -370,34 +373,36 @@ Options: ``` Or -```text -# reckoner template --help -Usage: reckoner template [OPTIONS] COURSE_FILE - - Output the template of the chart or charts as they would be installed or - upgraded - -Options: - -a, --run-all Run all charts in the course. Mutually - exclusive with 'only'. - -o, --only, --heading Only run a specific chart by name. Mutually - exclusive with 'run_all'. - - --helm-args TEXT Passes the following arg on to helm, can be - used more than once. WARNING: Setting this - will completely override any helm_args in the - course. Also cannot be used for configuring - how helm connects to tiller. - - --log-level TEXT Log Level. [INFO | DEBUG | WARN | ERROR]. - (default=INFO) - - --help Show this message and exit. +```text +$ reckoner template --help +Templates a helm chart for a release or several releases. Automatically sets --create-namespaces=false --dry-run=true + +Usage: + reckoner template [flags] + +Flags: + -h, --help help for template + --output-dir string path to the base output directory (eg, ~/myproject/manifests) + +Global Flags: + --create-namespaces If true, allow reckoner to create namespaces. (default true) + --dry-run Implies helm --dry-run --debug and skips any hooks + --helm-args strings 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. + --no-color If true, don't colorize output. + -o, --only strings Only install this list of releases. Can be passed + multiple times. + -a, --run-all Install every release in the course file + -v, --v Level number for the log level verbosity ``` + Or + ```text -# reckoner import --help +$ reckoner import --help Usage: reckoner import [OPTIONS] Outputs a chart block that can be used to import the specified release diff --git a/end_to_end_testing/course_files/01_test_basic.yml b/end_to_end_testing/course_files/01_test_basic.yaml similarity index 100% rename from end_to_end_testing/course_files/01_test_basic.yml rename to end_to_end_testing/course_files/01_test_basic.yaml diff --git a/end_to_end_testing/course_files/02_test_create_namespace.yml b/end_to_end_testing/course_files/02_test_create_namespace.yaml similarity index 100% rename from end_to_end_testing/course_files/02_test_create_namespace.yml rename to end_to_end_testing/course_files/02_test_create_namespace.yaml diff --git a/end_to_end_testing/course_files/03_test_env_var.yml b/end_to_end_testing/course_files/03_test_env_var.yaml similarity index 100% rename from end_to_end_testing/course_files/03_test_env_var.yml rename to end_to_end_testing/course_files/03_test_env_var.yaml diff --git a/end_to_end_testing/course_files/04_test_failed_chart.yml b/end_to_end_testing/course_files/04_test_failed_chart.yaml similarity index 100% rename from end_to_end_testing/course_files/04_test_failed_chart.yml rename to end_to_end_testing/course_files/04_test_failed_chart.yaml diff --git a/end_to_end_testing/course_files/05_test_exit_on_post_install_hook.yml b/end_to_end_testing/course_files/05_test_exit_on_post_install_hook.yaml similarity index 100% rename from end_to_end_testing/course_files/05_test_exit_on_post_install_hook.yml rename to end_to_end_testing/course_files/05_test_exit_on_post_install_hook.yaml diff --git a/end_to_end_testing/course_files/06_test_exit_on_pre_install_hook.yml b/end_to_end_testing/course_files/06_test_exit_on_pre_install_hook.yaml similarity index 100% rename from end_to_end_testing/course_files/06_test_exit_on_pre_install_hook.yml rename to end_to_end_testing/course_files/06_test_exit_on_pre_install_hook.yaml diff --git a/end_to_end_testing/course_files/07_test_good_hooks.yml b/end_to_end_testing/course_files/07_test_good_hooks.yaml similarity index 100% rename from end_to_end_testing/course_files/07_test_good_hooks.yml rename to end_to_end_testing/course_files/07_test_good_hooks.yaml diff --git a/end_to_end_testing/course_files/08_test_multi_chart.yml b/end_to_end_testing/course_files/08_test_multi_chart.yaml similarity index 100% rename from end_to_end_testing/course_files/08_test_multi_chart.yml rename to end_to_end_testing/course_files/08_test_multi_chart.yaml diff --git a/end_to_end_testing/course_files/09_test_multi_chart.yml b/end_to_end_testing/course_files/09_test_multi_chart.yaml similarity index 100% rename from end_to_end_testing/course_files/09_test_multi_chart.yml rename to end_to_end_testing/course_files/09_test_multi_chart.yaml diff --git a/end_to_end_testing/course_files/10_test_git_chart.yml b/end_to_end_testing/course_files/10_test_git_chart.yaml similarity index 100% rename from end_to_end_testing/course_files/10_test_git_chart.yml rename to end_to_end_testing/course_files/10_test_git_chart.yaml diff --git a/end_to_end_testing/course_files/11_test_after_first_failure.yml b/end_to_end_testing/course_files/11_test_after_first_failure.yaml similarity index 100% rename from end_to_end_testing/course_files/11_test_after_first_failure.yml rename to end_to_end_testing/course_files/11_test_after_first_failure.yaml diff --git a/end_to_end_testing/course_files/12_test_after_first_failure.yml b/end_to_end_testing/course_files/12_test_after_first_failure.yaml similarity index 100% rename from end_to_end_testing/course_files/12_test_after_first_failure.yml rename to end_to_end_testing/course_files/12_test_after_first_failure.yaml diff --git a/end_to_end_testing/course_files/13_test_bad_schema_repository.yml b/end_to_end_testing/course_files/13_test_bad_schema_repository.yaml similarity index 100% rename from end_to_end_testing/course_files/13_test_bad_schema_repository.yml rename to end_to_end_testing/course_files/13_test_bad_schema_repository.yaml diff --git a/end_to_end_testing/course_files/13_test_lint_bad_secret.yml b/end_to_end_testing/course_files/13_test_lint_bad_secret.yaml similarity index 100% rename from end_to_end_testing/course_files/13_test_lint_bad_secret.yml rename to end_to_end_testing/course_files/13_test_lint_bad_secret.yaml diff --git a/end_to_end_testing/course_files/13_test_lint_good_secret.yml b/end_to_end_testing/course_files/13_test_lint_good_secret.yaml similarity index 100% rename from end_to_end_testing/course_files/13_test_lint_good_secret.yml rename to end_to_end_testing/course_files/13_test_lint_good_secret.yaml diff --git a/end_to_end_testing/course_files/13_test_required_schema.yml b/end_to_end_testing/course_files/13_test_required_schema.yaml similarity index 100% rename from end_to_end_testing/course_files/13_test_required_schema.yml rename to end_to_end_testing/course_files/13_test_required_schema.yaml diff --git a/end_to_end_testing/course_files/15_test_default_namespace_annotation_and_labels.yml b/end_to_end_testing/course_files/15_test_default_namespace_annotation_and_labels.yaml similarity index 100% rename from end_to_end_testing/course_files/15_test_default_namespace_annotation_and_labels.yml rename to end_to_end_testing/course_files/15_test_default_namespace_annotation_and_labels.yaml diff --git a/end_to_end_testing/course_files/16_test_overwrite_namespace_annotation_and_labels.yml b/end_to_end_testing/course_files/16_test_overwrite_namespace_annotation_and_labels.yaml similarity index 100% rename from end_to_end_testing/course_files/16_test_overwrite_namespace_annotation_and_labels.yml rename to end_to_end_testing/course_files/16_test_overwrite_namespace_annotation_and_labels.yaml diff --git a/end_to_end_testing/course_files/17_test_dont_overwrite_ns_meta.yml b/end_to_end_testing/course_files/17_test_dont_overwrite_ns_meta.yaml similarity index 100% rename from end_to_end_testing/course_files/17_test_dont_overwrite_ns_meta.yml rename to end_to_end_testing/course_files/17_test_dont_overwrite_ns_meta.yaml diff --git a/end_to_end_testing/course_files/18_strong_typing.yml b/end_to_end_testing/course_files/18_strong_typing.yaml similarity index 100% rename from end_to_end_testing/course_files/18_strong_typing.yml rename to end_to_end_testing/course_files/18_strong_typing.yaml diff --git a/end_to_end_testing/course_files/20_test_strong_ordering.yml b/end_to_end_testing/course_files/20_test_strong_ordering.yaml similarity index 100% rename from end_to_end_testing/course_files/20_test_strong_ordering.yml rename to end_to_end_testing/course_files/20_test_strong_ordering.yaml diff --git a/end_to_end_testing/course_files/21_test_diff.yml b/end_to_end_testing/course_files/21_test_diff.yaml similarity index 100% rename from end_to_end_testing/course_files/21_test_diff.yml rename to end_to_end_testing/course_files/21_test_diff.yaml diff --git a/end_to_end_testing/course_files/23_test_environment_variable_namespace_on_chart.yml b/end_to_end_testing/course_files/23_test_environment_variable_namespace_on_chart.yaml similarity index 100% rename from end_to_end_testing/course_files/23_test_environment_variable_namespace_on_chart.yml rename to end_to_end_testing/course_files/23_test_environment_variable_namespace_on_chart.yaml diff --git a/end_to_end_testing/course_files/24_test_no_context.yml b/end_to_end_testing/course_files/24_test_no_context.yaml similarity index 100% rename from end_to_end_testing/course_files/24_test_no_context.yml rename to end_to_end_testing/course_files/24_test_no_context.yaml diff --git a/end_to_end_testing/course_files/25_test_import.yml b/end_to_end_testing/course_files/25_test_import.yaml similarity index 100% rename from end_to_end_testing/course_files/25_test_import.yml rename to end_to_end_testing/course_files/25_test_import.yaml diff --git a/end_to_end_testing/course_files/26_test_shell_executor_secret.yml b/end_to_end_testing/course_files/26_test_shell_executor_secret.yaml similarity index 100% rename from end_to_end_testing/course_files/26_test_shell_executor_secret.yml rename to end_to_end_testing/course_files/26_test_shell_executor_secret.yaml diff --git a/end_to_end_testing/course_files/test_does_not_overwrite_namespace_annotation_and_labels.yml b/end_to_end_testing/course_files/test_does_not_overwrite_namespace_annotation_and_labels.yaml similarity index 100% rename from end_to_end_testing/course_files/test_does_not_overwrite_namespace_annotation_and_labels.yml rename to end_to_end_testing/course_files/test_does_not_overwrite_namespace_annotation_and_labels.yaml diff --git a/end_to_end_testing/course_files/testing_in_folder/subfolder/relative_hook_namespace.yml b/end_to_end_testing/course_files/testing_in_folder/subfolder/relative_hook_namespace.yaml similarity index 100% rename from end_to_end_testing/course_files/testing_in_folder/subfolder/relative_hook_namespace.yml rename to end_to_end_testing/course_files/testing_in_folder/subfolder/relative_hook_namespace.yaml diff --git a/end_to_end_testing/course_files/testing_in_folder/subfolder/yaml_values.yml b/end_to_end_testing/course_files/testing_in_folder/subfolder/yaml_values.yaml similarity index 100% rename from end_to_end_testing/course_files/testing_in_folder/subfolder/yaml_values.yml rename to end_to_end_testing/course_files/testing_in_folder/subfolder/yaml_values.yaml diff --git a/end_to_end_testing/course_files/testing_in_folder/test_files_in_folders.yml b/end_to_end_testing/course_files/testing_in_folder/test_files_in_folders.yaml similarity index 87% rename from end_to_end_testing/course_files/testing_in_folder/test_files_in_folders.yml rename to end_to_end_testing/course_files/testing_in_folder/test_files_in_folders.yaml index eed58a55..8315fa3e 100644 --- a/end_to_end_testing/course_files/testing_in_folder/test_files_in_folders.yml +++ b/end_to_end_testing/course_files/testing_in_folder/test_files_in_folders.yaml @@ -10,4 +10,4 @@ charts: repository: fairwinds-incubator chart: basic-demo files: - - subfolder/yaml_values.yml + - subfolder/yaml_values.yaml diff --git a/end_to_end_testing/course_files/testing_in_folder/testing_in_subfolder/22_testing_relative_hook_location.yml b/end_to_end_testing/course_files/testing_in_folder/testing_in_subfolder/22_testing_relative_hook_location.yaml similarity index 80% rename from end_to_end_testing/course_files/testing_in_folder/testing_in_subfolder/22_testing_relative_hook_location.yml rename to end_to_end_testing/course_files/testing_in_folder/testing_in_subfolder/22_testing_relative_hook_location.yaml index 66c46838..2986672d 100644 --- a/end_to_end_testing/course_files/testing_in_folder/testing_in_subfolder/22_testing_relative_hook_location.yml +++ b/end_to_end_testing/course_files/testing_in_folder/testing_in_subfolder/22_testing_relative_hook_location.yaml @@ -11,4 +11,4 @@ charts: chart: basic-demo hooks: pre_install: - - kubectl apply -f ../subfolder/relative_hook_namespace.yml + - kubectl apply -f ../subfolder/relative_hook_namespace.yaml diff --git a/end_to_end_testing/tests/01_basic.yaml b/end_to_end_testing/tests/01_basic.yaml index 4d0c4efe..eacb1145 100644 --- a/end_to_end_testing/tests/01_basic.yaml +++ b/end_to_end_testing/tests/01_basic.yaml @@ -1,7 +1,7 @@ version: "2" name: Basic Functionality vars: - course: ../course_files/01_test_basic.yml + course: ../course_files/01_test_basic.yaml namespace: 01-infra release: first-chart testcases: diff --git a/end_to_end_testing/tests/02_namespace_creation.yaml b/end_to_end_testing/tests/02_namespace_creation.yaml index 7803c90f..fdf34e9d 100644 --- a/end_to_end_testing/tests/02_namespace_creation.yaml +++ b/end_to_end_testing/tests/02_namespace_creation.yaml @@ -1,7 +1,7 @@ version: "2" name: Namespace Creation vars: - course: ../course_files/02_test_create_namespace.yml + course: ../course_files/02_test_create_namespace.yaml namespace: 02-farglebargle release: namespace-test testcases: diff --git a/end_to_end_testing/tests/03_test_env_var.yaml b/end_to_end_testing/tests/03_test_env_var.yaml index d7c25f32..377725dd 100644 --- a/end_to_end_testing/tests/03_test_env_var.yaml +++ b/end_to_end_testing/tests/03_test_env_var.yaml @@ -1,7 +1,7 @@ version: "2" name: Environment Variable Interpolation vars: - course: ../course_files/03_test_env_var.yml + course: ../course_files/03_test_env_var.yaml namespace: 03-infra testcases: - name: 03 - plot without var diff --git a/end_to_end_testing/tests/04_bad_chart.yaml b/end_to_end_testing/tests/04_bad_chart.yaml index 4ff83d79..d0868f3f 100644 --- a/end_to_end_testing/tests/04_bad_chart.yaml +++ b/end_to_end_testing/tests/04_bad_chart.yaml @@ -1,7 +1,7 @@ version: "2" name: Bad Chart vars: - course: ../course_files/04_test_failed_chart.yml + course: ../course_files/04_test_failed_chart.yaml namespace: 04-test release: bad-chart testcases: diff --git a/end_to_end_testing/tests/05_exit_post_install.yaml b/end_to_end_testing/tests/05_exit_post_install.yaml index bf174ed0..124b36b2 100644 --- a/end_to_end_testing/tests/05_exit_post_install.yaml +++ b/end_to_end_testing/tests/05_exit_post_install.yaml @@ -1,7 +1,7 @@ version: "2" name: Exit on Failed Post Install vars: - course: ../course_files/05_test_exit_on_post_install_hook.yml + course: ../course_files/05_test_exit_on_post_install_hook.yaml namespace: 05-infra release: basic-demo testcases: diff --git a/end_to_end_testing/tests/06_exit_pre_install.yaml b/end_to_end_testing/tests/06_exit_pre_install.yaml index 910f78a3..e1cc6c77 100644 --- a/end_to_end_testing/tests/06_exit_pre_install.yaml +++ b/end_to_end_testing/tests/06_exit_pre_install.yaml @@ -1,7 +1,7 @@ version: "2" name: Exit on Failed Pre Install vars: - course: ../course_files/06_test_exit_on_pre_install_hook.yml + course: ../course_files/06_test_exit_on_pre_install_hook.yaml namespace: 06-infra release: basic-demo testcases: diff --git a/end_to_end_testing/tests/07_good_hooks.yaml b/end_to_end_testing/tests/07_good_hooks.yaml index f414d68c..d4849361 100644 --- a/end_to_end_testing/tests/07_good_hooks.yaml +++ b/end_to_end_testing/tests/07_good_hooks.yaml @@ -1,7 +1,7 @@ version: "2" name: Successful Hooks vars: - course: ../course_files/07_test_good_hooks.yml + course: ../course_files/07_test_good_hooks.yaml namespace: 07-redis-test-namespace release: should-install testcases: diff --git a/end_to_end_testing/tests/08_multi_chart.yaml b/end_to_end_testing/tests/08_multi_chart.yaml index e7b3b14a..c88593fe 100644 --- a/end_to_end_testing/tests/08_multi_chart.yaml +++ b/end_to_end_testing/tests/08_multi_chart.yaml @@ -1,7 +1,7 @@ version: "2" name: Multiple Charts in Multiple Namespaces vars: - course: ../course_files/08_test_multi_chart.yml + course: ../course_files/08_test_multi_chart.yaml testcases: - name: 08 - plot course steps: diff --git a/end_to_end_testing/tests/09_one_of_multi_chart.yaml b/end_to_end_testing/tests/09_one_of_multi_chart.yaml index d88015c2..da636f2a 100644 --- a/end_to_end_testing/tests/09_one_of_multi_chart.yaml +++ b/end_to_end_testing/tests/09_one_of_multi_chart.yaml @@ -1,7 +1,7 @@ version: "2" name: One of Multiple Charts vars: - course: ../course_files/09_test_multi_chart.yml + course: ../course_files/09_test_multi_chart.yaml testcases: - name: 09 - plot course -o first-chart-09 steps: diff --git a/end_to_end_testing/tests/10_git_charts.yaml b/end_to_end_testing/tests/10_git_charts.yaml index 95ddc151..b0db4c42 100644 --- a/end_to_end_testing/tests/10_git_charts.yaml +++ b/end_to_end_testing/tests/10_git_charts.yaml @@ -1,7 +1,7 @@ version: "2" name: Charts from Git Repos vars: - course: ../course_files/10_test_git_chart.yml + course: ../course_files/10_test_git_chart.yaml testcases: - name: 10 - plot course steps: diff --git a/end_to_end_testing/tests/11_stop_after_first_failure.yaml b/end_to_end_testing/tests/11_stop_after_first_failure.yaml index c439b3f2..a7a852b1 100644 --- a/end_to_end_testing/tests/11_stop_after_first_failure.yaml +++ b/end_to_end_testing/tests/11_stop_after_first_failure.yaml @@ -1,7 +1,7 @@ version: "2" name: Stop After First Failure vars: - course: ../course_files/11_test_after_first_failure.yml + course: ../course_files/11_test_after_first_failure.yaml namespace: 11-test testcases: - name: 11 - test stop after first failure diff --git a/end_to_end_testing/tests/12_continue_after_first_failure.yaml b/end_to_end_testing/tests/12_continue_after_first_failure.yaml index c2d14de9..1d679794 100644 --- a/end_to_end_testing/tests/12_continue_after_first_failure.yaml +++ b/end_to_end_testing/tests/12_continue_after_first_failure.yaml @@ -1,7 +1,7 @@ version: "2" name: Continue After First Failure vars: - course: ../course_files/12_test_after_first_failure.yml + course: ../course_files/12_test_after_first_failure.yaml namespace: 12-test testcases: - name: 12 - plot course diff --git a/end_to_end_testing/tests/13_schema.yaml b/end_to_end_testing/tests/13_schema.yaml index e035efd7..0357c238 100644 --- a/end_to_end_testing/tests/13_schema.yaml +++ b/end_to_end_testing/tests/13_schema.yaml @@ -3,32 +3,32 @@ name: Bad Chart vars: namespace: 13-test testcases: -- name: 13 - plot 13_test_bad_schema_repository.yml +- name: 13 - plot 13_test_bad_schema_repository.yaml steps: - script: | - reckoner plot -a ../course_files/13_test_bad_schema_repository.yml + reckoner plot -a ../course_files/13_test_bad_schema_repository.yaml assertions: - result.code ShouldEqual 1 - result.systemerr ShouldContainSubstring 'Course file has schema validation errors' -- name: 13 - plot 13_test_required_schema.yml +- name: 13 - plot 13_test_required_schema.yaml steps: - script: | - reckoner plot -a ../course_files/13_test_required_schema.yml + reckoner plot -a ../course_files/13_test_required_schema.yaml assertions: - result.code ShouldEqual 1 - result.systemerr ShouldContainSubstring 'Course file has schema validation errors' -- name: 13 - lint 13_test_lint_bad_secret.yml +- name: 13 - lint 13_test_lint_bad_secret.yaml steps: - script: | - reckoner lint ../course_files/13_test_lint_bad_secret.yml + reckoner lint ../course_files/13_test_lint_bad_secret.yaml assertions: - result.code ShouldEqual 1 - result.systemerr ShouldContainSubstring 'Course file has schema validation errors' -- name: 13 - lint 13_test_lint_good_secret.yml +- name: 13 - lint 13_test_lint_good_secret.yaml steps: - script: | - reckoner lint ../course_files/13_test_lint_good_secret.yml + reckoner lint ../course_files/13_test_lint_good_secret.yaml assertions: - result.code ShouldEqual 0 - result.systemerr ShouldContainSubstring 'No schema validation errors found' diff --git a/end_to_end_testing/tests/14_folders.yaml b/end_to_end_testing/tests/14_folders.yaml index 5b645f78..86fa5da7 100644 --- a/end_to_end_testing/tests/14_folders.yaml +++ b/end_to_end_testing/tests/14_folders.yaml @@ -1,7 +1,7 @@ version: "2" name: Files in Folders vars: - course: ../course_files/testing_in_folder/test_files_in_folders.yml + course: ../course_files/testing_in_folder/test_files_in_folders.yaml namespace: 14-infra release: chart-one testcases: diff --git a/end_to_end_testing/tests/15_namespace_management.yaml b/end_to_end_testing/tests/15_namespace_management.yaml index 81a4b5d4..b8f1f00b 100644 --- a/end_to_end_testing/tests/15_namespace_management.yaml +++ b/end_to_end_testing/tests/15_namespace_management.yaml @@ -1,7 +1,7 @@ version: "2" name: Default Namespace Management vars: - course: ../course_files/15_test_default_namespace_annotation_and_labels.yml + course: ../course_files/15_test_default_namespace_annotation_and_labels.yaml namespace: 15-annotatednamespace release: namespace-test testcases: diff --git a/end_to_end_testing/tests/16_namespace_management_overwrite.yml b/end_to_end_testing/tests/16_namespace_management_overwrite.yaml similarity index 98% rename from end_to_end_testing/tests/16_namespace_management_overwrite.yml rename to end_to_end_testing/tests/16_namespace_management_overwrite.yaml index a68e5788..230fcda5 100644 --- a/end_to_end_testing/tests/16_namespace_management_overwrite.yml +++ b/end_to_end_testing/tests/16_namespace_management_overwrite.yaml @@ -1,7 +1,7 @@ version: "2" name: Namespace Management Overwrite vars: - course: ../course_files/16_test_overwrite_namespace_annotation_and_labels.yml + course: ../course_files/16_test_overwrite_namespace_annotation_and_labels.yaml namespace: 16-annotatednamespace release: namespace-test testcases: diff --git a/end_to_end_testing/tests/17_namespace_managment_dont_overwrite.yaml b/end_to_end_testing/tests/17_namespace_managment_dont_overwrite.yaml index 1c01d57d..5267de80 100644 --- a/end_to_end_testing/tests/17_namespace_managment_dont_overwrite.yaml +++ b/end_to_end_testing/tests/17_namespace_managment_dont_overwrite.yaml @@ -1,7 +1,7 @@ version: "2" name: Namespace Management Overwrite vars: - course: ../course_files/17_test_dont_overwrite_ns_meta.yml + course: ../course_files/17_test_dont_overwrite_ns_meta.yaml namespace: 17-annotatednamespace release: namespace-test testcases: diff --git a/end_to_end_testing/tests/18_strong_typing.yaml b/end_to_end_testing/tests/18_strong_typing.yaml index 5658048b..66a7d622 100644 --- a/end_to_end_testing/tests/18_strong_typing.yaml +++ b/end_to_end_testing/tests/18_strong_typing.yaml @@ -1,7 +1,7 @@ version: "2" name: Strong Typing vars: - course: ../course_files/18_strong_typing.yml + course: ../course_files/18_strong_typing.yaml namespace: 18-testing testcases: - name: 18 - plot course diff --git a/end_to_end_testing/tests/20_strong_ordering.yaml b/end_to_end_testing/tests/20_strong_ordering.yaml index 522648ef..ffa36737 100644 --- a/end_to_end_testing/tests/20_strong_ordering.yaml +++ b/end_to_end_testing/tests/20_strong_ordering.yaml @@ -1,7 +1,7 @@ version: "2" name: Strong Ordering vars: - course: ../course_files/20_test_strong_ordering.yml + course: ../course_files/20_test_strong_ordering.yaml namespace: 20-test testcases: - name: 20 - plot course diff --git a/end_to_end_testing/tests/21_diff.yaml b/end_to_end_testing/tests/21_diff.yaml index 72fa34b1..1945bdf6 100644 --- a/end_to_end_testing/tests/21_diff.yaml +++ b/end_to_end_testing/tests/21_diff.yaml @@ -1,7 +1,7 @@ version: "2" name: Diff vars: - course: ../course_files/21_test_diff.yml + course: ../course_files/21_test_diff.yaml namespace: 21-test testcases: - name: 21 - plot course diff --git a/end_to_end_testing/tests/22_test_relative_hooks.yaml b/end_to_end_testing/tests/22_test_relative_hooks.yaml index 0cbdb365..d505407d 100644 --- a/end_to_end_testing/tests/22_test_relative_hooks.yaml +++ b/end_to_end_testing/tests/22_test_relative_hooks.yaml @@ -1,7 +1,7 @@ version: "2" name: Relative Hook Location vars: - course: ../course_files/testing_in_folder/testing_in_subfolder/22_testing_relative_hook_location.yml + course: ../course_files/testing_in_folder/testing_in_subfolder/22_testing_relative_hook_location.yaml namespace: 22-infra testcases: - name: 22 - plot course diff --git a/end_to_end_testing/tests/23_chart_namespace_environment_variable.yaml b/end_to_end_testing/tests/23_chart_namespace_environment_variable.yaml index 2c980a38..11295b3c 100644 --- a/end_to_end_testing/tests/23_chart_namespace_environment_variable.yaml +++ b/end_to_end_testing/tests/23_chart_namespace_environment_variable.yaml @@ -1,7 +1,7 @@ version: "2" name: Chart Namespace as Environment Variable vars: - course: ../course_files/23_test_environment_variable_namespace_on_chart.yml + course: ../course_files/23_test_environment_variable_namespace_on_chart.yaml namespace: 23-test-environment-namespace release: env-var-name-space testcases: diff --git a/end_to_end_testing/tests/24_no_context.yaml b/end_to_end_testing/tests/24_no_context.yaml index 9e323869..d3d0cac9 100644 --- a/end_to_end_testing/tests/24_no_context.yaml +++ b/end_to_end_testing/tests/24_no_context.yaml @@ -1,7 +1,7 @@ version: "2" name: No Context vars: - course: ../course_files/24_test_no_context.yml + course: ../course_files/24_test_no_context.yaml namespace: 24-test-no-context testcases: - name: 24 - get-manifests diff --git a/end_to_end_testing/tests/25_import.yaml b/end_to_end_testing/tests/25_import.yaml index c157b3e2..2875b9d1 100644 --- a/end_to_end_testing/tests/25_import.yaml +++ b/end_to_end_testing/tests/25_import.yaml @@ -1,7 +1,7 @@ version: "2" name: Shell Executor Secret vars: - course: ../course_files/25_test_import.yml + course: ../course_files/25_test_import.yaml namespace: 25-test-import release: import-test testcases: diff --git a/end_to_end_testing/tests/26_shell_executor_secret.yaml b/end_to_end_testing/tests/26_shell_executor_secret.yaml index 773a0c9a..a7f3b07b 100644 --- a/end_to_end_testing/tests/26_shell_executor_secret.yaml +++ b/end_to_end_testing/tests/26_shell_executor_secret.yaml @@ -1,7 +1,7 @@ version: "2" name: Shell Executor Secret vars: - course: ../course_files/26_test_shell_executor_secret.yml + course: ../course_files/26_test_shell_executor_secret.yaml namespace: 26-shell-executor release: shell-executor-chart testcases: diff --git a/go.mod b/go.mod index b0926bf2..bf1ae6f4 100644 --- a/go.mod +++ b/go.mod @@ -33,7 +33,7 @@ require ( github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect github.com/Azure/go-autorest/logger v0.2.1 // indirect github.com/Azure/go-autorest/tracing v0.6.0 // indirect - github.com/Microsoft/go-winio v0.4.16 // indirect + github.com/Microsoft/go-winio v0.4.17 // indirect github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect github.com/acomagu/bufpipe v1.0.3 // indirect github.com/emirpasic/gods v1.12.0 // indirect @@ -46,7 +46,7 @@ require ( github.com/golang/protobuf v1.5.2 // indirect github.com/google/go-cmp v0.5.6 // indirect github.com/google/go-github/v30 v30.1.0 // indirect - github.com/google/go-querystring v1.0.0 // indirect + github.com/google/go-querystring v1.1.0 // indirect github.com/google/gofuzz v1.1.0 // indirect github.com/googleapis/gnostic v0.5.5 // indirect github.com/imdario/mergo v0.3.12 // indirect diff --git a/go.sum b/go.sum index 4f5c719d..318e4634 100644 --- a/go.sum +++ b/go.sum @@ -67,8 +67,9 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc= github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= -github.com/Microsoft/go-winio v0.4.16 h1:FtSW/jqD+l4ba5iPBj9CODVtgfYAD8w2wS923g/cFDk= github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0= +github.com/Microsoft/go-winio v0.4.17 h1:iT12IBVClFevaf8PuVyi3UmZOVh4OqnaLxDTW2O6j3w= +github.com/Microsoft/go-winio v0.4.17/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84= github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= @@ -264,8 +265,9 @@ github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-github/v30 v30.1.0 h1:VLDx+UolQICEOKu2m4uAoMti1SxuEBAl7RSEG16L+Oo= github.com/google/go-github/v30 v30.1.0/go.mod h1:n8jBpHl45a/rlBUtRJMOG4GhNADUQFEufcolZ95JfU8= -github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= +github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= +github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g= github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= diff --git a/pkg/reckoner/plot.go b/pkg/reckoner/plot.go index 493f29e6..9fb9ff65 100644 --- a/pkg/reckoner/plot.go +++ b/pkg/reckoner/plot.go @@ -110,16 +110,15 @@ func (c *Client) Plot() error { } // TemplateAll runs the same as plot but runs template instead -func (c Client) TemplateAll() (string, error) { - err := c.UpdateHelmRepos() +func (c Client) TemplateAll(templateOutputDir string) (fullOutput string, err error) { + err = c.UpdateHelmRepos() if err != nil { - return "", nil + return fullOutput, err } - var fullOutput string for _, release := range c.CourseFile.Releases { - - if err := c.cloneGitRepo(release); err != nil { + err = c.cloneGitRepo(release) + if err != nil { color.Red(err.Error()) } @@ -128,6 +127,15 @@ func (c Client) TemplateAll() (string, error) { color.Red(err.Error()) continue } + + if len(templateOutputDir) > 0 { + err = c.WriteSplitYaml([]byte(out), templateOutputDir, release.Name) + if err != nil { + color.Red(err.Error()) + os.Exit(1) + } + } + fullOutput = fullOutput + out } return fullOutput, nil diff --git a/pkg/reckoner/split.go b/pkg/reckoner/split.go new file mode 100644 index 00000000..aeab658d --- /dev/null +++ b/pkg/reckoner/split.go @@ -0,0 +1,136 @@ +// Copyright 2022 Fairwinds +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License + +package reckoner + +import ( + "bytes" + "errors" + "io" + "os" + "strings" + + "gopkg.in/yaml.v3" +) + +type k8sMetaBasic struct { + Kind string `yaml:"kind"` + Metadata struct { + Name string `yaml:"name"` + Namespace string `yaml:"namespace,omitempty"` + } `yaml:"metadata"` +} + +// splitYAML will take a slice of bytes, assumed to be a multi-page (1+) YAML document, +// and append each page/object it finds in the document to a slice which is +// returned at the end of processing. Each object is typed as a slice of bytes. +// Therefore, this function returns a slice of a slice of bytes. +// splitYAML was shamelessly ripped from https://go.dev/play/p/MZNwxdUzxPo, which was +// found via github issue https://github.com/go-yaml/yaml/pull/301#issuecomment-792871300 +func splitYAML(in []byte) (out [][]byte, err error) { + decoder := yaml.NewDecoder(bytes.NewReader(in)) // create a YAML decoder to run through our document + + for { // keep going until we run out of bytes to process (end-of-file/EOF) + var value interface{} // something we can use to decode and marshal + var b bytes.Buffer // used for encoding & return + + err = decoder.Decode(&value) // attempt to decode a page in the document + if err == io.EOF { // we ran out of pages/objects/bytes + break // stop trying to process anything + } + // we might have bytes, but we still need to check if we could decode successfully + if err != nil { // check for errors + return nil, err // bubble up + } + + yamlEncoder := yaml.NewEncoder(&b) // create an encoder to handle custom configuration + yamlEncoder.SetIndent(2) // people expect two-space indents instead of the default four + err = yamlEncoder.Encode(&value) // encode proper YAML into slice of bytes + if err != nil { // check for errors + return nil, err // bubble up + } + + // we believe we have a valid YAML object + out = append(out, b.Bytes()) // so append it to the list to be returned later + } + + return out, nil // list of YAML objects, each a []byte +} + +func writeYAML(in []byte, filename string) (err error) { + file, err := os.Create(filename) + if err != nil { + return err + } + + _, err = file.Write(in) + if err != nil { + return err + } + + return err +} + +func (c *Client) WriteSplitYaml(in []byte, basePath string, releaseName string) (err error) { + releasePath := basePath + "/" + releaseName + + objects, err := splitYAML(in) // get list of YAML documents + if err != nil { // check for errors + return err // bubble up + } + + // ensure "${--output-dir}/release_name" exists + for _, dir := range []string{basePath, releasePath} { + if _, err := os.Stat(dir); errors.Is(err, os.ErrNotExist) { + err := os.Mkdir(dir, os.ModePerm) + if err != nil { + return err + } + } + } + + for _, object := range objects { // loop through documents + meta := k8sMetaBasic{} + err = yaml.Unmarshal(object, &meta) + if err != nil { + return err + } + + if len(meta.Kind) < 1 || len(meta.Metadata.Name) < 1 { // skip empty objects; these are the required fields in k8sMetaBasic{} + continue + } + + // This section will build out the name of the file based on what was found inside of the object. + // For example, an object with: + // kind: Deployment + // metadata: + // name: cool-app-api + // namespace: cool-app + // will have the filename of: --output-dir/release_name/cool-app_deployment_cool-app-api.yaml + // We also replace colons with underscores for windows compatibility since RBAC names may have colons + filename := releasePath + "/" // path for the release + if len(meta.Metadata.Namespace) > 0 { // only add the namespace to the filename when it's found in the object + filename = filename + strings.ToLower(meta.Metadata.Namespace) + "_" // lowercased for simplicity + } // continue building the rest of the filename + filename = filename + strings.ToLower(meta.Kind) + "_" + strings.ToLower(meta.Metadata.Name) + ".yaml" // lowercased for simplicity + filename = strings.ReplaceAll(filename, ":", "_") // replace colons with underscores for windows compatibility; RBAC names may have colons + + err = writeYAML(object, filename) // write out + if err != nil { + return err + } + } + + return err +} diff --git a/reckoner/example-course.yml b/reckoner/example-course.yaml similarity index 98% rename from reckoner/example-course.yml rename to reckoner/example-course.yaml index 6ba3a03f..a28c14c1 100644 --- a/reckoner/example-course.yml +++ b/reckoner/example-course.yaml @@ -41,7 +41,7 @@ charts: # list of charts heapster: version: "0.2.1" files: - - /path/to/values/file.yml + - /path/to/values/file.yaml datadog: version: "0.8.2" repository: stable