Skip to content

Commit

Permalink
refactor: replace golang.org/x/exp with stdlib (#7131)
Browse files Browse the repository at this point in the history
* refactor: replace `golang.org/x/exp` with stdlib

These experimental packages are now available in the Go standard
library:

	1. golang.org/x/exp/slices -> slices [1]
	2. golang.org/x/exp/maps -> maps [2]

[1]: https://go.dev/doc/go1.21#slices
[2]: https://go.dev/doc/go1.21#maps

Signed-off-by: Eng Zer Jun <[email protected]>

* Fix TestGetEndpointSlicesBySubselectedPods_GetsEndpointsOnNilValues

Signed-off-by: Eng Zer Jun <[email protected]>

---------

Signed-off-by: Eng Zer Jun <[email protected]>
  • Loading branch information
Juneezee authored Jan 16, 2025
1 parent 16874fe commit dec80c7
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 12 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ require (
github.com/stretchr/testify v1.10.0
go.opentelemetry.io/otel v1.33.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.33.0
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
k8s.io/api v0.32.0
k8s.io/apimachinery v0.32.0
k8s.io/client-go v0.32.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,6 @@ golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDf
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
Expand Down
10 changes: 5 additions & 5 deletions internal/k8s/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ import (
"context"
"fmt"
"log/slog"
"maps"
"net"
"os"
"slices"
"strconv"
"strings"
"sync"
"time"

"github.com/nginx/kubernetes-ingress/internal/telemetry"
"golang.org/x/exp/maps"

"github.com/nginx/kubernetes-ingress/internal/k8s/appprotect"
"github.com/nginx/kubernetes-ingress/internal/k8s/appprotectdos"
"github.com/nginx/kubernetes-ingress/internal/telemetry"
"k8s.io/client-go/informers"
"k8s.io/client-go/rest"

Expand Down Expand Up @@ -3009,7 +3009,7 @@ func getEndpointsFromEndpointSlicesForSubselectedPods(targetPort int32, pods []*
}
}
}
return maps.Keys(endpointSet)
return slices.Collect(maps.Keys(endpointSet))
}

return makePodEndpoints(pods, filterReadyEndpointsFrom(selectEndpointSlicesForPort(targetPort, svcEndpointSlices)))
Expand Down Expand Up @@ -3147,7 +3147,7 @@ func (lbc *LoadBalancerController) getEndpointsForPortFromEndpointSlices(endpoin
endpointSet[podEndpoint] = struct{}{}
}
}
return maps.Keys(endpointSet)
return slices.Collect(maps.Keys(endpointSet))
}

endpoints := makePodEndpoints(targetPort, filterReadyEndpointsFrom(selectEndpointSlicesForPort(targetPort, endpointSlices)))
Expand Down
4 changes: 2 additions & 2 deletions internal/k8s/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,7 @@ func TestGetEndpointSlicesBySubselectedPods_GetsEndpointsOnNilValues(t *testing.
{
desc: "no endpoints selected on nil endpoint port",
targetPort: 8080,
want: []podEndpoint{},
want: nil,
pods: []*api_v1.Pod{
{
ObjectMeta: meta_v1.ObjectMeta{
Expand Down Expand Up @@ -1267,7 +1267,7 @@ func TestGetEndpointSlicesBySubselectedPods_GetsEndpointsOnNilValues(t *testing.
{
desc: "no endpoints selected on nil endpoint condition",
targetPort: 8080,
want: []podEndpoint{},
want: nil,
pods: []*api_v1.Pod{
{
ObjectMeta: meta_v1.ObjectMeta{
Expand Down
3 changes: 1 addition & 2 deletions pkg/apis/externaldns/validation/externaldns.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package validation
import (
"errors"
"fmt"
"slices"
"strings"

"golang.org/x/exp/slices"

v1 "github.com/nginx/kubernetes-ingress/pkg/apis/externaldns/v1"
"k8s.io/apimachinery/pkg/util/validation"
"k8s.io/apimachinery/pkg/util/validation/field"
Expand Down

0 comments on commit dec80c7

Please sign in to comment.