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

Kops Template YAML Formatting #3706

Merged
merged 1 commit into from
Oct 30, 2017
Merged

Conversation

gambol99
Copy link
Contributor

@gambol99 gambol99 commented Oct 26, 2017

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
  • updated the cli documentation
  • the option is off by default to retain behavior

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 26, 2017
@gambol99
Copy link
Contributor Author

/assign @gambol99

@gambol99
Copy link
Contributor Author

/assign @chrislovecnm


if len(rendered) <= 0 {
continue
}
io.WriteString(writer, rendered)
Copy link
Member

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!


if options.formatYAML {
var data interface{}
err := yaml.Unmarshal(content, &data)
Copy link
Member

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..

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type: formatting

return fmt.Errorf("unable to open file: %s, error: %v", options.outputPath, err)
}
defer w.Close()
w.Write(content)
Copy link
Member

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

defer w.Close()
w.Write(content)
} else {
out.Write(content)
Copy link
Member

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

@justinsb
Copy link
Member

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
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 30, 2017
@gambol99
Copy link
Contributor Author

hi @justinsb

  • fixed the spelling mistakes
  • amended the code to use the buffer writer than the io package and am checking the errors
  • I've added a little --config-value which we use to grab merged configuration

@justinsb
Copy link
Member

/lgtm

Thanks @gambol99!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 30, 2017
@k8s-github-robot
Copy link

[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 /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 30, 2017
@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue.

@k8s-github-robot k8s-github-robot merged commit e0d8eef into kubernetes:master Oct 30, 2017
@gambol99
Copy link
Contributor Author

gambol99 commented Oct 30, 2017

eeek! :'-( .. i just spotted a bug .. ok, raising a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants