Skip to content

Commit 110cb78

Browse files
authored
Merge pull request #8197 from hetznercloud/deps-update-hcloud-go
deps(hetzner): update vendored hcloud-go to v2.21.1
2 parents 347db2d + 2a9103e commit 110cb78

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2974
-2708
lines changed

cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/action.go

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/url"
77
"time"
88

9+
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/exp/ctxutil"
910
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema"
1011
)
1112

@@ -54,9 +55,21 @@ const (
5455
type ActionError struct {
5556
Code string
5657
Message string
58+
59+
action *Action
60+
}
61+
62+
// Action returns the [Action] that triggered the error if available.
63+
func (e ActionError) Action() *Action {
64+
return e.action
5765
}
5866

5967
func (e ActionError) Error() string {
68+
action := e.Action()
69+
if action != nil {
70+
// For easier debugging, the error string contains the Action ID.
71+
return fmt.Sprintf("%s (%s, %d)", e.Message, e.Code, action.ID)
72+
}
6073
return fmt.Sprintf("%s (%s)", e.Message, e.Code)
6174
}
6275

@@ -65,6 +78,7 @@ func (a *Action) Error() error {
6578
return ActionError{
6679
Code: a.ErrorCode,
6780
Message: a.ErrorMessage,
81+
action: a,
6882
}
6983
}
7084
return nil
@@ -111,11 +125,15 @@ func (c *ActionClient) List(ctx context.Context, opts ActionListOpts) ([]*Action
111125
}
112126

113127
// All returns all actions.
128+
//
129+
// Deprecated: It is required to pass in a list of IDs since 30 January 2025. Please use [ActionClient.AllWithOpts] instead.
114130
func (c *ActionClient) All(ctx context.Context) ([]*Action, error) {
115131
return c.action.All(ctx, ActionListOpts{ListOpts: ListOpts{PerPage: 50}})
116132
}
117133

118134
// AllWithOpts returns all actions for the given options.
135+
//
136+
// It is required to set [ActionListOpts.ID]. Any other fields set in the opts are ignored.
119137
func (c *ActionClient) AllWithOpts(ctx context.Context, opts ActionListOpts) ([]*Action, error) {
120138
return c.action.All(ctx, opts)
121139
}
@@ -136,65 +154,43 @@ func (c *ResourceActionClient) getBaseURL() string {
136154

137155
// GetByID retrieves an action by its ID. If the action does not exist, nil is returned.
138156
func (c *ResourceActionClient) GetByID(ctx context.Context, id int64) (*Action, *Response, error) {
139-
req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("%s/actions/%d", c.getBaseURL(), id), nil)
140-
if err != nil {
141-
return nil, nil, err
142-
}
157+
opPath := c.getBaseURL() + "/actions/%d"
158+
ctx = ctxutil.SetOpPath(ctx, opPath)
143159

144-
var body schema.ActionGetResponse
145-
resp, err := c.client.Do(req, &body)
160+
reqPath := fmt.Sprintf(opPath, id)
161+
162+
respBody, resp, err := getRequest[schema.ActionGetResponse](ctx, c.client, reqPath)
146163
if err != nil {
147164
if IsError(err, ErrorCodeNotFound) {
148165
return nil, resp, nil
149166
}
150-
return nil, nil, err
167+
return nil, resp, err
151168
}
152-
return ActionFromSchema(body.Action), resp, nil
169+
return ActionFromSchema(respBody.Action), resp, nil
153170
}
154171

155172
// List returns a list of actions for a specific page.
156173
//
157174
// Please note that filters specified in opts are not taken into account
158175
// when their value corresponds to their zero value or when they are empty.
159176
func (c *ResourceActionClient) List(ctx context.Context, opts ActionListOpts) ([]*Action, *Response, error) {
160-
req, err := c.client.NewRequest(
161-
ctx,
162-
"GET",
163-
fmt.Sprintf("%s/actions?%s", c.getBaseURL(), opts.values().Encode()),
164-
nil,
165-
)
166-
if err != nil {
167-
return nil, nil, err
168-
}
177+
opPath := c.getBaseURL() + "/actions?%s"
178+
ctx = ctxutil.SetOpPath(ctx, opPath)
179+
180+
reqPath := fmt.Sprintf(opPath, opts.values().Encode())
169181

170-
var body schema.ActionListResponse
171-
resp, err := c.client.Do(req, &body)
182+
respBody, resp, err := getRequest[schema.ActionListResponse](ctx, c.client, reqPath)
172183
if err != nil {
173-
return nil, nil, err
174-
}
175-
actions := make([]*Action, 0, len(body.Actions))
176-
for _, i := range body.Actions {
177-
actions = append(actions, ActionFromSchema(i))
184+
return nil, resp, err
178185
}
179-
return actions, resp, nil
186+
187+
return allFromSchemaFunc(respBody.Actions, ActionFromSchema), resp, nil
180188
}
181189

182190
// All returns all actions for the given options.
183191
func (c *ResourceActionClient) All(ctx context.Context, opts ActionListOpts) ([]*Action, error) {
184-
allActions := []*Action{}
185-
186-
err := c.client.all(func(page int) (*Response, error) {
192+
return iterPages(func(page int) ([]*Action, *Response, error) {
187193
opts.Page = page
188-
actions, resp, err := c.List(ctx, opts)
189-
if err != nil {
190-
return resp, err
191-
}
192-
allActions = append(allActions, actions...)
193-
return resp, nil
194+
return c.List(ctx, opts)
194195
})
195-
if err != nil {
196-
return nil, err
197-
}
198-
199-
return allActions, nil
200196
}

cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/action_waiter.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ type ActionWaiter interface {
1616
var _ ActionWaiter = (*ActionClient)(nil)
1717

1818
// WaitForFunc waits until all actions are completed by polling the API at the interval
19-
// defined by [WithPollBackoffFunc]. An action is considered as complete when its status is
19+
// defined by [WithPollOpts]. An action is considered as complete when its status is
2020
// either [ActionStatusSuccess] or [ActionStatusError].
2121
//
2222
// The handleUpdate callback is called every time an action is updated.
2323
func (c *ActionClient) WaitForFunc(ctx context.Context, handleUpdate func(update *Action) error, actions ...*Action) error {
24+
// Filter out nil actions
25+
actions = slices.DeleteFunc(actions, func(a *Action) bool { return a == nil })
26+
2427
running := make(map[int64]struct{}, len(actions))
2528
for _, action := range actions {
2629
if action.Status == ActionStatusRunning {
@@ -48,18 +51,19 @@ func (c *ActionClient) WaitForFunc(ctx context.Context, handleUpdate func(update
4851
retries++
4952
}
5053

51-
opts := ActionListOpts{
52-
Sort: []string{"status", "id"},
53-
ID: make([]int64, 0, len(running)),
54-
}
55-
for actionID := range running {
56-
opts.ID = append(opts.ID, actionID)
57-
}
58-
slices.Sort(opts.ID)
54+
updates := make([]*Action, 0, len(running))
55+
for runningIDsChunk := range slices.Chunk(slices.Sorted(maps.Keys(running)), 25) {
56+
opts := ActionListOpts{
57+
Sort: []string{"status", "id"},
58+
ID: runningIDsChunk,
59+
}
60+
61+
updatesChunk, err := c.AllWithOpts(ctx, opts)
62+
if err != nil {
63+
return err
64+
}
5965

60-
updates, err := c.AllWithOpts(ctx, opts)
61-
if err != nil {
62-
return err
66+
updates = append(updates, updatesChunk...)
6367
}
6468

6569
if len(updates) != len(running) {
@@ -95,7 +99,7 @@ func (c *ActionClient) WaitForFunc(ctx context.Context, handleUpdate func(update
9599
}
96100

97101
// WaitFor waits until all actions succeed by polling the API at the interval defined by
98-
// [WithPollBackoffFunc]. An action is considered as succeeded when its status is either
102+
// [WithPollOpts]. An action is considered as succeeded when its status is either
99103
// [ActionStatusSuccess].
100104
//
101105
// If a single action fails, the function will stop waiting and the error set in the

cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/action_watch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
// timeout, use the [context.Context]. Once the method has stopped watching,
2222
// both returned channels are closed.
2323
//
24-
// WatchOverallProgress uses the [WithPollBackoffFunc] of the [Client] to wait
24+
// WatchOverallProgress uses the [WithPollOpts] of the [Client] to wait
2525
// until sending the next request.
2626
//
2727
// Deprecated: WatchOverallProgress is deprecated, use [WaitForFunc] instead.
@@ -86,7 +86,7 @@ func (c *ActionClient) WatchOverallProgress(ctx context.Context, actions []*Acti
8686
// timeout, use the [context.Context]. Once the method has stopped watching,
8787
// both returned channels are closed.
8888
//
89-
// WatchProgress uses the [WithPollBackoffFunc] of the [Client] to wait until
89+
// WatchProgress uses the [WithPollOpts] of the [Client] to wait until
9090
// sending the next request.
9191
//
9292
// Deprecated: WatchProgress is deprecated, use [WaitForFunc] instead.

0 commit comments

Comments
 (0)