Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch adds several example scripts - Host list provider - CAPI boot strap in kind cluster - Querying API objects - Kubernes nodes provider - Query logs via Api objects - Command to script argument passing The patch also introduced minor name changes. Signed-off-by: Vladimir Vivien <vivienv@vmware.com>
- Loading branch information
1 parent
2bece74
commit a2d6299
Showing
14 changed files
with
293 additions
and
43 deletions.
There are no files selected for viewing
This file contains 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,28 @@ | ||
# Copyright (c) 2020 VMware, Inc. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# This script shows how to use the host list provider. | ||
# As its name implies, this provider takes a list of hosts | ||
# and allows command functions to execute on those hosts using | ||
# SSH. | ||
# | ||
# This example requires an SSH server running on the targeted hosts. | ||
|
||
# setup and configuration | ||
ssh=ssh_config( | ||
username=os.username, | ||
private_key_path="{0}/.ssh/id_rsa".format(os.home), | ||
port=args.ssh_port, | ||
max_retries=5, | ||
) | ||
|
||
provider=host_list_provider(hosts=["localhost", "127.0.0.1"], ssh_config=ssh) | ||
hosts=resources(provider=provider) | ||
|
||
# commands to run on each host | ||
uptimes = run(cmd="uptime", resources=hosts) | ||
|
||
# result for resource 0 (localhost) | ||
print(uptimes[0].result) | ||
# result for resource 1 (127.0.0.1) | ||
print(uptimes[1].result) |
This file contains 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,22 @@ | ||
# Copyright (c) 2020 VMware, Inc. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
conf=crashd_config(workdir="/tmp/crashobjs") | ||
nspaces=[ | ||
"capi-kubeadm-bootstrap-system", | ||
"capi-kubeadm-control-plane-system", | ||
"capi-system capi-webhook-system", | ||
"capv-system capa-system", | ||
"cert-manager tkg-system", | ||
] | ||
|
||
|
||
kube_config(path=args.kubecfg) | ||
|
||
# capture Kubernetes API object and store in files (under working dir) | ||
kube_capture(what="objects", kinds=["services", "pods"], namespaces=nspaces) | ||
kube_capture(what="objects", kinds=["deployments", "replicasets"], namespaces=nspaces) | ||
kube_capture(what="objects", kinds=["clusters", "machines", "machinesets", "machinedeployments"], namespaces="tkg-system") | ||
|
||
# bundle files stored in working dir | ||
archive(output_file="/tmp/crashobjs.tar.gz", source_paths=[conf.workdir]) |
This file contains 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,39 @@ | ||
# Copyright (c) 2020 VMware, Inc. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# Kind CAPI Bootstrap example | ||
# The following script extracts CAPI bootstrap info from a kind cluster. | ||
|
||
# declare global default config for script | ||
conf=crashd_config(workdir="/tmp/crashd-test") | ||
|
||
kind_cluster = args.cluster_name | ||
|
||
# exports kind logs to a file under workdir directory | ||
run_local("kind export logs --name {0} {1}/kind-logs".format(kind_cluster, conf.workdir)) | ||
|
||
# runs `kind get kubeconfig` to capture kubeconfig file | ||
kind_cfg = capture_local( | ||
cmd="kind get kubeconfig --name {0}".format(kind_cluster), | ||
file_name="kind.kubecfg" | ||
) | ||
|
||
# declares default configuration for Kubernetes commands | ||
|
||
nspaces=[ | ||
"capi-kubeadm-bootstrap-system", | ||
"capi-kubeadm-control-plane-system", | ||
"capi-system capi-webhook-system", | ||
"capv-system capa-system", | ||
"cert-manager tkg-system", | ||
] | ||
|
||
kconf=kube_config(path=kind_cfg) | ||
|
||
# capture Kubernetes API object and store in files (under working dir) | ||
kube_capture(what="objects", kinds=["services", "pods"], namespaces=nspaces, kube_conf=kconf) | ||
kube_capture(what="objects", kinds=["deployments", "replicasets"], namespaces=nspaces, kube_conf=kconf) | ||
kube_capture(what="objects", kinds=["clusters", "machines", "machinesets", "machinedeployments"], namespaces="tkg-system", kube_conf=kconf) | ||
|
||
# bundle files stored in working dir | ||
archive(output_file="/tmp/crashout.tar.gz", source_paths=[conf.workdir]) |
This file contains 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,30 @@ | ||
# Copyright (c) 2020 VMware, Inc. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# This script shows how to use the kube nodes provider. | ||
# The kube node provider uses the Kubernetes Nodes objects | ||
# to enumerate compute resources that are part of the cluster. | ||
# It uses SSH to execute commands on those on nodes. | ||
# | ||
# This example requires an SSH and a Kubernetes cluster. | ||
|
||
# setup and configuration | ||
ssh=ssh_config( | ||
username=os.username, | ||
private_key_path="{0}/.ssh/id_rsa".format(os.home), | ||
port=args.ssh_port, | ||
max_retries=5, | ||
) | ||
|
||
hosts=resources( | ||
provider=kube_nodes_provider( | ||
kube_config=kube_config(path=args.kubecfg), | ||
ssh_config=ssh, | ||
), | ||
) | ||
|
||
# commands to run on each host | ||
uptimes = run(cmd="uptime", resources=hosts) | ||
|
||
# result for resource 0 (localhost) | ||
print(uptimes.result) |
This file contains 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,9 @@ | ||
# Copyright (c) 2020 VMware, Inc. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
conf=crashd_config(workdir="/tmp/crashlogs") | ||
kube_config(path="{0}/.kube/config".format(os.home)) | ||
kube_capture(what="logs", namespaces=["default", "cert-manager", "tkg-system"]) | ||
|
||
# bundle files stored in working dir | ||
archive(output_file="/tmp/craslogs.tar.gz", source_paths=[conf.workdir]) |
This file contains 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,9 @@ | ||
# Copyright (c) 2020 VMware, Inc. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
conf=crashd_config(workdir=args.workdir) | ||
kube_config(path=args.kubecfg) | ||
kube_capture(what="logs", namespaces=["default", "cert-manager", "tkg-system"]) | ||
|
||
# bundle files stored in working dir | ||
archive(output_file=args.output, source_paths=[args.workdir]) |
This file contains 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 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 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 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 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 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.