Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/metal-stack/metal-api int…
Browse files Browse the repository at this point in the history
…o dualstack-support
  • Loading branch information
majst01 committed Aug 5, 2024
2 parents 87a2a98 + 5a5b2e4 commit 23e4cbd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
5 changes: 1 addition & 4 deletions cmd/metal-api/internal/metal/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,6 @@ func (r IngressRule) Validate() error {
if err := validateCIDRs(r.From); err != nil {
return err
}
if err := validateCIDRs(slices.Concat(r.From, r.To)); err != nil {
return err
}

return nil
}
Expand Down Expand Up @@ -279,7 +276,7 @@ func validateCIDRs(cidrs []string) error {
var newaf string
if p.Addr().Is4() {
newaf = "ipv4"
} else {
} else if p.Addr().Is6() {
newaf = "ipv6"
}
if af != "" && af != newaf {
Expand Down
16 changes: 8 additions & 8 deletions cmd/metal-api/internal/service/network-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (r *networkResource) findNetwork(request *restful.Request, response *restfu
return
}
ctx := request.Request.Context()
usage, err := getNetworkUsage(ctx, nw, r.ipamer)
usage, err := r.getNetworkUsage(ctx, nw)
if err != nil {
r.sendError(request, response, defaultError(err))
return
Expand All @@ -175,7 +175,7 @@ func (r *networkResource) listNetworks(request *restful.Request, response *restf
ctx := request.Request.Context()
var result []*v1.NetworkResponse
for i := range nws {
usage, err := getNetworkUsage(ctx, &nws[i], r.ipamer)
usage, err := r.getNetworkUsage(ctx, &nws[i])
if err != nil {
r.sendError(request, response, defaultError(err))
return
Expand Down Expand Up @@ -210,7 +210,7 @@ func (r *networkResource) findNetworks(request *restful.Request, response *restf
ctx := request.Request.Context()
result := []*v1.NetworkResponse{}
for i := range nws {
usage, err := getNetworkUsage(ctx, &nws[i], r.ipamer)
usage, err := r.getNetworkUsage(ctx, &nws[i])
if err != nil {
r.sendError(request, response, defaultError(err))
return
Expand Down Expand Up @@ -417,7 +417,7 @@ func (r *networkResource) createNetwork(request *restful.Request, response *rest
return
}

usage, err := getNetworkUsage(ctx, nw, r.ipamer)
usage, err := r.getNetworkUsage(ctx, nw)
if err != nil {
r.sendError(request, response, defaultError(err))
return
Expand Down Expand Up @@ -634,7 +634,7 @@ func (r *networkResource) allocateNetwork(request *restful.Request, response *re
return
}

usage, err := getNetworkUsage(ctx, nw, r.ipamer)
usage, err := r.getNetworkUsage(ctx, nw)
if err != nil {
r.sendError(request, response, defaultError(err))
return
Expand Down Expand Up @@ -828,7 +828,7 @@ func (r *networkResource) updateNetwork(request *restful.Request, response *rest
return
}

usage, err := getNetworkUsage(ctx, &newNetwork, r.ipamer)
usage, err := r.getNetworkUsage(ctx, &newNetwork)
if err != nil {
r.sendError(request, response, defaultError(err))
return
Expand Down Expand Up @@ -896,7 +896,7 @@ func (r *networkResource) deleteNetwork(request *restful.Request, response *rest
r.send(request, response, http.StatusOK, v1.NewNetworkResponse(nw, &metal.NetworkUsage{}))
}

func getNetworkUsage(ctx context.Context, nw *metal.Network, ipamer ipam.IPAMer) (*metal.NetworkUsage, error) {
func (r *networkResource) getNetworkUsage(ctx context.Context, nw *metal.Network) (*metal.NetworkUsage, error) {
usage := &metal.NetworkUsage{
AvailableIPs: make(map[metal.AddressFamily]uint64),
UsedIPs: make(map[metal.AddressFamily]uint64),
Expand All @@ -915,7 +915,7 @@ func getNetworkUsage(ctx context.Context, nw *metal.Network, ipamer ipam.IPAMer)
if pfx.Addr().Is6() {
key = metal.IPv6AddressFamily
}
u, err := ipamer.PrefixUsage(ctx, prefix.String())
u, err := r.ipamer.PrefixUsage(ctx, prefix.String())
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 23e4cbd

Please sign in to comment.