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

Fix #377: Removing name flag from the tink template create/update command #385

Merged
merged 4 commits into from Jan 21, 2021

Conversation

parauliya
Copy link
Contributor

@parauliya parauliya commented Dec 11, 2020

Description

This PR will remove the name flag from the tink template create/update command in tink-cli.

Why is this needed

Fixes: #377

How Has This Been Tested?

This has been tested manually over the vagrant setup.

How to migrate?

Current Behaviour:
At present, the tink template create -n <name> allows users to provide a name to a workflow template. A user can also update this name using the tink template update -n <new-name> command.

The workflow template also has the name field. So, a workflow is getting itss name from two different and places and this can be confusing to users.

version: "0.1"
name: hello_world_workflow
global_timeout: 6
tasks:
  - name: "hello world"
    worker: "{{.device_1}}"
    actions:
      - name: "hello_world"
        image: hello-world
        timeout: 60

New Behaviour:
With this PR, tink template create and tink template update CLI will not accept a name for the template to be created or updated. Instead, the template name will be picked from the name field in the template definition.

The existing users need to run the tink template update <id> --file <template-file> command. This will update the name of each template as per the value of name field in the template definition.

Checklist:

I have:

  • updated the documentation and/or roadmap (if required)
  • added unit or e2e tests
  • provided instructions on how to upgrade

@codecov
Copy link

codecov bot commented Dec 11, 2020

Codecov Report

Merging #385 (fe503ee) into master (745c2d0) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #385   +/-   ##
=======================================
  Coverage   33.08%   33.08%           
=======================================
  Files          24       24           
  Lines        2170     2170           
=======================================
  Hits          718      718           
  Misses       1376     1376           
  Partials       76       76           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 745c2d0...fe503ee. Read the comment docs.

@gianarb gianarb added the breaking-change Denotes a PR that introduces potentially breaking changes that require user action. label Dec 11, 2020
@gianarb
Copy link
Contributor

gianarb commented Dec 11, 2020

This is a BC break and I think we should take this opportunity to carefully review our UX.

This is what I mean in practice: tink hardware push uses -f to require the location for a file, here we use -p for the same thing. Should we move it to -f to gain some sort of consistency?

@gauravgahlot
Copy link
Contributor

This is a BC break and I think we should take this opportunity to carefully review our UX.

This is what I mean in practice: tink hardware push uses -f to require the location for a file, here we use -p for the same thing. Should we move it to -f to gain some sort of consistency?

tink hardware push does not have a shorthand for file path and uses --file. -f is used for the facility.

Usage:
  tink hardware push [flags]

Examples:
cat /tmp/data.json | tink hardware push
tink hardware push --file /tmp/data.json

Flags:
      --file string   hardware data file
  -h, --help          help for push

Global Flags:
  -f, --facility string   used to build grpc and http urls

either pipe the data or provide the required '--file' flag

That's the reason why we had to use -p for the file path.

@gianarb
Copy link
Contributor

gianarb commented Dec 11, 2020

Thank you for clarifying @gauravgahlot but my point is the same:

hardware use --file when asking for the location for a file.
template uses -p for the same reason.

Should we use the same one? 👍 👎

@gauravgahlot
Copy link
Contributor

Thank you for clarifying @gauravgahlot but my point is the same:

hardware use --file when asking for the location for a file.
template uses -p for the same reason.

Should we use the same one?

Oh yes totally. Initially, we had thought of removing facility altogether and use -f for the file path. But I'm assuming the facility is required in the Packet environment. 🤔

@gianarb
Copy link
Contributor

gianarb commented Dec 11, 2020

But I'm assuming the facility is required in the Packet environment

Never say to me that something is required for ONE single company.. :) but yeah for now I think we should use --file and leave the facility, probably when @mmlb will start removing Packet or dead code from all the repo -f/--facility will go away, but out of scope for now.

filePath string
templateName string
)

type TemplateName struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should not be an exported type.

