Skip to content

Commit d5e5fcf

Browse files
authored
Do not error out if no ip is available in a prefix (#551)
1 parent 89978cc commit d5e5fcf

File tree

4 files changed

+68
-61
lines changed

4 files changed

+68
-61
lines changed

cmd/metal-api/internal/service/async-actor.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import (
66
"fmt"
77
"log/slog"
88

9+
"connectrpc.com/connect"
910
"github.com/metal-stack/metal-api/cmd/metal-api/internal/headscale"
1011

11-
ipamer "github.com/metal-stack/go-ipam"
1212
"github.com/metal-stack/metal-api/cmd/metal-api/internal/datastore"
1313
"github.com/metal-stack/metal-api/cmd/metal-api/internal/ipam"
1414
"github.com/metal-stack/metal-api/cmd/metal-api/internal/metal"
@@ -216,12 +216,15 @@ func (a *asyncActor) releaseIP(ip metal.IP) error {
216216

217217
// now the IP should not exist any more in our datastore
218218
// so cleanup the ipam
219-
219+
220220
ctx := context.Background()
221221
err = a.ReleaseIP(ctx, ip)
222222
if err != nil {
223-
if errors.Is(err, ipamer.ErrNotFound) {
224-
return nil
223+
var connectErr *connect.Error
224+
if errors.As(err, &connectErr) {
225+
if connectErr.Code() == connect.CodeNotFound {
226+
return nil
227+
}
225228
}
226229
return fmt.Errorf("cannot release IP %q: %w", ip, err)
227230
}

cmd/metal-api/internal/service/ip-service.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import (
2323

2424
v1 "github.com/metal-stack/metal-api/cmd/metal-api/internal/service/v1"
2525

26-
goipam "github.com/metal-stack/go-ipam"
27-
2826
restfulspec "github.com/emicklei/go-restful-openapi/v2"
2927
restful "github.com/emicklei/go-restful/v3"
3028
"github.com/metal-stack/metal-lib/httperrors"
@@ -439,10 +437,13 @@ func allocateSpecificIP(ctx context.Context, parent *metal.Network, specificIP s
439437
func allocateRandomIP(ctx context.Context, parent *metal.Network, ipamer ipam.IPAMer) (ipAddress, parentPrefixCidr string, err error) {
440438
for _, prefix := range parent.Prefixes {
441439
ipAddress, err = ipamer.AllocateIP(ctx, prefix)
442-
if err != nil && errors.Is(err, goipam.ErrNoIPAvailable) {
443-
continue
444-
}
445440
if err != nil {
441+
var connectErr *connect.Error
442+
if errors.As(err, &connectErr) {
443+
if connectErr.Code() == connect.CodeNotFound {
444+
continue
445+
}
446+
}
446447
return "", "", err
447448
}
448449

go.mod

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/juanfont/headscale v0.22.3
1919
github.com/klauspost/connect-compress/v2 v2.0.0
2020
github.com/looplab/fsm v1.0.2
21-
github.com/metal-stack/go-ipam v1.14.1
21+
github.com/metal-stack/go-ipam v1.14.3
2222
github.com/metal-stack/masterdata-api v0.11.4
2323
github.com/metal-stack/metal-lib v0.17.2
2424
github.com/metal-stack/security v0.8.0
@@ -31,9 +31,9 @@ require (
3131
github.com/stretchr/testify v1.9.0
3232
github.com/testcontainers/testcontainers-go v0.31.0
3333
github.com/undefinedlabs/go-mpatch v1.0.7
34-
golang.org/x/crypto v0.24.0
34+
golang.org/x/crypto v0.25.0
3535
golang.org/x/sync v0.7.0
36-
google.golang.org/grpc v1.64.0
36+
google.golang.org/grpc v1.65.0
3737
google.golang.org/protobuf v1.34.2
3838
gopkg.in/rethinkdb/rethinkdb-go.v6 v6.2.2
3939
)
@@ -63,9 +63,9 @@ require (
6363
github.com/beorn7/perks v1.0.1 // indirect
6464
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
6565
github.com/cespare/xxhash/v2 v2.3.0 // indirect
66-
github.com/containerd/containerd v1.7.18 // indirect
67-
github.com/containerd/errdefs v0.1.0 // indirect
66+
github.com/containerd/containerd v1.7.19 // indirect
6867
github.com/containerd/log v0.1.0 // indirect
68+
github.com/containerd/platforms v0.2.1 // indirect
6969
github.com/coreos/go-oidc/v3 v3.10.0 // indirect
7070
github.com/coreos/go-semver v0.3.1 // indirect
7171
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
@@ -147,6 +147,7 @@ require (
147147
github.com/modern-go/reflect2 v1.0.2 // indirect
148148
github.com/montanaflynn/stats v0.7.1 // indirect
149149
github.com/morikuni/aec v1.0.0 // indirect
150+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
150151
github.com/ncruces/go-strftime v0.1.9 // indirect
151152
github.com/oklog/ulid v1.3.1 // indirect
152153
github.com/opencontainers/go-digest v1.0.0 // indirect
@@ -159,10 +160,10 @@ require (
159160
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
160161
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
161162
github.com/prometheus/client_model v0.6.1 // indirect
162-
github.com/prometheus/common v0.54.0 // indirect
163+
github.com/prometheus/common v0.55.0 // indirect
163164
github.com/prometheus/procfs v0.15.1 // indirect
164165
github.com/puzpuzpuz/xsync/v2 v2.5.1 // indirect
165-
github.com/redis/go-redis/v9 v9.5.3 // indirect
166+
github.com/redis/go-redis/v9 v9.5.4 // indirect
166167
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
167168
github.com/rs/zerolog v1.33.0 // indirect
168169
github.com/sagikazarmark/locafero v0.6.0 // indirect
@@ -191,24 +192,24 @@ require (
191192
go.etcd.io/etcd/api/v3 v3.5.14 // indirect
192193
go.etcd.io/etcd/client/pkg/v3 v3.5.14 // indirect
193194
go.etcd.io/etcd/client/v3 v3.5.14 // indirect
194-
go.mongodb.org/mongo-driver v1.15.1 // indirect
195-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 // indirect
196-
go.opentelemetry.io/otel v1.27.0 // indirect
197-
go.opentelemetry.io/otel/metric v1.27.0 // indirect
198-
go.opentelemetry.io/otel/trace v1.27.0
195+
go.mongodb.org/mongo-driver v1.16.0 // indirect
196+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect
197+
go.opentelemetry.io/otel v1.28.0 // indirect
198+
go.opentelemetry.io/otel/metric v1.28.0 // indirect
199+
go.opentelemetry.io/otel/trace v1.28.0
199200
go.uber.org/multierr v1.11.0 // indirect
200201
go.uber.org/zap v1.27.0 // indirect
201202
go4.org/mem v0.0.0-20240501181205-ae6ca9944745 // indirect
202203
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect
203204
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8
204-
golang.org/x/net v0.26.0 // indirect
205+
golang.org/x/net v0.27.0 // indirect
205206
golang.org/x/oauth2 v0.21.0 // indirect
206-
golang.org/x/sys v0.21.0 // indirect
207+
golang.org/x/sys v0.22.0 // indirect
207208
golang.org/x/text v0.16.0 // indirect
208209
golang.org/x/time v0.5.0 // indirect; indirecct
209210
golang.zx2c4.com/wireguard/windows v0.5.3 // indirect
210-
google.golang.org/genproto/googleapis/api v0.0.0-20240617180043-68d350f18fd4 // indirect
211-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240617180043-68d350f18fd4 // indirect
211+
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d // indirect
212+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d // indirect
212213
gopkg.in/cenkalti/backoff.v2 v2.2.1 // indirect
213214
gopkg.in/inf.v0 v0.9.1 // indirect
214215
gopkg.in/ini.v1 v1.67.0 // indirect

0 commit comments

Comments
 (0)