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

cli: add config command and config validate subcommand to nomad CLI #9198

Merged
merged 2 commits into from
Feb 8, 2022

Conversation

th0m
Copy link
Contributor

@th0m th0m commented Oct 27, 2020

This command is similar to the consul validate command and can be used to perform configuration validation before actually restarting Nomad and risking a failure if there is an issue in the configuration.

Also added three test cases to the command test suite:

  1. Empty directory which is acceptable
  2. Working configuration
  3. Non-working configuration

@th0m th0m changed the title Add config-validate command to nomad CLI cli: add config-validate command to nomad CLI Oct 27, 2020
Copy link
Member

@jrasell jrasell left a comment

Choose a reason for hiding this comment

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

Thanks very much for this @th0m.

I would be curious of your thoughts, as well as others, around the command nomad config validate rather than nomad config-validate? In my mind, this allows for additional config based sub-commands in the future thus providing future flexibility while keeping the experience consistent.

@th0m
Copy link
Contributor Author

th0m commented Oct 28, 2020

Makes sense to me @jrasell, happy to change it.

@th0m th0m force-pushed the tlefebvre/add-config-validate-command branch from 501babd to 85b7249 Compare October 28, 2020 20:58
@th0m th0m changed the title cli: add config-validate command to nomad CLI cli: add config command and config validate subcommand to nomad CLI Oct 28, 2020
jrasell
jrasell previously requested changes Nov 2, 2020
Copy link
Member

@jrasell jrasell left a comment

Choose a reason for hiding this comment

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

Thanks for the update. I have suggested a couple of changes along with a question regarding the error handling which I would be keen to get your feedback on as a target user for this command.

}
defer os.Remove(fh)

ui := new(cli.MockUi)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ui := new(cli.MockUi)
ui := cli.NewMockUi()

t.Fatalf("err: %s", err)
}

ui := new(cli.MockUi)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ui := new(cli.MockUi)
ui := cli.NewMockUi()

t.Fatalf("err: %s", err)
}

ui := new(cli.MockUi)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ui := new(cli.MockUi)
ui := cli.NewMockUi()

Comment on lines 58 to 61
if err != nil {
c.Ui.Error(fmt.Sprintf(
"Error loading configuration from %s: %s", path, err))
return 1
Copy link
Member

Choose a reason for hiding this comment

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

I am curious on your thoughts here around the use of multierror? In the event of multiple files having validation issues, the command can output all the errors in a single run, rather than needing the operator to run the command multiple times to fix each issue which is displayed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great idea, I'll use multierror.

@jrasell jrasell self-assigned this Nov 2, 2020
@dadgar
Copy link
Contributor

dadgar commented Nov 7, 2020

@jrasell @th0m It may be good to refactor the isValidConfig call so that it can be used here. Currently, the command just validates the config can be parsed, but it may have settings that will cause Nomad not to be able to start:

@th0m
Copy link
Contributor Author

th0m commented Dec 13, 2021

Thanks for the review @dadgar and @jrasell.
I just rebased my branch and will follow up on your comments shortly.

@th0m
Copy link
Contributor Author

th0m commented Jan 20, 2022

@dadgar following your suggestion I've made the isValidConfig function visible to other packages to be able to use it here and perform config validation in addition to parsability validation.
I've added a test that catches a bad configuration that is otherwise parsable.

@jrasell I think I have addressed all your comments, can you please re-review?

Thanks both.

@th0m
Copy link
Contributor Author

th0m commented Jan 28, 2022

@jrasell sorry about the repeated ping but in case you missed my previous message this PR is now ready for review 🙂
Thank you!

@th0m
Copy link
Contributor Author

th0m commented Feb 7, 2022

@jrasell @tgross may I have a review here when you have a minute? Thank you so much!

@tgross tgross self-requested a review February 7, 2022 16:58
@tgross tgross self-assigned this Feb 7, 2022
Copy link
Member

@tgross tgross left a comment

Choose a reason for hiding this comment

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

Looking pretty good @th0m! I've left some comments but mostly it's just tightening up language at this point.

command/config_validate.go Outdated Show resolved Hide resolved
command/config_validate.go Outdated Show resolved Hide resolved
@th0m th0m force-pushed the tlefebvre/add-config-validate-command branch from c8f821f to 0cfb338 Compare February 7, 2022 19:57
@vercel vercel bot temporarily deployed to Preview – nomad February 7, 2022 19:57 Inactive
@th0m
Copy link
Contributor Author

th0m commented Feb 7, 2022

Thank you @tgross, I have committed both of your suggestions and squashed the three commits into one.

Copy link
Member

@tgross tgross left a comment

Choose a reason for hiding this comment

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

LGTM

@tgross tgross dismissed jrasell’s stale review February 8, 2022 21:52

These issues were addressed.

@tgross tgross merged commit 41f84c6 into hashicorp:main Feb 8, 2022
@th0m
Copy link
Contributor Author

th0m commented Feb 9, 2022

Thanks @tgross!

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Development

Successfully merging this pull request may close these issues.

4 participants