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

support: template --output-dir some_dir #587

Merged
merged 9 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from 8 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
24 changes: 16 additions & 8 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand All @@ -69,16 +71,19 @@ 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.")

importCmd.Flags().StringVar(&importNamespace, "namespace", "", "Namespace that contains the release to be imported.")
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,
Expand Down Expand Up @@ -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)
}
},
}

Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
File renamed without changes.
File renamed without changes.
16 changes: 8 additions & 8 deletions cmd/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
{
Expand All @@ -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"},
},
Expand Down Expand Up @@ -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,
},
}
Expand Down
6 changes: 3 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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!
Expand All @@ -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.

<!-- Begin boilerplate -->
## Join the Fairwinds Open Source Community
Expand Down
63 changes: 34 additions & 29 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -266,6 +266,7 @@ secrets:
## CLI Usage

```text
$ reckoner --help
Usage: reckoner [OPTIONS] COMMAND [ARGS]...

Options:
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 <chart> 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
Expand Down
2 changes: 1 addition & 1 deletion end_to_end_testing/tests/01_basic.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion end_to_end_testing/tests/02_namespace_creation.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion end_to_end_testing/tests/03_test_env_var.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion end_to_end_testing/tests/04_bad_chart.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion end_to_end_testing/tests/05_exit_post_install.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion end_to_end_testing/tests/06_exit_pre_install.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion end_to_end_testing/tests/07_good_hooks.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion end_to_end_testing/tests/08_multi_chart.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion end_to_end_testing/tests/09_one_of_multi_chart.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion end_to_end_testing/tests/10_git_charts.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading