1
0
mirror of https://github.com/ubuntu/microk8s.git synced 2021-05-23 02:23:41 +03:00

Pass through subcommands as if there were called directly (#1057)

This commit is contained in:
Joe Borg
2020-03-25 03:54:07 -04:00
committed by GitHub
parent 48d5102f86
commit 575d4159df
37 changed files with 106 additions and 68 deletions

View File

@@ -30,6 +30,6 @@ script:
- export UNDER_TIME_PRESSURE="True"
- (cd tests; pytest -s verify-branches.py)
- (cd tests; sudo -E pytest -s -ra test-addons.py)
- sudo microk8s.reset
- sudo microk8s reset
- sudo snap remove microk8s
- sudo -E UPGRADE_MICROK8S_FROM=edge UPGRADE_MICROK8S_TO=`pwd`/`ls microk8s*.snap` pytest -s ./tests/test-upgrade.py

View File

@@ -1,3 +1,3 @@
Please run `microk8s.inspect` and attach the generated tarball to this issue.
Please run `microk8s inspect` and attach the generated tarball to this issue.
We appreciate your feedback. Thank you for using microk8s.

View File

@@ -55,17 +55,17 @@ Install MicroK8s with:
snap install microk8s --classic
```
MicroK8s includes a `microk8s.kubectl` command:
MicroK8s includes a `microk8s kubectl` command:
```
sudo microk8s.kubectl get nodes
sudo microk8s.kubectl get services
sudo microk8s kubectl get nodes
sudo microk8s kubectl get services
```
To use MicroK8s with your existing kubectl:
```
sudo microk8s.kubectl config view --raw > $HOME/.kube/config
sudo microk8s kubectl config view --raw > $HOME/.kube/config
```
#### User access without sudo
@@ -78,13 +78,13 @@ sudo usermod -a -G microk8s <username>
#### Kubernetes add-ons
MicroK8s installs a barebones upstream Kubernetes. Additional services like dns and the Kubernetes dashboard can be enabled using the `microk8s.enable` command.
MicroK8s installs a barebones upstream Kubernetes. Additional services like dns and the Kubernetes dashboard can be enabled using the `microk8s enable` command.
```
sudo microk8s.enable dns dashboard
sudo microk8s enable dns dashboard
```
Use `microk8s.status` to see a list of enabled and available addons. You can find the addon manifests and/or scripts under `${SNAP}/actions/`, with `${SNAP}` pointing by default to `/snap/microk8s/current`.
Use `microk8s status` to see a list of enabled and available addons. You can find the addon manifests and/or scripts under `${SNAP}/actions/`, with `${SNAP}` pointing by default to `/snap/microk8s/current`.
## Documentation

View File

@@ -18,7 +18,7 @@ exit_if_stopped() {
# test if the snap is marked as stopped
if [ -e ${SNAP_DATA}/var/lock/stopped.lock ]
then
echo "microk8s is not running, try microk8s.start" >&2
echo "microk8s is not running, try microk8s start" >&2
exit 1
fi
}

View File

@@ -6,4 +6,4 @@ source $SNAP/actions/common/utils.sh
echo "Disabling the private registry"
use_manifest registry delete
echo "The registry is disabled. Use 'microk8s.disable storage:destroy-storage' to free the storage space."
echo "The registry is disabled. Use 'microk8s disable storage:destroy-storage' to free the storage space."

View File

@@ -10,10 +10,10 @@ use_manifest dashboard apply
echo "
If RBAC is not enabled access the dashboard using the default token retrieved with:
token=\$(microk8s.kubectl -n kube-system get secret | grep default-token | cut -d \" \" -f1)
microk8s.kubectl -n kube-system describe secret \$token
token=\$(microk8s kubectl -n kube-system get secret | grep default-token | cut -d \" \" -f1)
microk8s kubectl -n kube-system describe secret \$token
In an RBAC enabled setup (microk8s.enable RBAC) you need to create a user with restricted
In an RBAC enabled setup (microk8s enable RBAC) you need to create a user with restricted
permissions as shown in:
https://github.com/kubernetes/dashboard/blob/master/docs/user/access-control/creating-sample-user.md
"

View File

@@ -257,12 +257,12 @@ def main():
To see these values again, run:
microk8s.juju config dex-auth static-username
microk8s.juju config dex-auth static-password
microk8s juju config dex-auth static-username
microk8s juju config dex-auth static-password
To tear down Kubeflow and associated infrastructure, run:
microk8s.disable kubeflow
microk8s disable kubeflow
"""
% (hostname, password)
)

View File

@@ -27,7 +27,7 @@ then
if [ -z "${ip_range}" ]
then
echo "You have to input an IP Range value when asked, or provide it as an argument to the enable command, eg:"
echo " microk8s.enable metallb:10.64.140.43-10.64.140.49"
echo " microk8s enable metallb:10.64.140.43-10.64.140.49"
exit 1
fi
else

View File

@@ -11,12 +11,12 @@ source $SNAP/actions/common/utils.sh
if [ -e ${SNAP_DATA}/var/lock/clustered.lock ]
then
echo "This MicroK8s deployment is acting as a node in a cluster. Please use the microk8s.add-node on the master."
echo "This MicroK8s deployment is acting as a node in a cluster. Please use the microk8s add-node on the master."
exit 1
fi
if echo "$*" | grep -q -- 'help'; then
echo "Usage: microk8s.add-node"
echo "Usage: microk8s add-node"
echo ""
echo "Produce a connection string for a node to join the cluster"
exit 0
@@ -52,12 +52,12 @@ fi
default_ip="$(get_default_ip)"
all_ips="$(get_ips)"
echo "Join node with: microk8s.join ${default_ip}:$port/${token}"
echo "Join node with: microk8s join ${default_ip}:$port/${token}"
echo ""
echo "If the node you are adding is not reachable through the default interface you can use one of the following:"
for addr in $(echo "${all_ips}"); do
if ! [[ $addr == *":"* ]]; then
echo " microk8s.join ${addr}:$port/${token}"
echo " microk8s join ${addr}:$port/${token}"
fi
done

View File

@@ -7,7 +7,7 @@ ARCH="$($SNAP/bin/uname -m)"
export LD_LIBRARY_PATH="$SNAP/lib:$SNAP/usr/lib:$SNAP/lib/$ARCH-linux-gnu:$SNAP/usr/lib/$ARCH-linux-gnu"
if [ ! -f "${SNAP_DATA}/bin/cilium" ]; then
echo "Cilium not available, try enabling it with 'microk8s.enable cilium'" >&2
echo "Cilium not available, try enabling it with 'microk8s enable cilium'" >&2
exit 0
fi

View File

@@ -8,7 +8,7 @@ source $SNAP/actions/common/utils.sh
if [ -e ${SNAP_DATA}/var/lock/clustered.lock ]
then
echo "This MicroK8s deployment is acting as a node in a cluster. Please use the microk8s.config on the master."
echo "This MicroK8s deployment is acting as a node in a cluster. Please use the microk8s config on the master."
exit 0
fi
@@ -24,7 +24,7 @@ while true; do
-h|--help)
echo "Usage: $0 [OPTIONS]"
echo
echo "Retrieve the client config, similar to microk8s.kubectl config view --raw"
echo "Retrieve the client config, similar to microk8s kubectl config view --raw"
echo
echo "Options:"
echo " -h, --help Show this help"

View File

@@ -10,7 +10,7 @@ source $SNAP/actions/common/utils.sh
if [ -e ${SNAP_DATA}/var/lock/clustered.lock ]
then
echo "This MicroK8s deployment is acting as a node in a cluster. Please use the microk8s.disable on the master."
echo "This MicroK8s deployment is acting as a node in a cluster. Please use the microk8s disable on the master."
exit 0
fi

View File

@@ -10,7 +10,7 @@ source $SNAP/actions/common/utils.sh
if [ -e ${SNAP_DATA}/var/lock/clustered.lock ]
then
echo "This MicroK8s deployment is acting as a node in a cluster. Please use the microk8s.enable on the master."
echo "This MicroK8s deployment is acting as a node in a cluster. Please use the microk8s enable on the master."
exit 0
fi

View File

@@ -7,7 +7,7 @@ ARCH="$($SNAP/bin/uname -m)"
export LD_LIBRARY_PATH="$SNAP/lib:$SNAP/usr/lib:$SNAP/lib/$ARCH-linux-gnu:$SNAP/usr/lib/$ARCH-linux-gnu"
if [ ! -f "${SNAP_DATA}/bin/helm" ]; then
echo "Helm not available, try enabling it with 'microk8s.enable helm'" >&2
echo "Helm not available, try enabling it with 'microk8s enable helm'" >&2
exit 0
fi

View File

@@ -7,7 +7,7 @@ ARCH="$($SNAP/bin/uname -m)"
export LD_LIBRARY_PATH="$SNAP/lib:$SNAP/usr/lib:$SNAP/lib/$ARCH-linux-gnu:$SNAP/usr/lib/$ARCH-linux-gnu"
if [ ! -f "${SNAP_DATA}/bin/helm3" ]; then
echo "Helm 3 not available, try enabling it with 'microk8s.enable helm3'" >&2
echo "Helm 3 not available, try enabling it with 'microk8s enable helm3'" >&2
exit 0
fi

View File

@@ -7,7 +7,7 @@ ARCH="$($SNAP/bin/uname -m)"
export LD_LIBRARY_PATH="$SNAP/lib:$SNAP/usr/lib:$SNAP/lib/$ARCH-linux-gnu:$SNAP/usr/lib/$ARCH-linux-gnu"
if [ ! -f "${SNAP_DATA}/bin/istioctl" ]; then
echo "Istio not available, try enabling is with 'microk8s.enable istio'"
echo "Istio not available, try enabling is with 'microk8s enable istio'"
exit 0
fi
@@ -15,7 +15,7 @@ source $SNAP/actions/common/utils.sh
if [ -e ${SNAP_DATA}/var/lock/clustered.lock ]
then
echo "This MicroK8s deployment is acting as a node in a cluster. Please use the microk8s.istioctl on the master."
echo "This MicroK8s deployment is acting as a node in a cluster. Please use the microk8s istioctl on the master."
exit 0
fi

View File

@@ -7,7 +7,7 @@ source $SNAP/actions/common/utils.sh
if [ -e ${SNAP_DATA}/var/lock/clustered.lock ]
then
echo "This MicroK8s deployment is acting as a node in a cluster. Please use the microk8s.kubectl on the master."
echo "This MicroK8s deployment is acting as a node in a cluster. Please use the microk8s kubectl on the master."
exit 0
fi

View File

@@ -10,9 +10,9 @@ export SNAP_NAME
source $SNAP/actions/common/utils.sh
if echo "$*" | grep -q -- 'help'; then
echo "Usage: microk8s.leave"
echo "Usage: microk8s leave"
echo ""
echo "With microk8s.leave the node will depart from the cluster it is in."
echo "With microk8s leave the node will depart from the cluster it is in."
exit 0
fi

View File

@@ -8,12 +8,12 @@ export LD_LIBRARY_PATH="$SNAP/lib:$SNAP/usr/lib:$SNAP/lib/$ARCH-linux-gnu:$SNAP/
if [ -e ${SNAP_DATA}/var/lock/clustered.lock ]
then
echo "This MicroK8s deployment is acting as a node in a cluster. Please use the microk8s.linkerd on the master."
echo "This MicroK8s deployment is acting as a node in a cluster. Please use the microk8s linkerd on the master."
exit 0
fi
if [ ! -f "${SNAP_DATA}/bin/linkerd" ]; then
echo "Linkerd not available, try enabling Linkerd. 'microk8s.enable linkerd' or 'microk8s.enable linkerd:--proxy-auto-inject' "
echo "Linkerd not available, try enabling Linkerd. 'microk8s enable linkerd' or 'microk8s enable linkerd:--proxy-auto-inject' "
exit 0
fi

View File

@@ -10,9 +10,9 @@ export SNAP_NAME
source $SNAP/actions/common/utils.sh
if echo "$*" | grep -q -- 'help'; then
echo "Usage: microk8s.remove <node>"
echo "Usage: microk8s remove <node>"
echo ""
echo "microk8s.remove will remove the node provided from the cluster."
echo "microk8s remove will remove the node provided from the cluster."
exit 0
fi
@@ -20,7 +20,7 @@ exit_if_no_permissions
if [ -e ${SNAP_DATA}/var/lock/clustered.lock ]
then
echo "This MicroK8s deployment is acting as a node in a cluster. Please use microk8s.leave."
echo "This MicroK8s deployment is acting as a node in a cluster. Please use microk8s leave."
exit 1
fi

View File

@@ -25,9 +25,9 @@ disable_addons() {
addon_arguments=""
if [ "$action" = "storage" ] && [ ${destroy_storage_enabled} ]
then
microk8s.disable $action:destroy-storage > /dev/null 2>&1 || true
microk8s disable $action:destroy-storage > /dev/null 2>&1 || true
else
microk8s.disable $action > /dev/null 2>&1 || true
microk8s disable $action > /dev/null 2>&1 || true
fi
done
echo "All addons disabled."
@@ -101,7 +101,7 @@ clean_cluster() {
if [ -e ${SNAP_DATA}/var/lock/clustered.lock ]
then
echo "This MicroK8s deployment is acting as a node in a cluster. Please use the microk8s.reset on the master."
echo "This MicroK8s deployment is acting as a node in a cluster. Please use the microk8s reset on the master."
exit 0
fi

View File

@@ -7,7 +7,7 @@ source $SNAP/actions/common/utils.sh
if [ -e ${SNAP_DATA}/var/lock/clustered.lock ]
then
echo "This MicroK8s deployment is acting as a node in a cluster. Please use the microk8s.reset on the master."
echo "This MicroK8s deployment is acting as a node in a cluster. Please use the microk8s reset on the master."
exit 0
fi

View File

@@ -8,7 +8,7 @@ source $SNAP/actions/common/utils.sh
if [ -e ${SNAP_DATA}/var/lock/clustered.lock ]
then
echo "This MicroK8s deployment is acting as a node in a cluster. Please use the microk8s.stop on the master."
echo "This MicroK8s deployment is acting as a node in a cluster. Please use the microk8s stop on the master."
exit 0
fi

View File

@@ -0,0 +1,36 @@
#!/usr/bin/env bash
set -e
function help() {
echo "Available subcommands are:"
for i in $(ls ${SNAP}/microk8s-*.wrapper | sed 's/microk8s-//g' | sed 's/.wrapper//g'); do
echo -e "\t$(basename ${i})"
done
echo -e "\tinspect"
}
if [ -z "$1" ]; then
help
exit 1
fi
readonly APP="$1"
shift
if [ -f "${SNAP}/microk8s-${APP}.wrapper" ]; then
"${SNAP}/microk8s-${APP}.wrapper" "$@"
readonly EXIT="$?"
elif [ "${APP}" == "inspect" ]; then
sudo SNAP_DATA=${SNAP_DATA} ${SNAP}/inspect.sh
readonly EXIT="$?"
elif [ "${APP}" == "help" ] || [ "${APP}" == "--help" ] || [ "$APP" == "-h" ]; then
help
readonly EXIT="0"
else
echo "'${APP}' is not a valid MicroK8s subcommand."
help
readonly EXIT="1"
fi
exit ${EXIT}

View File

@@ -88,7 +88,7 @@ then
if [ -e ${SNAP_DATA}/var/lock/stopped.lock ]
then
# Mark the api server as starting. This is needed incase you
# microk8s.stop and then snap start microk8s
# microk8s stop and then snap start microk8s
rm -f ${SNAP_DATA}/var/lock/stopped.lock &> /dev/null
fi
fi

View File

@@ -63,7 +63,7 @@ def get_connection_info(master_ip, master_port, token, callback_token):
def usage():
print("Join a cluster: microk8s.join <master>:<port>/<token>")
print("Join a cluster: microk8s join <master>:<port>/<token>")
def set_arg(key, value, file):

View File

@@ -94,12 +94,12 @@ function store_kubernetes_info {
# Collect some in-k8s details
printf -- ' Inspect kubernetes cluster\n'
mkdir -p $INSPECT_DUMP/k8s
sudo -E /snap/bin/microk8s.kubectl version 2>&1 | sudo tee $INSPECT_DUMP/k8s/version > /dev/null
sudo -E /snap/bin/microk8s.kubectl cluster-info 2>&1 | sudo tee $INSPECT_DUMP/k8s/cluster-info > /dev/null
sudo -E /snap/bin/microk8s.kubectl cluster-info dump 2>&1 | sudo tee $INSPECT_DUMP/k8s/cluster-info-dump > /dev/null
sudo -E /snap/bin/microk8s.kubectl get all --all-namespaces 2>&1 | sudo tee $INSPECT_DUMP/k8s/get-all > /dev/null
sudo -E /snap/bin/microk8s.kubectl get pv 2>&1 | sudo tee $INSPECT_DUMP/k8s/get-pv > /dev/null # 2>&1 redirects stderr and stdout to /dev/null if no resources found
sudo -E /snap/bin/microk8s.kubectl get pvc 2>&1 | sudo tee $INSPECT_DUMP/k8s/get-pvc > /dev/null # 2>&1 redirects stderr and stdout to /dev/null if no resources found
sudo -E /snap/bin/microk8s kubectl version 2>&1 | sudo tee $INSPECT_DUMP/k8s/version > /dev/null
sudo -E /snap/bin/microk8s kubectl cluster-info 2>&1 | sudo tee $INSPECT_DUMP/k8s/cluster-info > /dev/null
sudo -E /snap/bin/microk8s kubectl cluster-info dump 2>&1 | sudo tee $INSPECT_DUMP/k8s/cluster-info-dump > /dev/null
sudo -E /snap/bin/microk8s kubectl get all --all-namespaces 2>&1 | sudo tee $INSPECT_DUMP/k8s/get-all > /dev/null
sudo -E /snap/bin/microk8s kubectl get pv 2>&1 | sudo tee $INSPECT_DUMP/k8s/get-pv > /dev/null # 2>&1 redirects stderr and stdout to /dev/null if no resources found
sudo -E /snap/bin/microk8s kubectl get pvc 2>&1 | sudo tee $INSPECT_DUMP/k8s/get-pvc > /dev/null # 2>&1 redirects stderr and stdout to /dev/null if no resources found
}

View File

@@ -60,7 +60,7 @@ def is_cluster_ready():
def is_cluster_locked():
clusterLockFile = os.path.expandvars("${SNAP_DATA}/var/lock/clustered.lock")
if os.path.isfile(clusterLockFile):
print("This MicroK8s deployment is acting as a node in a cluster. Please use the microk8s.status on the master.")
print("This MicroK8s deployment is acting as a node in a cluster. Please use the microk8s status on the master.")
exit(0)

View File

@@ -10,9 +10,9 @@ def print_console(addons):
def show_help():
print("Usage: microk8s.enable ADDON...")
print("Usage: microk8s enable ADDON...")
print("Enable one or more ADDON included with microk8s")
print("Example: microk8s.enable dns storage")
print("Example: microk8s enable dns storage")
available_addons = get_available_addons(get_current_arch())

View File

@@ -20,7 +20,7 @@ def print_short(isReady, enabled_addons, disabled_addons):
if isReady:
print("microk8s is running")
else:
print("microk8s is not running. Use microk8s.inspect for a deeper inspection.")
print("microk8s is not running. Use microk8s inspect for a deeper inspection.")
if isReady:
print("addons:")
@@ -37,7 +37,7 @@ def print_pretty(isReady, enabled_addons, disabled_addons):
if isReady:
print("microk8s is running")
else:
print("microk8s is not running. Use microk8s.inspect for a deeper inspection.")
print("microk8s is not running. Use microk8s inspect for a deeper inspection.")
if isReady:
print("addons:")
@@ -57,7 +57,7 @@ def print_short_yaml(isReady, enabled_addons, disabled_addons):
print("{:>2} {} {}".format("", "running:", isReady))
if not isReady:
print("{:>2} {} {}".format("","message:","microk8s is not running. Use microk8s.inspect for a deeper inspection."))
print("{:>2} {} {}".format("","message:","microk8s is not running. Use microk8s inspect for a deeper inspection."))
return
if isReady:
@@ -74,7 +74,7 @@ def print_yaml(isReady, enabled_addons, disabled_addons):
print("{:>2} {} {}".format("", "running:", isReady))
if not isReady:
print("{:>2} {} {}".format("","message:","microk8s is not running. Use microk8s.inspect for a deeper inspection."))
print("{:>2} {} {}".format("","message:","microk8s is not running. Use microk8s inspect for a deeper inspection."))
return
if isReady:
@@ -124,7 +124,7 @@ if __name__ == '__main__':
is_cluster_locked()
# initiate the parser with a description
parser = argparse.ArgumentParser(description='Microk8s cluster status check.', prog='microk8s.status')
parser = argparse.ArgumentParser(description='Microk8s cluster status check.', prog='microk8s status')
parser.add_argument("--format", help="print cluster and addon status, output can be in yaml, pretty or short",
default="short", choices={"pretty", "yaml", "short"})
parser.add_argument("-w", "--wait-ready", action='store_true', help="wait until the cluster is in ready state")

View File

@@ -70,7 +70,7 @@ fi
mkdir -p ${SNAP_DATA}/var/lock/
# This will allow us to refresh the snap to the more secure version.
# We need to make sure the client certificate used in microk8s.kubectl is available under $SNAP_DATA
# We need to make sure the client certificate used in microk8s kubectl is available under $SNAP_DATA
if [ ! -f ${SNAP_DATA}/credentials/client.config ]
then
echo "Patching client config location"

View File

@@ -16,6 +16,8 @@ confinement: classic
base: core
apps:
microk8s:
command: microk8s.wrapper
daemon-etcd:
command: run-etcd-with-args
daemon: simple
@@ -331,7 +333,8 @@ parts:
echo "Creating inspect hook"
cp $KUBE_SNAP_ROOT/scripts/inspect.sh .
# Add bash completion for microk8s.kubectl.
# Add bash completion for microk8s kubectl.
./kubectl completion bash | sed "s/complete -o default -F __start_kubectl kubectl/complete -o default -F __start_kubectl microk8s kubectl/g" | sed "s/complete -o default -o nospace -F __start_kubectl kubectl/complete -o default -o nospace -F __start_kubectl kubectl/g" > kubectl.bash
./kubectl completion bash | sed "s/complete -o default -F __start_kubectl kubectl/complete -o default -F __start_kubectl microk8s.kubectl/g" | sed "s/complete -o default -o nospace -F __start_kubectl kubectl/complete -o default -o nospace -F __start_kubectl kubectl/g" > kubectl.bash
if $REMOVE_KUBE_SNAP_BINS; then

View File

@@ -6,7 +6,7 @@ set -eux
n=0
until [ $n -ge 10 ]
do
(sudo /snap/bin/microk8s.kubectl get all --all-namespaces | grep -z "service/kubernetes") && break
(sudo /snap/bin/microk8s kubectl get all --all-namespaces | grep -z "service/kubernetes") && break
n=$[$n+1]
if [ $n -ge 10 ]; then
exit 1
@@ -17,7 +17,7 @@ done
n=0
until [ $n -ge 3 ]
do
(sudo /snap/bin/microk8s.kubectl get no | grep -z "Ready") && exit 0
(sudo /snap/bin/microk8s kubectl get no | grep -z "Ready") && exit 0
n=$[$n+1]
sleep 20
done

View File

@@ -75,7 +75,7 @@ class TestAddons(object):
microk8s_disable("storage:destroy-storage")
'''
We would disable DNS here but this freezes any terminating pods.
We let microk8s.reset to do the cleanup.
We let microk8s reset to do the cleanup.
print("Disabling DNS")
microk8s_disable("dns")
'''

View File

@@ -43,7 +43,7 @@ class TestCluster(object):
microk8s_disable("dashboard")
'''
We would disable DNS here but this freezes any terminating pods.
We let microk8s.reset to do the cleanup.
We let microk8s reset to do the cleanup.
print("Disabling DNS")
microk8s_disable("dns")
'''

View File

@@ -66,7 +66,7 @@ fi
lxc exec $NAME -- /var/tmp/tests/patch-kube-proxy.sh
# use 'script' for required tty: https://github.com/lxc/lxd/issues/1724#issuecomment-194416774
lxc exec $NAME -- script -e -c "pytest -s /var/tmp/tests/test-addons.py"
lxc exec $NAME -- microk8s.reset
lxc exec $NAME -- microk8s reset
lxc delete $NAME --force
# Test addons upgrade

View File

@@ -224,4 +224,3 @@ def update_yaml_with_arch(manifest_file):
with open(manifest_file, 'w') as f:
s = s.replace('$ARCH', arch)
f.write(s)