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

refactor: use new client.Action.WaitFor #636

Closed
wants to merge 5 commits into from
Closed
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
25 changes: 12 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ go 1.21

require (
github.com/hetznercloud/hcloud-go/v2 v2.6.0
github.com/prometheus/client_golang v1.18.0
github.com/prometheus/client_golang v1.19.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
github.com/syself/hrobot-go v0.2.5
k8s.io/api v0.29.1
k8s.io/apimachinery v0.29.1
Expand Down Expand Up @@ -52,27 +52,24 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/stoewer/go-strcase v1.2.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
go.etcd.io/etcd/api/v3 v3.5.10 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.10 // indirect
go.etcd.io/etcd/client/v3 v3.5.10 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.42.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.44.0 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.10.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
Expand All @@ -82,21 +79,21 @@ require (
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.19.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/oauth2 v0.12.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/grpc v1.58.3 // indirect
google.golang.org/protobuf v1.31.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand All @@ -112,3 +109,5 @@ require (
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace github.com/hetznercloud/hcloud-go/v2 => github.com/hetznercloud/hcloud-go/v2 v2.7.3-0.20240430130644-7bb1a7b9ae5f
573 changes: 45 additions & 528 deletions go.sum

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions hcloud/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (r *routes) CreateRoute(ctx context.Context, clusterName string, nameHint s
return fmt.Errorf("%s: %w", op, err)
}

if err := hcops.WatchAction(ctx, &r.client.Action, action); err != nil {
if err := r.client.Action.WaitFor(ctx, action); err != nil {
return fmt.Errorf("%s: %w", op, err)
}
}
Expand Down Expand Up @@ -198,7 +198,7 @@ func (r *routes) deleteRouteFromHcloud(ctx context.Context, cidr *net.IPNet, ip
}
return fmt.Errorf("%s: %w", op, err)
}
if err := hcops.WatchAction(ctx, &r.client.Action, action); err != nil {
if err := r.client.Action.WaitFor(ctx, action); err != nil {
return fmt.Errorf("%s: %w", op, err)
}
return nil
Expand Down Expand Up @@ -256,7 +256,7 @@ func (r *routes) checkIfRouteAlreadyExists(ctx context.Context, route *cloudprov
return false, fmt.Errorf("%s: %w", op, err)
}

if err := hcops.WatchAction(ctx, &r.client.Action, action); err != nil {
if err := r.client.Action.WaitFor(ctx, action); err != nil {
return false, fmt.Errorf("%s: %w", op, err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions hcloud/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestRoutes_CreateRoute(t *testing.T) {
},
})
})
env.Mux.HandleFunc("/actions/1", func(w http.ResponseWriter, _ *http.Request) {
env.Mux.HandleFunc("/actions?id=1&page=1&sort=status&sort=id", func(w http.ResponseWriter, _ *http.Request) {
json.NewEncoder(w).Encode(schema.NetworkActionAddRouteResponse{
Action: schema.Action{
ID: 1,
Expand Down Expand Up @@ -155,7 +155,7 @@ func TestRoutes_DeleteRoute(t *testing.T) {
},
})
})
env.Mux.HandleFunc("/actions/1", func(w http.ResponseWriter, _ *http.Request) {
env.Mux.HandleFunc("/actions?id=1&page=1&sort=status&sort=id", func(w http.ResponseWriter, _ *http.Request) {
json.NewEncoder(w).Encode(schema.NetworkActionAddRouteResponse{
Action: schema.Action{
ID: 1,
Expand Down
8 changes: 1 addition & 7 deletions internal/hcops/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,5 @@ import (
)

type HCloudActionClient interface {
WatchProgress(ctx context.Context, a *hcloud.Action) (<-chan int, <-chan error)
}

func WatchAction(ctx context.Context, ac HCloudActionClient, a *hcloud.Action) error {
_, errCh := ac.WatchProgress(ctx, a)
err := <-errCh
return err
WaitFor(ctx context.Context, actions ...*hcloud.Action) error
}
28 changes: 14 additions & 14 deletions internal/hcops/load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (l *LoadBalancerOps) Create(
if err != nil {
return nil, fmt.Errorf("%s: %w", op, err)
}
if err := WatchAction(ctx, l.ActionClient, result.Action); err != nil {
if err := l.ActionClient.WaitFor(ctx, result.Action); err != nil {
return nil, fmt.Errorf("%s: %w", op, err)
}

Expand Down Expand Up @@ -374,7 +374,7 @@ func (l *LoadBalancerOps) changeIPv4RDNS(ctx context.Context, lb *hcloud.LoadBal
if err != nil {
return false, fmt.Errorf("%s: %w", op, err)
}
err = WatchAction(ctx, l.ActionClient, action)
err = l.ActionClient.WaitFor(ctx, action)
if err != nil {
return false, fmt.Errorf("%s: %w", op, err)
}
Expand All @@ -399,7 +399,7 @@ func (l *LoadBalancerOps) changeIPv6RDNS(ctx context.Context, lb *hcloud.LoadBal
if err != nil {
return false, fmt.Errorf("%s: %w", op, err)
}
err = WatchAction(ctx, l.ActionClient, action)
err = l.ActionClient.WaitFor(ctx, action)
if err != nil {
return false, fmt.Errorf("%s: %w", op, err)
}
Expand All @@ -426,7 +426,7 @@ func (l *LoadBalancerOps) changeAlgorithm(ctx context.Context, lb *hcloud.LoadBa
if err != nil {
return false, fmt.Errorf("%s: %w", op, err)
}
err = WatchAction(ctx, l.ActionClient, action)
err = l.ActionClient.WaitFor(ctx, action)
if err != nil {
return false, fmt.Errorf("%s: %w", op, err)
}
Expand All @@ -450,7 +450,7 @@ func (l *LoadBalancerOps) changeType(ctx context.Context, lb *hcloud.LoadBalance
if err != nil {
return false, fmt.Errorf("%s: %w", op, err)
}
err = WatchAction(ctx, l.ActionClient, action)
err = l.ActionClient.WaitFor(ctx, action)
if err != nil {
return false, fmt.Errorf("%s: %w", op, err)
}
Expand All @@ -476,7 +476,7 @@ func (l *LoadBalancerOps) detachFromNetwork(ctx context.Context, lb *hcloud.Load
if err != nil {
return changed, fmt.Errorf("%s: %w", op, err)
}
if err := WatchAction(ctx, l.ActionClient, a); err != nil {
if err := l.ActionClient.WaitFor(ctx, a); err != nil {
return changed, fmt.Errorf("%s: %w", op, err)
}
changed = true
Expand Down Expand Up @@ -520,7 +520,7 @@ func (l *LoadBalancerOps) attachToNetwork(ctx context.Context, lb *hcloud.LoadBa
return false, fmt.Errorf("%s: %w", op, err)
}

if err := WatchAction(ctx, l.ActionClient, a); err != nil {
if err := l.ActionClient.WaitFor(ctx, a); err != nil {
return false, fmt.Errorf("%s: %w", op, err)
}

Expand Down Expand Up @@ -554,7 +554,7 @@ func (l *LoadBalancerOps) togglePublicInterface(ctx context.Context, lb *hcloud.
return false, fmt.Errorf("%s: %w", op, err)
}

if err := WatchAction(ctx, l.ActionClient, a); err != nil {
if err := l.ActionClient.WaitFor(ctx, a); err != nil {
return false, fmt.Errorf("%s: %w", op, err)
}
return true, nil
Expand Down Expand Up @@ -658,7 +658,7 @@ func (l *LoadBalancerOps) ReconcileHCLBTargets(
if err != nil {
return changed, fmt.Errorf("%s: target: %s: %w", op, nodeName, err)
}
if err := WatchAction(ctx, l.ActionClient, a); err != nil {
if err := l.ActionClient.WaitFor(ctx, a); err != nil {
return changed, fmt.Errorf("%s: target: %s: %w", op, nodeName, err)
}
changed = true
Expand Down Expand Up @@ -695,7 +695,7 @@ func (l *LoadBalancerOps) ReconcileHCLBTargets(
}
return changed, e
}
if err := WatchAction(ctx, l.ActionClient, a); err != nil {
if err := l.ActionClient.WaitFor(ctx, a); err != nil {
var e error
if foundServer {
e = fmt.Errorf("%s: target: %s: %w", op, nodeName, err)
Expand Down Expand Up @@ -738,7 +738,7 @@ func (l *LoadBalancerOps) ReconcileHCLBTargets(
}
return changed, fmt.Errorf("%s: target %s: %w", op, node.Name, err)
}
if err := WatchAction(ctx, l.ActionClient, a); err != nil {
if err := l.ActionClient.WaitFor(ctx, a); err != nil {
return changed, fmt.Errorf("%s: target %s: %w", op, node.Name, err)
}
changed = true
Expand Down Expand Up @@ -780,7 +780,7 @@ func (l *LoadBalancerOps) ReconcileHCLBTargets(
}
return changed, fmt.Errorf("%s: target %s: %w", op, node, err)
}
if err := WatchAction(ctx, l.ActionClient, a); err != nil {
if err := l.ActionClient.WaitFor(ctx, a); err != nil {
return changed, fmt.Errorf("%s: target %s: %w", op, node, err)
}
changed = true
Expand Down Expand Up @@ -870,7 +870,7 @@ func (l *LoadBalancerOps) ReconcileHCLBServices(
}
}

if err = WatchAction(ctx, l.ActionClient, action); err != nil {
if err = l.ActionClient.WaitFor(ctx, action); err != nil {
return changed, fmt.Errorf("%s: %w", op, err)
}
changed = true
Expand All @@ -883,7 +883,7 @@ func (l *LoadBalancerOps) ReconcileHCLBServices(
if err != nil {
return changed, fmt.Errorf("%s: port %d: %w", op, p, err)
}
err = WatchAction(ctx, l.ActionClient, a)
err = l.ActionClient.WaitFor(ctx, a)
if err != nil {
return changed, fmt.Errorf("%s: port: %d: %w", op, p, err)
}
Expand Down
Loading
Loading