-
Notifications
You must be signed in to change notification settings - Fork 116
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
Script Runner addon #229
base: master
Are you sure you want to change the base?
Script Runner addon #229
Conversation
Signed-off-by: Waleed Gadelkareem <[email protected]>
Signed-off-by: Waleed Gadelkareem <[email protected]>
Signed-off-by: Waleed Gadelkareem <[email protected]>
Signed-off-by: Waleed Gadelkareem <[email protected]>
wow, that's I cool. I'll review asap |
Yeah! I suggest to allow to specify the server type, actually we have 3 main "type" of server, |
@mavimo we can use the power of bash and keep the addon simple :)
|
@gadelkareem it's a possibility, so the addon is simple but bash script should be "complex" ;) I think is also a bit fragile because we can't guarantee that the name of server match the master / worker / etcd name, we generate new server with the specified name but a user can add the server to the pool with a different name or rename it.. so IMHO we should move server type definition on addon instead of into the script that we deploy |
@mavimo I see that the names are not constant, especially if it is an external server being added. Maybe we should have a file on the server to hint its type? I think the bash script will probably be much more complex than the hostname check example above. And since the user already knows his own cluster then it should be trivial to manage the script based on the hostname or any other properties. Because if we start adding a new argument for each use case then it will not be as simple as now. For example, with the current use case of choosing the instance group to run on, we will need to think if the user also wants to run the script on 2 groups (master and worker) or 3 of them. And what if there is a new group created then we need to modify this addon. That's why I always prefer to keep it simple and if we have feature request then it could be added to it. |
@gadelkareem WDYT to send as args to script invocation some information about current server / cluster topology? |
@mavimo good idea! which info do you think would be nice to pass to the script? |
@gadelkareem NB: I'm not sure but what we should pass, I'll try to write some proposal for discussion 😄 We should start with something like:
Maybe point 2 and 3 should be mixed if we build a JSON that contains all cluster information as second argument like:
where script should process the second information if needed (eg: |
Signed-off-by: Waleed Gadelkareem <[email protected]>
Ok so now the script will have the node group as first param then the cluster info which is the same as the JSON from the config file. |
Signed-off-by: Waleed Gadelkareem <[email protected]>
I also allowed the display of output for each node since it will be different. |
The LGTM already, but I would love to see some docs for the users on how to use that. With some examples, so users will know how to deal with the params. Maybe a distinct page like the HA-guide and wireguard info page? |
pkg/addons/addon_script_runner.go
Outdated
package addons | ||
|
||
import ( | ||
"fmt" |
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.
Please re-sort import definition, typically:
- stdlib packages (alphabetic)
- EMPTY LINE
- other packages (alphabetic)
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.
hmm.. did you mean remove empty line?
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.
I mean that we should change it to:
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"strings"
"time"
"github.com/xetys/hetzner-kube/pkg/clustermanager"
)
FatalOnError(err) | ||
|
||
replacer := strings.NewReplacer("\n", "", "'", "\\'") | ||
clusterInfo := replacer.Replace(string(clusterInfoBin)) |
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.
I'm not sure to understand why we are going to use replacer here, this is needed since there are some info in JSON encoded that can generate invalid string argument? Is possibile to use some different approach in order to do not manipulate result value, like:
echo $(cat <<EOF
<JSON_MARSHALLED_VALUE>
EOF)
I'm not sure is doable, but will allow us to do not manipulate the value and be "safe" on changes we do in config..
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.
I don't think the run command will allow multi line. If it works for you, please let me know.
@gadelkareem do you have time to write some doc? If you need some help please ping me :) |
@mavimo Since you are asking. Do you have an example config.json that i can use? |
added some docs! |
docs/script-runner-addon.md
Outdated
# Script Runner Addon Guide | ||
|
||
Script Runner lets you run a bash script on all your cluster nodes with one command. It uploads the bash script to each node then execute. The script will receive two arguments upon execution: | ||
1) Node group, for example (master, worker, etcd) |
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.
Markdown suggest to use:
1) Node group, for example (master, worker, etcd) | |
1. Node group, allowed values are `master`, `worker` and `etcd` |
docs/script-runner-addon.md
Outdated
|
||
Script Runner lets you run a bash script on all your cluster nodes with one command. It uploads the bash script to each node then execute. The script will receive two arguments upon execution: | ||
1) Node group, for example (master, worker, etcd) | ||
2) Cluster info JSON config, which is similar to the hetzner-kube config found in `~/.hetzner-kube/config.json` |
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.
Markdown suggest to use
2) Cluster info JSON config, which is similar to the hetzner-kube config found in `~/.hetzner-kube/config.json` | |
1. Cluster info JSON config, which is similar to the `hetzner-kube` configuration that you can found in `~/.hetzner-kube/config.json` |
``` | ||
Example script.sh: | ||
```bash | ||
|
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.
Bash script should start with:
#!/bin/bash
this should be omitted (than specify on the doc that should not be included) or is missing here (than add to the sample)?
2) Cluster info JSON config, which is similar to the hetzner-kube config found in `~/.hetzner-kube/config.json` | ||
|
||
### Example | ||
hetzner-kube Command: |
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.
Please add a space between title and text and between text and code sample
@gadelkareem I know I should sound like a "nuisance" (sorry), added some comments to the doc :) |
cool done ;) |
Script Runner makes it easy to run a bash script on all your k8s nodes with one command.