From 09fc2867c44c7889ebe7ba7efed0df71d54b5d90 Mon Sep 17 00:00:00 2001 From: LiHui Date: Wed, 29 Sep 2021 09:35:18 +0800 Subject: [PATCH] remove mathutil.Max --- .../openpitrix/helmrepo/helm_repo_controller.go | 9 ++++----- pkg/kapis/openpitrix/v1/handler.go | 5 ++--- pkg/utils/mathutil/mathutil.go | 9 --------- 3 files changed, 6 insertions(+), 17 deletions(-) delete mode 100644 pkg/utils/mathutil/mathutil.go diff --git a/pkg/controller/openpitrix/helmrepo/helm_repo_controller.go b/pkg/controller/openpitrix/helmrepo/helm_repo_controller.go index 8f30d93dc..bca75aecd 100644 --- a/pkg/controller/openpitrix/helmrepo/helm_repo_controller.go +++ b/pkg/controller/openpitrix/helmrepo/helm_repo_controller.go @@ -21,9 +21,6 @@ import ( "math" "time" - "kubesphere.io/kubesphere/pkg/constants" - "kubesphere.io/kubesphere/pkg/utils/mathutil" - "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -38,6 +35,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" + "kubesphere.io/kubesphere/pkg/constants" + "kubesphere.io/api/application/v1alpha1" "kubesphere.io/kubesphere/pkg/simple/client/openpitrix/helmrepoindex" @@ -157,7 +156,7 @@ func (r *ReconcileHelmRepo) Reconcile(ctx context.Context, request reconcile.Req copyInstance := instance.DeepCopy() if copyInstance.Spec.SyncPeriod != 0 { - copyInstance.Spec.SyncPeriod = mathutil.Max(copyInstance.Spec.SyncPeriod, constants.HelmRepoMinSyncPeriod) + copyInstance.Spec.SyncPeriod = int(math.Max(float64(copyInstance.Spec.SyncPeriod), constants.HelmRepoMinSyncPeriod)) } retryAfter := 0 @@ -256,7 +255,7 @@ func needReSyncNow(instance *v1alpha1.HelmRepo) (syncNow bool, after int) { } else { period = instance.Spec.SyncPeriod if period != 0 { - period = mathutil.Max(instance.Spec.SyncPeriod, constants.HelmRepoMinSyncPeriod) + period = int(math.Max(float64(instance.Spec.SyncPeriod), constants.HelmRepoMinSyncPeriod)) if now.After(state.SyncTime.Add(time.Duration(period) * time.Second)) { return true, 0 } diff --git a/pkg/kapis/openpitrix/v1/handler.go b/pkg/kapis/openpitrix/v1/handler.go index 9da8d863a..5a9ef099b 100644 --- a/pkg/kapis/openpitrix/v1/handler.go +++ b/pkg/kapis/openpitrix/v1/handler.go @@ -17,13 +17,12 @@ import ( "encoding/json" "fmt" "io/ioutil" + "math" "net/url" "strconv" "strings" "time" - "kubesphere.io/kubesphere/pkg/utils/mathutil" - restful "github.com/emicklei/go-restful" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -101,7 +100,7 @@ func (h *openpitrixHandler) CreateRepo(req *restful.Request, resp *restful.Respo api.HandleBadRequest(resp, nil, err) return } else if duration > 0 { - syncPeriod = mathutil.Max(int(duration/time.Second), constants.HelmRepoMinSyncPeriod) + syncPeriod = int(math.Max(float64(duration/time.Second), constants.HelmRepoMinSyncPeriod)) } } diff --git a/pkg/utils/mathutil/mathutil.go b/pkg/utils/mathutil/mathutil.go deleted file mode 100644 index b82829fc2..000000000 --- a/pkg/utils/mathutil/mathutil.go +++ /dev/null @@ -1,9 +0,0 @@ -package mathutil - -// Max returns the larger of a and b. -func Max(a, b int) int { - if a >= b { - return a - } - return b -}