Skip to content

Commit 23a8e2c

Browse files
committed
removed v1 impl (apart from zones) and fixed tests
1 parent a76f71e commit 23a8e2c

2 files changed

Lines changed: 70 additions & 237 deletions

File tree

cloud/linode/instances.go

Lines changed: 24 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,7 @@ type instances struct {
1717
client Client
1818
}
1919

20-
// TODO(PR): providing both APIs to keep the tests green and to enable
21-
// gradual migration
22-
type hybridInstances interface {
23-
cloudprovider.Instances
24-
cloudprovider.InstancesV2
25-
}
26-
27-
func newInstances(client Client) hybridInstances {
20+
func newInstances(client Client) cloudprovider.InstancesV2 {
2821
return &instances{client}
2922
}
3023

@@ -36,50 +29,6 @@ func (e instanceNoIPAddressesError) Error() string {
3629
return fmt.Sprintf("instance %d has no IP addresses", e.id)
3730
}
3831

39-
func (i *instances) NodeAddresses(ctx context.Context, name types.NodeName) ([]v1.NodeAddress, error) {
40-
ctx = sentry.SetHubOnContext(ctx)
41-
sentry.SetTag(ctx, "node_name", string(name))
42-
43-
linode, err := linodeByName(ctx, i.client, name)
44-
if err != nil {
45-
sentry.CaptureError(ctx, err)
46-
return nil, err
47-
}
48-
49-
addresses, err := i.nodeAddresses(ctx, linode)
50-
if err != nil {
51-
sentry.CaptureError(ctx, err)
52-
return nil, err
53-
}
54-
55-
return addresses, nil
56-
}
57-
58-
func (i *instances) NodeAddressesByProviderID(ctx context.Context, providerID string) ([]v1.NodeAddress, error) {
59-
ctx = sentry.SetHubOnContext(ctx)
60-
sentry.SetTag(ctx, "provider_id", providerID)
61-
62-
id, err := parseProviderID(providerID)
63-
if err != nil {
64-
sentry.CaptureError(ctx, err)
65-
return nil, err
66-
}
67-
68-
linode, err := linodeByID(ctx, i.client, id)
69-
if err != nil {
70-
sentry.CaptureError(ctx, err)
71-
return nil, err
72-
}
73-
74-
addresses, err := i.nodeAddresses(ctx, linode)
75-
if err != nil {
76-
sentry.CaptureError(ctx, err)
77-
return nil, err
78-
}
79-
80-
return addresses, nil
81-
}
82-
8332
func (i *instances) nodeAddresses(ctx context.Context, linode *linodego.Instance) ([]v1.NodeAddress, error) {
8433
var addresses []v1.NodeAddress
8534
addresses = append(addresses, v1.NodeAddress{Type: v1.NodeHostName, Address: linode.Label})
@@ -106,110 +55,6 @@ func (i *instances) nodeAddresses(ctx context.Context, linode *linodego.Instance
10655
return addresses, nil
10756
}
10857

109-
func (i *instances) InstanceID(ctx context.Context, nodeName types.NodeName) (string, error) {
110-
ctx = sentry.SetHubOnContext(ctx)
111-
sentry.SetTag(ctx, "node_name", string(nodeName))
112-
113-
linode, err := linodeByName(ctx, i.client, nodeName)
114-
if err != nil {
115-
sentry.CaptureError(ctx, err)
116-
return "", err
117-
}
118-
return strconv.Itoa(linode.ID), nil
119-
}
120-
121-
func (i *instances) InstanceType(ctx context.Context, nodeName types.NodeName) (string, error) {
122-
ctx = sentry.SetHubOnContext(ctx)
123-
sentry.SetTag(ctx, "node_name", string(nodeName))
124-
125-
linode, err := linodeByName(ctx, i.client, nodeName)
126-
if err != nil {
127-
sentry.CaptureError(ctx, err)
128-
return "", err
129-
}
130-
return linode.Type, nil
131-
}
132-
133-
func (i *instances) InstanceTypeByProviderID(ctx context.Context, providerID string) (string, error) {
134-
ctx = sentry.SetHubOnContext(ctx)
135-
sentry.SetTag(ctx, "provider_id", providerID)
136-
137-
id, err := parseProviderID(providerID)
138-
if err != nil {
139-
sentry.CaptureError(ctx, err)
140-
return "", err
141-
}
142-
143-
sentry.SetTag(ctx, "linode_id", strconv.Itoa(id))
144-
145-
linode, err := linodeByID(ctx, i.client, id)
146-
if err != nil {
147-
sentry.CaptureError(ctx, err)
148-
return "", err
149-
}
150-
return linode.Type, nil
151-
}
152-
153-
func (i *instances) AddSSHKeyToAllInstances(_ context.Context, user string, keyData []byte) error {
154-
return cloudprovider.NotImplemented
155-
}
156-
157-
func (i *instances) CurrentNodeName(_ context.Context, hostname string) (types.NodeName, error) {
158-
return types.NodeName(hostname), nil
159-
}
160-
161-
func (i *instances) InstanceExistsByProviderID(ctx context.Context, providerID string) (bool, error) {
162-
ctx = sentry.SetHubOnContext(ctx)
163-
sentry.SetTag(ctx, "provider_id", providerID)
164-
165-
id, err := parseProviderID(providerID)
166-
if err != nil {
167-
sentry.CaptureError(ctx, err)
168-
return false, err
169-
}
170-
171-
sentry.SetTag(ctx, "linode_id", strconv.Itoa(id))
172-
173-
_, err = linodeByID(ctx, i.client, id)
174-
if err != nil {
175-
if apiError, ok := err.(*linodego.Error); ok && apiError.Code == http.StatusNotFound {
176-
return false, nil
177-
}
178-
sentry.CaptureError(ctx, err)
179-
return false, err
180-
}
181-
182-
return true, nil
183-
}
184-
185-
func (i *instances) InstanceShutdownByProviderID(ctx context.Context, providerID string) (bool, error) {
186-
ctx = sentry.SetHubOnContext(ctx)
187-
sentry.SetTag(ctx, "provider_id", providerID)
188-
189-
id, err := parseProviderID(providerID)
190-
if err != nil {
191-
sentry.CaptureError(ctx, err)
192-
return false, err
193-
}
194-
195-
sentry.SetTag(ctx, "linode_id", strconv.Itoa(id))
196-
197-
instance, err := linodeByID(ctx, i.client, id)
198-
if err != nil {
199-
sentry.CaptureError(ctx, err)
200-
return false, err
201-
}
202-
203-
// An instance is considered to be "shutdown" when it is
204-
// in the process of shutting down, or already offline.
205-
if instance.Status == linodego.InstanceOffline ||
206-
instance.Status == linodego.InstanceShuttingDown {
207-
return true, nil
208-
}
209-
210-
return false, nil
211-
}
212-
21358
func (i *instances) InstanceExists(ctx context.Context, node *v1.Node) (bool, error) {
21459
providerID := node.Spec.ProviderID
21560

@@ -267,18 +112,29 @@ func (i *instances) InstanceShutdown(ctx context.Context, node *v1.Node) (bool,
267112
}
268113

269114
func (i *instances) InstanceMetadata(ctx context.Context, node *v1.Node) (*cloudprovider.InstanceMetadata, error) {
270-
providerID := node.Spec.ProviderID
271-
272-
// TODO(okokes): should we at all times rely on providerID or should we include
273-
// lookups by node name as well?
274-
id, err := parseProviderID(providerID)
275-
if err != nil {
276-
return nil, err
277-
}
115+
var (
116+
providerID = node.Spec.ProviderID
117+
nodeName = types.NodeName(node.Name)
118+
linode *linodego.Instance
119+
err error
120+
)
121+
122+
// TODO(okokes): abstract this away and reuse it in our other methods here
123+
if providerID != "" {
124+
id, err := parseProviderID(providerID)
125+
if err != nil {
126+
return nil, err
127+
}
278128

279-
linode, err := linodeByID(ctx, i.client, id)
280-
if err != nil {
281-
return nil, err
129+
linode, err = linodeByID(ctx, i.client, id)
130+
if err != nil {
131+
return nil, err
132+
}
133+
} else {
134+
linode, err = linodeByName(ctx, i.client, nodeName)
135+
if err != nil {
136+
return nil, err
137+
}
282138
}
283139

284140
addresses, err := i.nodeAddresses(ctx, linode)
@@ -290,6 +146,7 @@ func (i *instances) InstanceMetadata(ctx context.Context, node *v1.Node) (*cloud
290146
meta := &cloudprovider.InstanceMetadata{
291147
ProviderID: providerID,
292148
NodeAddresses: addresses,
149+
InstanceType: linode.Type,
293150
Region: linode.Region,
294151
}
295152

0 commit comments

Comments
 (0)