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

chore: get rid of golang.org/x/exp/{constraints,slices} modules #8239

Merged
merged 1 commit into from
Oct 8, 2024
Merged
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
2 changes: 1 addition & 1 deletion apis/operations/v1alpha1/opsrequest_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (
"context"
"encoding/json"
"fmt"
"slices"
"strings"

"github.com/pkg/errors"
"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/cluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ package apps
import (
"encoding/json"
"fmt"
"slices"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/sethvargo/go-password/password"
"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/cluster_status_conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ package apps

import (
"fmt"
"slices"

"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/clusterdefinition_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ package apps
import (
"context"
"fmt"
"slices"
"strings"

"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
k8sruntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/record"
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/componentdefinition_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (
"fmt"
"hash/fnv"
"reflect"
"slices"
"strings"

"github.com/pkg/errors"
"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
Expand Down
6 changes: 3 additions & 3 deletions controllers/apps/configuration/reconfigure_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ func (param *reconfigureParams) maxRollingReplicas() int32 {
if isPercentage {
r = int32(math.Floor(float64(v) * float64(replicas) / 100))
} else {
r = util.Safe2Int32(util.Min(v, param.getTargetReplicas()))
r = util.Safe2Int32(min(v, param.getTargetReplicas()))
}
return util.Max(r, defaultRolling)
return max(r, defaultRolling)
}

func (param *reconfigureParams) getTargetReplicas() int {
Expand All @@ -195,7 +195,7 @@ func (param *reconfigureParams) getTargetReplicas() int {

func (param *reconfigureParams) podMinReadySeconds() int32 {
minReadySeconds := param.SynthesizedComponent.MinReadySeconds
return util.Max(minReadySeconds, viper.GetInt32(constant.PodMinReadySecondsEnv))
return max(minReadySeconds, viper.GetInt32(constant.PodMinReadySecondsEnv))
}

func RegisterPolicy(policy appsv1alpha1.UpgradePolicy, action reconfigurePolicy) {
Expand Down
3 changes: 1 addition & 2 deletions controllers/apps/configuration/rolling_upgrade_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

appsv1alpha1 "github.com/apecloud/kubeblocks/apis/apps/v1alpha1"
"github.com/apecloud/kubeblocks/pkg/configuration/util"
"github.com/apecloud/kubeblocks/pkg/constant"
podutil "github.com/apecloud/kubeblocks/pkg/controllerutil"
viper "github.com/apecloud/kubeblocks/pkg/viperx"
Expand Down Expand Up @@ -151,7 +150,7 @@ func markDynamicCursor(pods []corev1.Pod, podsStats *componentPodStats, configKe
podsStats.updated[pod.Name] = pod
}

podWindows.begin = util.Max[int](podWindows.end-int(rollingReplicas), 0)
podWindows.begin = max(podWindows.end-int(rollingReplicas), 0)
for i := podWindows.begin; i < podWindows.end; i++ {
pod := &pods[i]
if podutil.IsMatchConfigVersion(pod, configKey, currentVersion) {
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/transformer_cluster_backup_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ package apps
import (
"encoding/json"
"fmt"
"slices"
"strings"

"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/gengo/examples/set-gen/sets"
Expand Down
12 changes: 7 additions & 5 deletions controllers/apps/transformer_cluster_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package apps

import (
"slices"
"strings"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
Expand Down Expand Up @@ -113,8 +115,8 @@ var _ = Describe("cluster service transformer test", func() {
graphCli := transCtx.Client.(model.GraphClient)
objs := graphCli.FindAll(dag, &corev1.Service{})
Expect(len(objs)).Should(Equal(len(reader.objs)))
slices.SortFunc(objs, func(a, b client.Object) bool {
return a.GetName() < b.GetName()
slices.SortFunc(objs, func(a, b client.Object) int {
return strings.Compare(a.GetName(), b.GetName())
})
for i := 0; i < len(reader.objs); i++ {
svc := objs[i].(*corev1.Service)
Expand Down Expand Up @@ -149,8 +151,8 @@ var _ = Describe("cluster service transformer test", func() {

for i := 0; i < len(transCtx.Cluster.Spec.Services); i++ {
svc := objs[i].(*corev1.Service)
slices.SortFunc(svc.Spec.Ports, func(a, b corev1.ServicePort) bool { return a.Name < b.Name })
slices.SortFunc(expectedPorts, func(a, b corev1.ServicePort) bool { return a.Name < b.Name })
slices.SortFunc(svc.Spec.Ports, func(a, b corev1.ServicePort) int { return strings.Compare(a.Name, b.Name) })
slices.SortFunc(expectedPorts, func(a, b corev1.ServicePort) int { return strings.Compare(a.Name, b.Name) })
Expect(svc.Spec.Ports).Should(Equal(expectedPorts))
Expect(graphCli.IsAction(dag, svc, model.ActionUpdatePtr())).Should(BeTrue())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package apps

import (
"slices"
"strings"

"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down
15 changes: 8 additions & 7 deletions controllers/apps/transformer_component_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ package apps

import (
"fmt"
"slices"
"strings"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -133,8 +134,8 @@ var _ = Describe(" component service transformer test", func() {
graphCli := transCtx.Client.(model.GraphClient)
objs := graphCli.FindAll(dag, &corev1.Service{})
Expect(len(objs)).Should(Equal(int(transCtx.SynthesizeComponent.Replicas)))
slices.SortFunc(objs, func(a, b client.Object) bool {
return a.GetName() < b.GetName()
slices.SortFunc(objs, func(a, b client.Object) int {
return strings.Compare(a.GetName(), b.GetName())
})
for i := int32(0); i < transCtx.SynthesizeComponent.Replicas; i++ {
svc := objs[i].(*corev1.Service)
Expand All @@ -160,8 +161,8 @@ var _ = Describe(" component service transformer test", func() {
graphCli := transCtx.Client.(model.GraphClient)
objs := graphCli.FindAll(dag, &corev1.Service{})
Expect(len(objs)).Should(Equal(int(transCtx.SynthesizeComponent.Replicas)))
slices.SortFunc(objs, func(a, b client.Object) bool {
return a.GetName() < b.GetName()
slices.SortFunc(objs, func(a, b client.Object) int {
return strings.Compare(a.GetName(), b.GetName())
})
for i := int32(0); i < transCtx.SynthesizeComponent.Replicas; i++ {
svc := objs[i].(*corev1.Service)
Expand All @@ -188,8 +189,8 @@ var _ = Describe(" component service transformer test", func() {
graphCli := transCtx.Client.(model.GraphClient)
objs := graphCli.FindAll(dag, &corev1.Service{})
Expect(len(objs)).Should(Equal(int(replicas)))
slices.SortFunc(objs, func(a, b client.Object) bool {
return a.GetName() < b.GetName()
slices.SortFunc(objs, func(a, b client.Object) int {
return strings.Compare(a.GetName(), b.GetName())
})
for i := int32(0); i < replicas; i++ {
svc := objs[i].(*corev1.Service)
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/transformer_component_workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
"errors"
"fmt"
"reflect"
"slices"
"strings"

"github.com/spf13/viper"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
Expand Down
6 changes: 3 additions & 3 deletions controllers/dataprotection/log_collection_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ package dataprotection
import (
"context"
"fmt"
"slices"
"strings"

"github.com/spf13/viper"
"golang.org/x/exp/slices"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
k8sruntime "k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -136,8 +136,8 @@ func (r *LogCollectionReconciler) collectErrorLogs(reqCtx intctrlutil.RequestCtx
return "", nil
}
// sort pod with oldest creation place front
slices.SortFunc(podList.Items, func(a, b corev1.Pod) bool {
return !b.CreationTimestamp.Before(&(a.CreationTimestamp))
slices.SortFunc(podList.Items, func(a, b corev1.Pod) int {
return b.CreationTimestamp.Compare(a.CreationTimestamp.Time)
})
oldestPod := podList.Items[0]
clientset, err := corev1client.NewForConfig(r.RestConfig)
Expand Down
2 changes: 1 addition & 1 deletion controllers/dataprotection/volumepopulator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ package dataprotection
import (
"context"
"fmt"
"slices"
"strings"

vsv1 "github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumesnapshot/v1"
"golang.org/x/exp/slices"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package experimental

import (
"slices"
"time"

"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand Down
2 changes: 1 addition & 1 deletion controllers/experimental/reconciler_update_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ package experimental

import (
"fmt"
"slices"
"strings"

"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
6 changes: 3 additions & 3 deletions controllers/extensions/addon_controller_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import (
"context"
"encoding/json"
"fmt"
"slices"
"strings"
"time"

"github.com/Masterminds/semver/v3"
ctrlerihandler "github.com/authzed/controller-idioms/handler"
"golang.org/x/exp/slices"
v1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -1101,8 +1101,8 @@ func logFailedJobPodToCondError(ctx context.Context, stageCtx *stageCtx, addon *
}

// sort pod with latest creation place front
slices.SortFunc(podList.Items, func(a, b corev1.Pod) bool {
return b.CreationTimestamp.Before(&(a.CreationTimestamp))
slices.SortFunc(podList.Items, func(a, b corev1.Pod) int {
return b.CreationTimestamp.Compare(a.CreationTimestamp.Time)
})

podsloop:
Expand Down
2 changes: 1 addition & 1 deletion controllers/operations/opsrequest_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"context"
"math"
"reflect"
"slices"
"strings"
"time"

"golang.org/x/exp/slices"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down
2 changes: 1 addition & 1 deletion controllers/operations/opsrequest_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ package operations
import (
"fmt"
"reflect"
"slices"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

snapshotv1 "github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumesnapshot/v1"
"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,3 @@ require (
sigs.k8s.io/kustomize/kyaml v0.14.3 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
)

replace golang.org/x/exp => golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb
Loading
Loading