rancher-sandbox / cluster-api-provider-rke2

RKE2 bootstrap and control-plane Cluster API providers.
Apache License 2.0
78 stars 24 forks source link

kubectl invoked from incorrect location during bootstrap #349

Open anmazzotti opened 3 weeks ago

anmazzotti commented 3 weeks ago

What happened:

One command in the cloud-init bootstrap is as follows:

kubectl create secret tls cluster-etcd -o yaml --dry-run=client -n kube-system --cert=/var/lib/rancher/rke2/server/tls/etcd/server-ca.crt --key=/var/lib/rancher/rke2/server/tls/etcd/server-ca.key --kubeconfig /etc/rancher/rke2/rke2.yaml | kubectl apply -f- --kubeconfig /etc/rancher/rke2/rke2.yaml

The problem with this in the first place is that it relies on kubectl, making it a dependency in order to bootstrap. I wonder if there is a better way to add this secret.

The other problem is that kubectl is not in PATH. This is not supported by RKE2 and it's going to fail on any RKE2 installation. As the documentation suggests, /var/lib/rancher/rke2/bin/kubectl should be used.

However it's unclear to me if these CLI tools are going to stay or are just there for debugging/testing purposes. Using /var/lib/rancher/rke2/bin/ may stop working unexpectedly because of that.

Also be aware that this bug is currently silently failing due to #221

What did you expect to happen:

How to reproduce it:

Anything else you would like to add: [Miscellaneous information that will assist in solving the issue.]

Environment:

anmazzotti commented 2 weeks ago

Relevant to this issue, is that the /var/lib/rancher/rke2 may not be hardcoded, because it can be set by the user.

I don't know if the data-dir can already be configured on the RKE2 provider, but it may be in the future. Relevant issue: https://github.com/rancher/rancher/pull/45326