From 11fbff09f7c809f2df171720e173ca9bbfb2153f Mon Sep 17 00:00:00 2001 From: Tom Wieczorek Date: Wed, 3 Apr 2024 15:07:11 +0200 Subject: [PATCH] Let k0s-cloud provider assign a node's provider ID Since Kubernetes commit 53d38a31611, it is required for cloud providers to assign a provider ID to each node. Let k0s comply with that requirement. Signed-off-by: Tom Wieczorek --- inttest/k0scloudprovider/k0scloudprovider_test.go | 13 +++++++++---- pkg/k0scloudprovider/instances.go | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/inttest/k0scloudprovider/k0scloudprovider_test.go b/inttest/k0scloudprovider/k0scloudprovider_test.go index df90bf302c30..72af8cbc4c8e 100644 --- a/inttest/k0scloudprovider/k0scloudprovider_test.go +++ b/inttest/k0scloudprovider/k0scloudprovider_test.go @@ -48,12 +48,17 @@ func (s *K0sCloudProviderSuite) TestK0sGetsUp() { s.Require().NoError(err) s.Require().NoError(s.WaitJoinAPI(s.ControllerNode(0))) - err = s.WaitForNodeReady(s.WorkerNode(0), kc) + nodeName := s.WorkerNode(0) + err = s.WaitForNodeReady(nodeName, kc) s.Require().NoError(err) - s.testAddAddress(ctx, kc, s.WorkerNode(0), "1.2.3.4") - s.testAddAddress(ctx, kc, s.WorkerNode(0), "2041:0000:140F::875B:131B") - s.testAddAddress(ctx, kc, s.WorkerNode(0), "GIGO") + node, err := kc.CoreV1().Nodes().Get(ctx, nodeName, metav1.GetOptions{}) + s.Require().NoError(err) + s.Equal("k0s-cloud-provider://"+nodeName, node.Spec.ProviderID) + + s.testAddAddress(ctx, kc, nodeName, "1.2.3.4") + s.testAddAddress(ctx, kc, nodeName, "2041:0000:140F::875B:131B") + s.testAddAddress(ctx, kc, nodeName, "GIGO") } // testAddAddress adds the provided address to a node and ensures that the diff --git a/pkg/k0scloudprovider/instances.go b/pkg/k0scloudprovider/instances.go index 82fe8afaa708..6fba36192d6e 100644 --- a/pkg/k0scloudprovider/instances.go +++ b/pkg/k0scloudprovider/instances.go @@ -56,7 +56,7 @@ func (i *instancesV2) InstanceShutdown(ctx context.Context, node *v1.Node) (bool // properties of the node like its name, labels and annotations. func (i *instancesV2) InstanceMetadata(ctx context.Context, node *v1.Node) (*cloudprovider.InstanceMetadata, error) { return &cloudprovider.InstanceMetadata{ - ProviderID: node.Spec.ProviderID, + ProviderID: Name + "://" + node.Name, InstanceType: Name, NodeAddresses: i.addressCollector(node), }, nil