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

feature: Validate config before restarting rke2 #188

Open
mueller-ma opened this issue Jan 31, 2024 · 7 comments
Open

feature: Validate config before restarting rke2 #188

mueller-ma opened this issue Jan 31, 2024 · 7 comments
Labels
enhancement New feature or request

Comments

@mueller-ma
Copy link
Contributor

Summary

I had the following invalid ansible-role-rke2 config which lead to a broken /etc/rancher/rke2/config.yaml on the server:

rke2_server_options:
  service-node-port-range: 20000-32767

Maybe the config.yaml can be validated before trying to restart any service?

Issue Type

Feature Idea

@mueller-ma mueller-ma added the enhancement New feature or request label Jan 31, 2024
@mueller-ma
Copy link
Contributor Author

@MonolithProjects Would you accept an PR that installs yamllint on the node and uses that to validate /etc/rancher/rke2/config.yaml? It can be made optional to avoid the installation of yamllint.

@MonolithProjects
Copy link
Collaborator

Hi, yamllint will not catch this. As far as i know, currently it is not possible to check RKE2 config prior the service start/restart.

@mueller-ma
Copy link
Contributor Author

In this case yamllint will catch the issue:

$ yamllint /etc/rancher/rke2/config.yaml -d relaxed
/etc/rancher/rke2/config.yaml
  1:1       warning  too many blank lines (1 > 0)  (empty-lines)
  16:1      error    syntax error: could not find expected ':' (syntax)

(Warning can be ignored)

@MonolithProjects
Copy link
Collaborator

But you wrote that your problem was caused by

rke2_server_options:
  service-node-port-range: 20000-32767

I thought you are talking about some kind of port conflict because of you changed the ports range. And of course this can not cause yaml syntax issue.

What was the problem in the line no.16 ?

@mueller-ma
Copy link
Contributor Author

The following yaml in Ansible causes an invalid yaml file on the server:

# On Ansible controller
rke2_server_options:
  service-node-port-range: 20000-32767
# On rke2 server
$ sudo grep service-node-port-range /etc/rancher/rke2/config.yaml
service-node-port-range:
# Invalid yaml here. Causes 'syntax error: could not find expected ':' (syntax)'

Correct is:

# On Ansible controller
rke2_server_options:
  - "service-node-port-range: '20000-32767'"
# On rke2 server
$ sudo grep service-node-port-range /etc/rancher/rke2/config.yaml
service-node-port-range: '20000-32767' # Valid yaml here

@MonolithProjects
Copy link
Collaborator

Ah OK got it now. rke2_server_options variable has to be a list. To make sure we are using correct variable type we should use assert module and introduce task which will check them. I am reopening this issue.

@mueller-ma
Copy link
Contributor Author

Indeed, that's better than using yamllint on the final config. Maybe use Role argument validation instead of adding a task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants