-
Notifications
You must be signed in to change notification settings - Fork 4
inv: import cluster creation tasks #50
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
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 1.28.5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| { "allowedUnsafeSysctls": ["net.*"] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "sysctls": { | ||
| "netCoreRmemMax": 16777216, | ||
| "netCoreWmemMax": 16777216, | ||
| "netIpv4TcpRmem": "4096 87380 16777216", | ||
| "netIpv4TcpWmem": "4096 65536 16777216", | ||
| "netCoreNetdevMaxBacklog": "30000", | ||
| "netCoreRmemDefault": 16777216, | ||
| "netCoreWmemDefault": 16777216, | ||
| "netIpv4TcpMem": "16777216 16777216 16777216", | ||
| "netIpv4RouteFlush": 1 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| from invoke import task | ||
| from os.path import join | ||
| from subprocess import run | ||
| from tasks.util.env import ( | ||
| ACR_NAME, | ||
| AKS_CLUSTER_NAME, | ||
| AKS_NODE_COUNT, | ||
| AKS_REGION, | ||
| AKS_VM_SIZE, | ||
| AZURE_PUB_SSH_KEY, | ||
| AZURE_RESOURCE_GROUP, | ||
| CONFIG_DIR, | ||
| KUBECTL_BIN, | ||
| ) | ||
| from tasks.util.version import get_k8s_version | ||
|
|
||
|
|
||
| # AKS commandline reference here: | ||
| # https://docs.microsoft.com/en-us/cli/azure/aks?view=azure-cli-latest | ||
| def _run_aks_cmd(name, az_args=None): | ||
| cmd = [ | ||
| "az", | ||
| "aks {}".format(name), | ||
| "--resource-group {}".format(AZURE_RESOURCE_GROUP), | ||
| ] | ||
|
|
||
| if az_args: | ||
| cmd.extend(az_args) | ||
|
|
||
| cmd = " ".join(cmd) | ||
| print(cmd) | ||
| run(cmd, shell=True, check=True) | ||
|
|
||
|
|
||
| @task | ||
| def list(ctx): | ||
| """ | ||
| List all AKS resources | ||
| """ | ||
| _run_aks_cmd("list") | ||
|
|
||
|
|
||
| @task(optional=["sgx"]) | ||
| def provision( | ||
| ctx, | ||
| nodes=AKS_NODE_COUNT, | ||
| vm=AKS_VM_SIZE, | ||
| location=AKS_REGION, | ||
| name=AKS_CLUSTER_NAME, | ||
| sgx=False, | ||
| granny=True, | ||
| ): | ||
| """ | ||
| Provision the AKS cluster | ||
| """ | ||
| k8s_ver = get_k8s_version() | ||
| sgx = sgx and (sgx.lower() != "false") | ||
| granny_kubelet_config = join(CONFIG_DIR, "granny_aks_kubelet_config.json") | ||
| granny_os_config = join(CONFIG_DIR, "granny_aks_os_config.json") | ||
|
|
||
| if sgx and "Standard_DC" not in vm: | ||
| print( | ||
| "Error provisioning SGX cluster: only `Standard_DC` VMs are supported" | ||
| ) | ||
| return | ||
|
|
||
| _run_aks_cmd( | ||
| "create", | ||
| [ | ||
| "--name {}".format(name), | ||
| "--node-count {}".format(nodes), | ||
| "--node-vm-size {}".format(vm), | ||
| "--os-sku Ubuntu", | ||
| "--kubernetes-version {}".format(k8s_ver), | ||
| "--ssh-key-value {}".format(AZURE_PUB_SSH_KEY), | ||
| "--location {}".format(location), | ||
| # Could not create a role assignment for ACR. Are you an Owner on this subscription? | ||
| # "--attach-acr {}".format(ACR_NAME.split(".")[0]), | ||
| "{}".format( | ||
| "--kubelet-config {}".format(granny_kubelet_config) | ||
| if granny | ||
| else "" | ||
| ), | ||
| "{}".format( | ||
| "--linux-os-config {}".format(granny_os_config) | ||
| if granny | ||
| else "" | ||
| ), | ||
| "{}".format( | ||
| "--enable-addons confcom --enable-sgxquotehelper" | ||
| if sgx | ||
| else "" | ||
| ), | ||
| ], | ||
| ) | ||
|
|
||
|
|
||
| @task | ||
| def details(ctx): | ||
| """ | ||
| Show the details of the cluster | ||
| """ | ||
| _run_aks_cmd( | ||
| "show", | ||
| [ | ||
| "--name {}".format(AKS_CLUSTER_NAME), | ||
| ], | ||
| ) | ||
|
|
||
|
|
||
| @task | ||
| def delete(ctx, name=AKS_CLUSTER_NAME): | ||
| """ | ||
| Delete the AKS cluster | ||
| """ | ||
| _run_aks_cmd( | ||
| "delete", | ||
| [ | ||
| "--name {}".format(name), | ||
| "--yes", | ||
| ], | ||
| ) | ||
|
|
||
|
|
||
| @task | ||
| def credentials(ctx, name=AKS_CLUSTER_NAME, out_file=None): | ||
| """ | ||
| Get credentials for the AKS cluster | ||
| """ | ||
| # Set up the credentials | ||
| _run_aks_cmd( | ||
| "get-credentials", | ||
| [ | ||
| "--name {}".format(name), | ||
| "--overwrite-existing", | ||
| "--file {}".format(out_file) if out_file else "", | ||
| ], | ||
| ) | ||
|
|
||
| # Check we can access the cluster | ||
| cmd = "{} get nodes".format(KUBECTL_BIN) | ||
| print(cmd) | ||
| run(cmd, shell=True, check=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| from invoke import task | ||
| from os.path import join, exists | ||
| from os import makedirs | ||
| from shutil import copy, rmtree | ||
| from subprocess import run | ||
|
|
||
| from tasks.util.env import ( | ||
| BIN_DIR, | ||
| GLOBAL_BIN_DIR, | ||
| K9S_VERSION, | ||
| ) | ||
|
|
||
| from tasks.util.version import get_k8s_version | ||
|
|
||
|
|
||
| def _download_binary(url, binary_name): | ||
| makedirs(BIN_DIR, exist_ok=True) | ||
| cmd = "curl -LO {}".format(url) | ||
| run(cmd, shell=True, check=True, cwd=BIN_DIR) | ||
| run("chmod +x {}".format(binary_name), shell=True, check=True, cwd=BIN_DIR) | ||
|
|
||
| return join(BIN_DIR, binary_name) | ||
|
|
||
|
|
||
| def _symlink_global_bin(binary_path, name): | ||
| global_path = join(GLOBAL_BIN_DIR, name) | ||
| if exists(global_path): | ||
| print("Removing existing binary at {}".format(global_path)) | ||
| run( | ||
| "sudo rm -f {}".format(global_path), | ||
| shell=True, | ||
| check=True, | ||
| ) | ||
|
|
||
| print("Symlinking {} -> {}".format(global_path, binary_path)) | ||
| run( | ||
| "sudo ln -s {} {}".format(binary_path, name), | ||
| shell=True, | ||
| check=True, | ||
| cwd=GLOBAL_BIN_DIR, | ||
| ) | ||
|
|
||
|
|
||
| @task | ||
| def install_kubectl(ctx, system=False): | ||
| """ | ||
| Install the k8s CLI (kubectl) | ||
| """ | ||
| k8s_ver = get_k8s_version() | ||
| url = "https://dl.k8s.io/release/v{}/bin/linux/amd64/kubectl".format( | ||
| k8s_ver | ||
| ) | ||
|
|
||
| binary_path = _download_binary(url, "kubectl") | ||
|
|
||
| # Symlink for kubectl globally | ||
| if system: | ||
| _symlink_global_bin(binary_path, "kubectl") | ||
|
|
||
|
|
||
| @task | ||
| def install_k9s(ctx, system=False): | ||
| """ | ||
| Install the K9s CLI | ||
| """ | ||
| tar_name = "k9s_Linux_amd64.tar.gz" | ||
| url = "https://github.com/derailed/k9s/releases/download/v{}/{}".format( | ||
| K9S_VERSION, tar_name | ||
| ) | ||
| print(url) | ||
|
|
||
| # Download the TAR | ||
| workdir = "/tmp/k9s-csg" | ||
| makedirs(workdir, exist_ok=True) | ||
|
|
||
| cmd = "curl -LO {}".format(url) | ||
| run(cmd, shell=True, check=True, cwd=workdir) | ||
|
|
||
| # Untar | ||
| run("tar -xf {}".format(tar_name), shell=True, check=True, cwd=workdir) | ||
|
|
||
| # Copy k9s into place | ||
| binary_path = join(BIN_DIR, "k9s") | ||
| copy(join(workdir, "k9s"), binary_path) | ||
|
|
||
| # Remove tar | ||
| rmtree(workdir) | ||
|
|
||
| # Symlink for k9s command globally | ||
| if system: | ||
| _symlink_global_bin(binary_path, "k9s") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.