-
Notifications
You must be signed in to change notification settings - Fork 8
feature(cloud-init): Added the ability to inject extra variables #84
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,6 +90,25 @@ See ochami-cloud-init(1) for more details.`, | |
| os.Exit(1) | ||
| } | ||
| dsWrapper["ds"] = map[string]interface{}{"meta_data": ciData} | ||
|
|
||
| // Read any extra variables specified (This is mostly copy-pasted from cli.HandlePayload) | ||
| // The primary difference is the flag name | ||
| extraVarsMap := make(map[string]interface{}) | ||
| if cmd.Flag("extra-vars").Changed { | ||
| extraVars := cmd.Flag("extra-vars").Value.String() | ||
| if err := client.ReadPayload(extraVars, cli.FormatInput, &extraVarsMap); err != nil { | ||
| log.Logger.Error().Err(err).Msg("unable to read extra variable data or file") | ||
| cli.LogHelpError(cmd) | ||
| os.Exit(1) | ||
| } | ||
| } | ||
|
|
||
| // Apply extra variables to the context | ||
| for k, v := range extraVarsMap { | ||
| dsWrapper[k] = v | ||
| } | ||
|
|
||
| // Construct the context for the template | ||
| refData := exec.NewContext(dsWrapper) | ||
|
|
||
| // Render | ||
|
|
@@ -111,5 +130,11 @@ See ochami-cloud-init(1) for more details.`, | |
| }, | ||
| } | ||
|
|
||
| // Create flags | ||
| groupRenderCmd.Flags().VarP(&cli.FormatInput, "format-input", "f", "format of input payload data (json,json-pretty,yaml)") | ||
| groupRenderCmd.Flags().StringP("extra-vars", "", "", "extra variables to be passed to the template renderer or (if starting with @) file containing extra variables to be passed to the template renderer (can be - to read from stdin)") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should provide a shorthand if using Also, the description is a bit long. To avoid too much wrapping, could we shorten it? Something like this to eliminate redundancy: "extra variables to be passed to the template renderer or (if starting with @) file containing extra variables (can be - to read from stdin)" |
||
|
|
||
| groupRenderCmd.RegisterFlagCompletionFunc("format-input", cli.CompletionFormatData) | ||
|
|
||
| return groupRenderCmd | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are adding an extra flag here, we'll want to update the
rendercommand in the cloud-init(1) manual page with the flag, following the formatting conventions of the commands around it.