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: set host-uuid correctly on non LKE clusters #167

Merged
merged 2 commits into from
Jan 16, 2024
Merged
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
6 changes: 5 additions & 1 deletion cloud/linode/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ func (e invalidProviderIDError) Error() string {
return fmt.Sprintf("invalid provider ID %q", e.value)
}

func isLinodeProviderID(providerID string) bool {
return strings.HasPrefix(providerID, providerIDPrefix)
}

func parseProviderID(providerID string) (int, error) {
if !strings.HasPrefix(providerID, providerIDPrefix) {
if !isLinodeProviderID(providerID) {
return 0, invalidProviderIDError{providerID}
}
id, err := strconv.Atoi(strings.TrimPrefix(providerID, providerIDPrefix))
Expand Down
2 changes: 1 addition & 1 deletion cloud/linode/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (i *instances) lookupLinode(ctx context.Context, node *v1.Node) (*linodego.
sentry.SetTag(ctx, "provider_id", providerID)
sentry.SetTag(ctx, "node_name", node.Name)

if providerID != "" {
if providerID != "" && isLinodeProviderID(providerID){
id, err := parseProviderID(providerID)
if err != nil {
sentry.CaptureError(ctx, err)
Expand Down
11 changes: 0 additions & 11 deletions cloud/linode/instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,6 @@ func TestMalformedProviders(t *testing.T) {

client := NewMockClient(ctrl)

t.Run("fails on malformed providerID", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove? can't fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no "malformed provider ID" anymore, its either a linode-id or a label that we can look up - since we mock the linodeGo response, I didn't feel like it was a useful test to see if a string existed in a list (that we mock)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not what the test does, it doesn't test anything in the linodego response - it checks that we error out in case there's an incorrect spec value on the Node object. The new codebase just ignores this issue entirely and I don't find that to be correct behaviour.

instances := newInstances(client)
providerID := "bogus://bogus"
node := nodeWithProviderID(providerID)
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{}, nil)

meta, err := instances.InstanceMetadata(ctx, node)
assert.ErrorIs(t, err, invalidProviderIDError{providerID})
assert.Nil(t, meta)
})

t.Run("fails on non-numeric providerID", func(t *testing.T) {
instances := newInstances(client)
providerID := providerIDPrefix + "abc"
Expand Down
Loading