diff --git a/.reuse/dep5 b/.reuse/dep5 index 4c14e41..02af697 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -9,7 +9,7 @@ Source: https://github.com/ironcore-dev/cloud-provider-metal Files: .github/* .gitignore - .golangci.yml + .golangci.yaml .dockerignore CODE_OF_CONDUCT.md CODEOWNERS diff --git a/pkg/cloudprovider/metal/instances_v2.go b/pkg/cloudprovider/metal/instances_v2.go index 68db4b9..9cfaa5c 100644 --- a/pkg/cloudprovider/metal/instances_v2.go +++ b/pkg/cloudprovider/metal/instances_v2.go @@ -8,8 +8,6 @@ import ( "fmt" "strings" - "k8s.io/apimachinery/pkg/types" - metalv1alpha1 "github.com/ironcore-dev/metal-operator/api/v1alpha1" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -122,7 +120,7 @@ func (o *metalInstancesV2) InstanceMetadata(ctx context.Context, node *corev1.No providerID := node.Spec.ProviderID if providerID == "" { - providerID = getProviderIDForServerClaim(serverClaim) + providerID = fmt.Sprintf("%s://%s/%s", ProviderName, o.metalNamespace, serverClaim.Name) } // TODO: use constants here @@ -150,10 +148,6 @@ func (o *metalInstancesV2) InstanceMetadata(ctx context.Context, node *corev1.No }, nil } -func getProviderIDForServerClaim(serverClaim *metalv1alpha1.ServerClaim) string { - return fmt.Sprintf("%s://%s/%s/%s", ProviderName, serverClaim.Namespace, serverClaim.Name, serverClaim.UID) -} - func (o *metalInstancesV2) getServerClaimForNode(ctx context.Context, node *corev1.Node) (*metalv1alpha1.ServerClaim, error) { var serverClaim *metalv1alpha1.ServerClaim if node.Spec.ProviderID != "" { @@ -180,7 +174,7 @@ func (o *metalInstancesV2) getServerClaimForNode(ctx context.Context, node *core } func (o *metalInstancesV2) getServerClaimFromProviderID(ctx context.Context, providerID string) (*metalv1alpha1.ServerClaim, error) { - objKey, objUID, err := getObjectKeyFromProviderID(providerID) + objKey, err := getObjectKeyFromProviderID(providerID) if err != nil { return nil, fmt.Errorf("failed to get object key for ProviderID %s: %w", providerID, err) } @@ -191,22 +185,16 @@ func (o *metalInstancesV2) getServerClaimFromProviderID(ctx context.Context, pro } return nil, fmt.Errorf("failed to get server claim object for ProviderID %s: %w", providerID, err) } - - // Check for UID equality. For backwards compatibility we only compare if the UID is part of the ProviderID. - if len(objUID) > 0 && serverClaim.UID != objUID { - return nil, cloudprovider.InstanceNotFound - } - return serverClaim, nil } -func getObjectKeyFromProviderID(providerID string) (client.ObjectKey, types.UID, error) { +func getObjectKeyFromProviderID(providerID string) (client.ObjectKey, error) { parts := strings.Split(strings.TrimPrefix(providerID, fmt.Sprintf("%s://", ProviderName)), "/") - if len(parts) != 3 { - return client.ObjectKey{}, "", fmt.Errorf("invalid format of ProviderID %s", providerID) + if len(parts) != 2 { + return client.ObjectKey{}, fmt.Errorf("invalid format of ProviderID %s", providerID) } return client.ObjectKey{ Namespace: parts[0], Name: parts[1], - }, types.UID(parts[2]), nil + }, nil } diff --git a/pkg/cloudprovider/metal/instances_v2_test.go b/pkg/cloudprovider/metal/instances_v2_test.go index 115edb3..7a350a7 100644 --- a/pkg/cloudprovider/metal/instances_v2_test.go +++ b/pkg/cloudprovider/metal/instances_v2_test.go @@ -98,7 +98,7 @@ var _ = Describe("InstancesV2", func() { instanceMetadata, err := instancesProvider.InstanceMetadata(ctx, node) Expect(err).NotTo(HaveOccurred()) Eventually(instanceMetadata).Should(SatisfyAll( - HaveField("ProviderID", getProviderIDForServerClaim(serverClaim)), + HaveField("ProviderID", getProviderID(serverClaim.Namespace, serverClaim.Name)), HaveField("InstanceType", "foo"), HaveField("NodeAddresses", ContainElements( corev1.NodeAddress{ @@ -163,7 +163,7 @@ var _ = Describe("InstancesV2", func() { GenerateName: "test-", }, Spec: corev1.NodeSpec{ - ProviderID: getProviderIDForServerClaim(serverClaim), + ProviderID: getProviderID(serverClaim.Namespace, serverClaim.Name), }, } Expect(k8sClient.Create(ctx, node)).To(Succeed()) @@ -183,7 +183,7 @@ var _ = Describe("InstancesV2", func() { instanceMetadata, err := instancesProvider.InstanceMetadata(ctx, node) Expect(err).NotTo(HaveOccurred()) Eventually(instanceMetadata).Should(SatisfyAll( - HaveField("ProviderID", getProviderIDForServerClaim(serverClaim)), + HaveField("ProviderID", getProviderID(serverClaim.Namespace, serverClaim.Name)), HaveField("InstanceType", "foo"), HaveField("NodeAddresses", ContainElements( corev1.NodeAddress{ @@ -207,7 +207,7 @@ var _ = Describe("InstancesV2", func() { Name: "foo", }, Spec: corev1.NodeSpec{ - ProviderID: fmt.Sprintf("%s://%s/foo/bar", ProviderName, ns.Name), + ProviderID: getProviderID(ns.Name, "bar"), }, } Expect(k8sClient.Create(ctx, node)).To(Succeed()) @@ -251,3 +251,7 @@ var _ = Describe("InstancesV2", func() { Expect(ok).To(BeFalse()) }) }) + +func getProviderID(namespace, serverClaimName string) string { + return fmt.Sprintf("%s://%s/%s", ProviderName, namespace, serverClaimName) +}