-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Kops Template YAML Formatting #3706
Conversation
/assign @gambol99 |
/assign @chrislovecnm |
cmd/kops/toolbox_template.go
Outdated
|
||
if len(rendered) <= 0 { | ||
continue | ||
} | ||
io.WriteString(writer, rendered) |
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.
Probably better to call writer.WriteString
, now that it is a bytes.Buffer (because we probably should have been checking for errors here previously, but we don't have to with bytes.Buffer, but we might as well call the method directly to trigger an error if we make this an io.Writer again!) But not a big deal!
cmd/kops/toolbox_template.go
Outdated
|
||
if options.formatYAML { | ||
var data interface{} | ||
err := yaml.Unmarshal(content, &data) |
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.
Is ---
actually part of yaml syntax? i.e. does this work with more than one template?
If not, we might have to format each section independently..
cmd/kops/toolbox_template.go
Outdated
return fmt.Errorf("encountered errors generating templates: %s", err) | ||
} | ||
if content, err = yaml.Marshal(data); err != nil { | ||
return fmt.Errorf("encountered error formating the template: %s", err) |
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.
type: formatting
cmd/kops/toolbox_template.go
Outdated
return fmt.Errorf("unable to open file: %s, error: %v", options.outputPath, err) | ||
} | ||
defer w.Close() | ||
w.Write(content) |
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.
Should check for an error from w.Write here
cmd/kops/toolbox_template.go
Outdated
defer w.Close() | ||
w.Write(content) | ||
} else { | ||
out.Write(content) |
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.
Should check the error code here too
A few small things - want to see if you agree @gambol99 ? |
Adding an extra option to the toolbox templating to format the YAML before writing out; which is usefull to cleanup formating issues and as detecting errors in the template - added a formating options --format-yaml to the toolbox template which cleans up the yaml before writing out - updated the cli documentation - added the --config-value used to grab the configuration
hi @justinsb
|
/lgtm Thanks @gambol99! |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: justinsb The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
/test all [submit-queue is verifying that this PR is safe to merge] |
Automatic merge from submit-queue. |
eeek! :'-( .. i just spotted a bug .. ok, raising a PR |
Adding an extra option to the toolbox templating to format the YAML before writing out; which is usefull to cleanup formating issues and as detecting errors in the template