This message was deleted.
# general
a
This message was deleted.
s
I'm not sure how this works in terms of 'supported' workflows but yes, rke2 creation is all done in v1 api. So if you're writing some internal scripts, that's what you'll need to use.
👍 1
g
Ok thank you. I’ll use v1 just like the Rancher UI does for RKE2.
👍 1
s
Unfortunately there are some things that are still in the v3 api that we use or reference in the UI that won't be completely moved to v1. the cluster name starting with
c-
is the v3 cluster name. You can view these objects in your local cluster by going to local -> more resources -> rancher -> mgmt clusters where the ID will match the name you see in the v3 call. These APIs aren't designed for users to directly use, hence the lack of documentation and support around v1 api. more on 'why is status.ClusterName' not there in the response when you set the clusterName on your v1 object Status is its own object of the cluster. meaning that when you update the name of the cluster, status doesn't get that update until after the create/update command is sent. So after you create your v1 cluster, you should then get it from rancher once its created. But you can run into race conditions, because rancher is actually updating those resources like its status behind the scenes after you 'create' the cluster, then rancher will update the schema of the cluster, if that makes sense. tldr: so to put that together, you'd have to create the v1 cluster, then poll the new object in rancher until Status.ClusterName is populated. If you're wanting the kubeConfig, you should also poll until the status of the cluster is active so that you'll have a valid kubeConfig when downloaded. Use status.clusterName as the ID in
v1/management.cattle.io.clusters/c-m-numbers?action=generateKubeconfig
and you should be able to download it.
g
@square-orange-60123 Thanks for the reply. I was able to get it working by polling
GET /v1/provisioning.cattle.io.clusters/{clusterId}
until
metadata.state.transitioning
was not
true
and then I check
metadata.state.name
to make sure it's
active
. Once it's active I grab
status.clusterName
like you said and at that point it is set so I'll go with that. A couple followup questions for you: 1. I assumed the v3 API was newer than the v1 API but since RKE1 cluster creation uses v3 and RKE2 cluster creation uses v1, does that mean v1 is newer despite the name? 2. To confirm, there is no way to control the value of
status.clusterName
and that will always be generated? 3.
status.clusterName
is the only key that can be used to download the kubeconfig, correct?
s
1. v1 is newer despite the name 2. correct, the name is generated 3. to my knowledge, that is also correct
👍 1
g
And one more: 4. To confirm, there are no APIs that are intended to be used outside of the Rancher UI for creating clusters?
s
4. to my knowledge, correct. The docs link you sent earlier is the only reference to the API I've seen in documentation, because its not 'officially' supported to do it this way. But people use it all the time, its just that if you get yourself into a hole using the api directly and have a support contract, my understanding is that they can't really help.
g
Ok, good to know. I'm surprised there is not an officially supported API since automating cluster creation is very important to some but I'm glad it can still be automated regardless.
s
a good option for supported automation would be something like our terraform provider. But we're working on our own public API that would support cluster creation in the future; but it isn't quite ready yet
g
One last one for you... in our script that creates a RKE1 cluster we polled the cluster until it was active but then we still found that some
kubectl
commands using the downloaded kubeconfig file wouldn't work and we found that it was a timing issues where even though the cluster was active the nodes were not ready so we also added in polling of
GET /v3/clusters/{clusterId}/nodes
and waited until all nodes had an active state which worked well for RKE1 and the v3 API but I don't know what the equivalent would be for the v1 API...
Ok that's great news. Looking forward to hearing more about the public API.
s
using the
view in api
option in the UI is great for finding the new resource in v1 coming from v3. for nodes, its
v1/cluster.x-k8s.io.machines/fleet-default/your_node_name
g
Ok I see
/v1/cluster.x-k8s.io.machines/fleet-default/{machinePoolName}
so is that would I would need to check or would I need to drill down to individual nodes/machines within the machine pool in case the size of the pool is greater than 1?
s
the last / is actually the node name that is generated from the pool name. so there shouldn't be any drill-down. in rke2/k3s, yes nodes are referred to as
machines
at this level.
so the key is something like
<pool_name>-<generated_name>
g
I tried
/v1/cluster.x-k8s.io.machines/fleet-default/{nodeName}
to view an individual node and it wasn't found. I can view the machine pool at
/v1/cluster.x-k8s.io.machines/fleet-default/{machinePoolName}
.... I think I just found it by drilling down in the Rancher UI. Looks like it's
/k8s/clusters/{status.clusterName}/v1/nodes/{nodeName}
?
Do you think it's sufficient to just check the state of the machine pool rather than having to check the state of all nodes in all machine pools in the cluster?
s
what does your nodeName look like
g
test-cluster-control-1b46842a-l5pbb
s
actually, I think either should work. As long as you have a valid status for the node
g
And the machine pool name is
test-cluster-control-777f8b57c6xs9gsh-s849g
Ok I'm going with
/k8s/clusters/{status.clusterName}/v1/nodes
and checking
metadata.state.name
of each
node
in the
data
array to make sure it's
active
. Thanks!
👍 1
s
no problem
g
Is
/k8s
a third API?
s
I believe it is directly kubernetes API
👍 1
g
Do you know if there any timeline estimates for the new public API that is being worked on and if there is any web page that shows the status? Or even an estimated Rancher version that it’s expected to be released with?
s
Unfortunately we don't have a dependable timeline for cluster support in public api.
g
Ok and what about the public API in general (without cluster support)?
s
Some things are already supported, but I'm not part of the team that worked on it so I have limited info. But I'm pretty sure we don't have much / any public docs on it because it is still alpha for most feature areas.
g
Ok. So does that mean parts of the public API are already part of a rancher release?
s
yes, but sorry I don't have much info on it at this time.
g
No problem. Thanks for all your help.
@square-orange-60123 When I send a POST to
/v1/rke-machine-config.cattle.io.tritonconfigs/fleet-default
to create a RKE2 cluster from my script it seems that changing
metadata.generateName
does not have any impact. For example, when I viewed the request that Rancher UI sent it included the cluster name so I removed that from
metadata.generateName
but the node names still end up prefixed by the cluster name. Any ideas?
I meant when I create a machine pool via API, not the RKE2 cluster that uses the machines pools
s
I don't recall there being a way to bypass the generated name
g
Ok bummer