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

move to samber lib intead of go-funk #638

Merged
merged 1 commit into from
Feb 11, 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
18 changes: 9 additions & 9 deletions controllers/githubactionrunner_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,17 @@ import (
"context"
"errors"
"fmt"
"github.com/caitlinelfring/go-env-default"
"strconv"
"strings"
"time"

env "github.com/caitlinelfring/go-env-default"

garov1alpha1 "github.com/evryfs/github-actions-runner-operator/api/v1alpha1"
"github.com/evryfs/github-actions-runner-operator/controllers/githubapi"
"github.com/go-logr/logr"
"github.com/google/go-github/v58/github"
"github.com/redhat-cop/operator-utils/pkg/util"
"github.com/thoas/go-funk"
"github.com/samber/lo"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -127,7 +126,8 @@ func (r *GithubActionRunnerReconciler) handleScaling(ctx context.Context, instan

if shouldScaleUp(podRunnerPairs, instance) {
instance.Status.CurrentSize = podRunnerPairs.numPods()
scale := funk.MaxInt([]int{instance.Spec.MinRunners - podRunnerPairs.numRunners(), 1})

scale := lo.Max([]int{instance.Spec.MinRunners - podRunnerPairs.numRunners(), 1})
logger.Info("Scaling up", "numInstances", scale)

if err := r.scaleUp(ctx, scale, instance); err != nil {
Expand Down Expand Up @@ -332,9 +332,9 @@ func (r *GithubActionRunnerReconciler) listRelatedPods(ctx context.Context, cr *
}

// filter result by owner-ref since it cannot be done server-side
podList.Items = funk.Filter(podList.Items, func(pod corev1.Pod) bool {
podList.Items = lo.Filter(podList.Items, func(pod corev1.Pod, _ int) bool {
return util.IsOwner(cr, &pod)
}).([]corev1.Pod)
})

return podList, nil
}
Expand Down Expand Up @@ -416,9 +416,9 @@ func (r *GithubActionRunnerReconciler) getPodRunnerPairs(ctx context.Context, cr
}

allRunners, err := r.GithubAPI.GetRunners(ctx, cr.Spec.Organization, cr.Spec.Repository, token)
runners := funk.Filter(allRunners, func(r *github.Runner) bool {
return strings.HasPrefix(r.GetName(), cr.Name)
}).([]*github.Runner)
runners := lo.Filter(allRunners, func(runner *github.Runner, _ int) bool {
return strings.HasPrefix(runner.GetName(), cr.Name)
})

if err != nil {
return podRunnerPairList, err
Expand Down
14 changes: 7 additions & 7 deletions controllers/podrunner_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/evryfs/github-actions-runner-operator/api/v1alpha1"
"github.com/google/go-github/v58/github"
"github.com/redhat-cop/operator-utils/pkg/util"
"github.com/thoas/go-funk"
"github.com/samber/lo"
corev1 "k8s.io/api/core/v1"
)

Expand Down Expand Up @@ -50,9 +50,9 @@ func from(podList *corev1.PodList, runners []*github.Runner) podRunnerPairList {
}

func (r podRunnerPairList) getBusyRunners() []*github.Runner {
return funk.Filter(r.runners, func(runner *github.Runner) bool {
return lo.Filter(r.runners, func(runner *github.Runner, _ int) bool {
return runner.GetBusy()
}).([]*github.Runner)
})
}

func (r podRunnerPairList) numBusy() int {
Expand Down Expand Up @@ -80,9 +80,9 @@ func (r podRunnerPairList) numIdle() int {
}

func (r podRunnerPairList) getIdles(sortOrder v1alpha1.SortOrder, minTTL time.Duration) []podRunnerPair {
idles := funk.Filter(r.pairs, func(pair podRunnerPair) bool {
idles := lo.Filter(r.pairs, func(pair podRunnerPair, _ int) bool {
return !(pair.runner.GetBusy() || util.IsBeingDeleted(&pair.pod)) && time.Now().After(pair.pod.CreationTimestamp.Add(minTTL))
}).([]podRunnerPair)
})

sort.SliceStable(idles, func(i, j int) bool {
if sortOrder == v1alpha1.LeastRecent {
Expand All @@ -95,7 +95,7 @@ func (r podRunnerPairList) getIdles(sortOrder v1alpha1.SortOrder, minTTL time.Du
}

func (r podRunnerPairList) getPodsBeingDeletedOrEvictedOrCompleted() []podRunnerPair {
return funk.Filter(r.pairs, func(pair podRunnerPair) bool {
return lo.Filter(r.pairs, func(pair podRunnerPair, _ int) bool {
return util.IsBeingDeleted(&pair.pod) || isEvicted(&pair.pod) || isCompleted(&pair.pod)
}).([]podRunnerPair)
})
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ require (
github.com/palantir/go-githubapp v0.22.0
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475
github.com/redhat-cop/operator-utils v1.3.8
github.com/samber/lo v1.39.0
github.com/stretchr/testify v1.8.4
github.com/thoas/go-funk v0.9.3
go.uber.org/zap v1.26.0
k8s.io/api v0.29.1
k8s.io/apimachinery v0.29.1
Expand Down Expand Up @@ -88,6 +88,7 @@ require (
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sync v0.2.0 // indirect
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncj
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A=
github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/samber/lo v1.39.0 h1:4gTz1wUhNYLhFSKl6O+8peW0v2F4BCY034GRpU9WnuA=
github.com/samber/lo v1.39.0/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
Expand All @@ -250,16 +252,13 @@ github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/thoas/go-funk v0.9.3 h1:7+nAEx3kn5ZJcnDm2Bh23N2yOtweO14bi//dvRtgLpw=
github.com/thoas/go-funk v0.9.3/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q=
github.com/xlab/treeprint v1.2.0 h1:HzHnuAF1plUN2zGlAFHbSQP2qJ0ZAD3XF5XD7OesXRQ=
github.com/xlab/treeprint v1.2.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down Expand Up @@ -288,6 +287,8 @@ golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 h1:3MTrJm4PyNL9NBqvYDSj3DHl46qQakyfqfWo4jgfaEM=
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
Expand Down
Loading