// createCmd represents the create subcommand for template command
var createCmd = &cobra.Command{
Use: "create",
Short: "create a workflow template ",
Example: `tink template create [flags]
cat /tmp/example.tmpl | tink template create -n example`,
cat /tmp/example.tmpl | tink template create `,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we please add more examples in the Long description?
For reference, you can check tink events watch.

templateName = templ.Name
return nil
}
return errors.New("Template does not have `name` field which is mandatory")
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move all the error messages to a const block and ensure they all start with a lower case.

@gianarb gianarb changed the title Fix #377: Removing name flag from the 'tink template create/update' command Fix #377: Removing name flag from the tink template create/update command Dec 11, 2020
@gianarb gianarb requested a review from mmlb December 11, 2020 13:08
@mmlb
Copy link
Contributor

mmlb commented Dec 11, 2020

But I'm assuming the facility is required in the Packet environment

Never say to me that something is required for ONE single company.. :) but yeah for now I think we should use --file and leave the facility, probably when @mmlb will start removing Packet or dead code from all the repo -f/--facility will go away, but out of scope for now.

Facility is only really used for the cert generation stuff, something I'd actually like to get rid of. Let me open up an issue for that (#389).

Copy link
Contributor

@gianarb gianarb left a comment

Choose a reason for hiding this comment

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

Great, @parauliya do you mind changing -p with --file and we are good? Thanks

Comment on lines 84 to 93
var templ TemplateName
err := yaml.Unmarshal([]byte(data), &templ)
if err != nil {
return err
}
if templ.Name != "" {
templateName = templ.Name
return nil
}
return errors.New("Template does not have `name` field which is mandatory")
Copy link
Contributor

Choose a reason for hiding this comment

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

This should use github.com/tinkerbell/tink/workflow.Parse instead.

Copy link
Contributor

@gianarb gianarb left a comment

Choose a reason for hiding this comment

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

This is a bc break, according with the proposal 0011 https://github.com/tinkerbell/proposals/blob/master/proposals/0011/README.md can you add a chapter in the PR description:

How to migrate

https://github.com/tinkerbell/proposals/blob/master/proposals/0011/README.md#how-to-migrate

Explaining what is not working anymore and how to do the same in the new way, thanks

@@ -69,16 +74,23 @@ func readAll(reader io.Reader) []byte {
func addFlags() {
flags := createCmd.PersistentFlags()
flags.StringVarP(&filePath, "path", "p", "", "path to the template file")
Copy link
Contributor

Choose a reason for hiding this comment

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

Please change this with --file to unify with hardware push

@gauravgahlot gauravgahlot requested review from mmlb, gianarb and gauravgahlot and removed request for gauravgahlot December 23, 2020 11:03
gauravgahlot
gauravgahlot previously approved these changes Dec 23, 2020
@gauravgahlot gauravgahlot self-assigned this Dec 23, 2020
@gauravgahlot gauravgahlot added this to In Progress in Issues List via automation Dec 23, 2020
gianarb
gianarb previously approved these changes Jan 4, 2021
@gauravgahlot
Copy link
Contributor

@mmlb Please let me know once you are back, and I will update the branch (one last time). 😄

Comment on lines 19 to 20
file = "file"
filePath string
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't quite see the reason for file global var when its not used in the flags.StringVarP call. It should either be named a little more descriptively (filePathArgName?) and used there too or we just hard code use of "file" every where.

I'm not a fan of the "variable for the variable name" approach...

PreRunE: func(c *cobra.Command, args []string) error {
if !isInputFromPipe() {
path, _ := c.Flags().GetString(fPath)
path, _ := c.Flags().GetString(file)
Copy link
Contributor

Choose a reason for hiding this comment

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

path isn't ever being used right?

@@ -61,8 +61,8 @@ func Test_templateCmd(t *testing.T) {
if err := root.Execute(); err != nil {
t.Error(err)
}
if !strings.Contains(out.String(), "create a workflow template") {
t.Error("expected output should include create a workflow template")
if !strings.Contains(out.String(), "Create template using the --file flag") {
Copy link
Contributor

Choose a reason for hiding this comment

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

can be DRY'd by doing:

want := "Create template using the --file flag"
if !strings.Contains(out.String(), want) {
    t.Error("unexpected output, looking for %q as a substring in %q", want, out.String())
}

or similar

@@ -112,8 +112,8 @@ func Test_templateCmd(t *testing.T) {
if err := root.Execute(); err != nil {
t.Error(err)
}
if !strings.Contains(out.String(), "update a template") {
t.Error("expected output should include update a template")
if !strings.Contains(out.String(), "Update an existing template") {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

gauravgahlot
gauravgahlot previously approved these changes Jan 12, 2021
parauliya and others added 4 commits January 21, 2021 14:42
…te/update' command in tink-cli

Signed-off-by: parauliya <aman@infracloud.io>
Signed-off-by: Gaurav Gahlot <gauravgahlot0107@gmail.com>
Signed-off-by: Gaurav Gahlot <gauravgahlot0107@gmail.com>
Signed-off-by: Gaurav Gahlot <gauravgahlot0107@gmail.com>
@gauravgahlot gauravgahlot self-requested a review January 21, 2021 09:31
@mergify mergify bot merged commit 26abf73 into tinkerbell:master Jan 21, 2021
Issues List automation moved this from In Progress to Just shipped Jan 21, 2021
@mmlb mmlb removed the ready-to-merge Signal to Mergify to merge the PR. label Jan 25, 2021
@parauliya parauliya deleted the Fix_377 branch February 25, 2021 07:51
gianarb pushed a commit that referenced this pull request Mar 3, 2021
Few weeks ago we decided to use --file for template creation:

#385

But a few days days ago probably during a rebase I broke that
behavior and left the template create command in a broken state

76793ee#diff-f5b9b4afa42ee036d5b6836337e9d6273de8c341267f7ea75eddc561f0ad6441

As detected by Dan #445

This commit should fix the issue, and it will require a documentation
update as soon as we release a new version of sandbox.
gianarb pushed a commit that referenced this pull request Mar 3, 2021
Few weeks ago we decided to use --file for template creation:

#385

But a few days days ago probably during a rebase I broke that
behavior and left the template create command in a broken state

76793ee#diff-f5b9b4afa42ee036d5b6836337e9d6273de8c341267f7ea75eddc561f0ad6441

As detected by Dan #445

This commit should fix the issue, and it will require a documentation
update as soon as we release a new version of sandbox.

Signed-off-by: Gianluca Arbezzano <gianarb92@gmail.com>
mergify bot added a commit that referenced this pull request Mar 3, 2021
A few weeks ago we decided to use --file for template creation:

#385

But a few days ago probably during a rebase, I broke that
behavior and left the template to create command in a broken state

76793ee#diff-f5b9b4afa42ee036d5b6836337e9d6273de8c341267f7ea75eddc561f0ad6441

As detected by Dan #445

This commit should fix the issue, and it will require a documentation
update as soon as we release a new version of the sandbox.

Fixed #445
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Denotes a PR that introduces potentially breaking changes that require user action. kind/feature Categorizes issue or PR as related to a new feature.
Projects
No open projects
Issues List
  
Just shipped
Development

Successfully merging this pull request may close these issues.

tink-cli should parse template name from the template itself
4 participants