Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use right implementation for instanceID #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scaleway/baremetal.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (b *baremetal) InstanceID(ctx context.Context, nodeName types.NodeName) (st
if err != nil {
return "", err
}
return BuildProviderID(InstanceTypeBaremtal, string(baremetalServer.Zone), baremetalServer.ID), nil
return BuildInstanceID(InstanceTypeBaremtal, string(baremetalServer.Zone), baremetalServer.ID), nil
}

// InstanceType returns the type of the specified instance.
Expand Down
2 changes: 1 addition & 1 deletion scaleway/baremetal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func TestBaremetal_InstanceID(t *testing.T) {
t.Run("Found", func(t *testing.T) {
result, err := baremetal.InstanceID(context.TODO(), "bm-keen-feistel")
AssertNoError(t, err)
Equals(t, "scaleway://baremetal/fr-par-2/53a6ca14-0d8d-4f2e-9887-2f1bcfba58ed", result)
Equals(t, "baremetal/fr-par-2/53a6ca14-0d8d-4f2e-9887-2f1bcfba58ed", result)
})

t.Run("NotFound", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion scaleway/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (i *instances) InstanceID(ctx context.Context, name types.NodeName) (string
if err != nil {
return "", err
}
return BuildProviderID(InstanceTypeInstance, string(instanceServer.Zone), instanceServer.ID), nil
return BuildInstanceID(InstanceTypeInstance, string(instanceServer.Zone), instanceServer.ID), nil
}

// InstanceType returns the type of the specified instance (ex. DEV1-M, GP1-XS,...).
Expand Down
2 changes: 1 addition & 1 deletion scaleway/instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func TestInstances_InstanceID(t *testing.T) {
t.Run("Found", func(t *testing.T) {
result, err := instance.InstanceID(context.TODO(), "scw-nervous-mccarthy")
AssertNoError(t, err)
Equals(t, "scaleway://instance/fr-par-1/232bf860-9ffe-4b08-97da-158c0316ed15", result)
Equals(t, "instance/fr-par-1/232bf860-9ffe-4b08-97da-158c0316ed15", result)
})

t.Run("NotFound", func(t *testing.T) {
Expand Down
7 changes: 6 additions & 1 deletion scaleway/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,14 @@ func ServerInfoFromProviderID(providerID string) (string, string, string, error)
return result[regexpProduct], result[regexpLocalization], result[regexpUUID], nil
}

// BuildInstanceID build the instanceID from given informations
func BuildInstanceID(product, localization, id string) string {
return fmt.Sprintf("%s/%s/%s", product, localization, id)
}

// BuildProviderID build the providerID from given informations
func BuildProviderID(product, localization, id string) string {
return fmt.Sprintf("%s://%s/%s/%s", providerName, product, localization, id)
return fmt.Sprintf("%s://%s", providerName, BuildInstanceID(product, localization, id))
}

// getImplementationByProviderID returns the corresponding cloudprovider.Instances implementation
Expand Down