Skip to content

Commit

Permalink
k8s: Make it work even if kubectl is not installed on the machine
Browse files Browse the repository at this point in the history
There's code in the k8s provider that takes care of pulling the
kubectl binary from the cluster and use that one for subsequent
operations; however, right before that happens, a few settings
are changed in kubeconfig, which means that it's necessary for
the host system to provide its own kubectl binary.

Invert the order of these operations, and make sure that we
always invoke the binary obtained from the cluster. This way, it
is possible to successfully bring up a cluster on a machine that
doesn't have kubectl installed.

Signed-off-by: Andrea Bolognani <[email protected]>
  • Loading branch information
andreabolognani committed Oct 11, 2024
1 parent ec02f99 commit 80c6f8e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions cluster-up/cluster/k8s-provider-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ function up() {

${_cli} scp --prefix $provider_prefix /etc/kubernetes/admin.conf - >${KUBEVIRTCI_CONFIG_PATH}/$KUBEVIRT_PROVIDER/.kubeconfig

# Set server and disable tls check
export KUBECONFIG=${KUBEVIRTCI_CONFIG_PATH}/$KUBEVIRT_PROVIDER/.kubeconfig
kubectl config set-cluster kubernetes --server="https://$(_main_ip):$(_port k8s)"
kubectl config set-cluster kubernetes --insecure-skip-tls-verify=true

# Workaround https://github.com/containers/conmon/issues/315 by not dumping the file to stdout for the time being
if [[ ${_cri_bin} = podman* ]]; then
k8s_version=$(kubectl get node node01 --no-headers -o=custom-columns=VERSION:.status.nodeInfo.kubeletVersion)
Expand All @@ -81,6 +76,11 @@ function up() {

chmod u+x ${KUBEVIRTCI_CONFIG_PATH}/$KUBEVIRT_PROVIDER/.kubectl

# Set server and disable tls check
export KUBECONFIG=${KUBEVIRTCI_CONFIG_PATH}/$KUBEVIRT_PROVIDER/.kubeconfig
${KUBEVIRTCI_CONFIG_PATH}/$KUBEVIRT_PROVIDER/.kubectl config set-cluster kubernetes --server="https://$(_main_ip):$(_port k8s)"
${KUBEVIRTCI_CONFIG_PATH}/$KUBEVIRT_PROVIDER/.kubectl config set-cluster kubernetes --insecure-skip-tls-verify=true

# Make sure that local config is correct
prepare_config
ssh="${_cli} --prefix $provider_prefix ssh"
Expand Down

0 comments on commit 80c6f8e

Please sign in to comment.