Skip to content

Commit 4342235

Browse files
authored
move to samber lib intead of go-funk (#638)
Signed-off-by: David J. M. Karlsen <[email protected]>
1 parent d2104e6 commit 4342235

File tree

4 files changed

+22
-20
lines changed

4 files changed

+22
-20
lines changed

controllers/githubactionrunner_controller.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,17 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23+
"github.com/caitlinelfring/go-env-default"
2324
"strconv"
2425
"strings"
2526
"time"
2627

27-
env "github.com/caitlinelfring/go-env-default"
28-
2928
garov1alpha1 "github.com/evryfs/github-actions-runner-operator/api/v1alpha1"
3029
"github.com/evryfs/github-actions-runner-operator/controllers/githubapi"
3130
"github.com/go-logr/logr"
3231
"github.com/google/go-github/v58/github"
3332
"github.com/redhat-cop/operator-utils/pkg/util"
34-
"github.com/thoas/go-funk"
33+
"github.com/samber/lo"
3534
corev1 "k8s.io/api/core/v1"
3635
apierrors "k8s.io/apimachinery/pkg/api/errors"
3736
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -127,7 +126,8 @@ func (r *GithubActionRunnerReconciler) handleScaling(ctx context.Context, instan
127126

128127
if shouldScaleUp(podRunnerPairs, instance) {
129128
instance.Status.CurrentSize = podRunnerPairs.numPods()
130-
scale := funk.MaxInt([]int{instance.Spec.MinRunners - podRunnerPairs.numRunners(), 1})
129+
130+
scale := lo.Max([]int{instance.Spec.MinRunners - podRunnerPairs.numRunners(), 1})
131131
logger.Info("Scaling up", "numInstances", scale)
132132

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

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

339339
return podList, nil
340340
}
@@ -416,9 +416,9 @@ func (r *GithubActionRunnerReconciler) getPodRunnerPairs(ctx context.Context, cr
416416
}
417417

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

423423
if err != nil {
424424
return podRunnerPairList, err

controllers/podrunner_types.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/evryfs/github-actions-runner-operator/api/v1alpha1"
99
"github.com/google/go-github/v58/github"
1010
"github.com/redhat-cop/operator-utils/pkg/util"
11-
"github.com/thoas/go-funk"
11+
"github.com/samber/lo"
1212
corev1 "k8s.io/api/core/v1"
1313
)
1414

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

5252
func (r podRunnerPairList) getBusyRunners() []*github.Runner {
53-
return funk.Filter(r.runners, func(runner *github.Runner) bool {
53+
return lo.Filter(r.runners, func(runner *github.Runner, _ int) bool {
5454
return runner.GetBusy()
55-
}).([]*github.Runner)
55+
})
5656
}
5757

5858
func (r podRunnerPairList) numBusy() int {
@@ -80,9 +80,9 @@ func (r podRunnerPairList) numIdle() int {
8080
}
8181

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

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

9797
func (r podRunnerPairList) getPodsBeingDeletedOrEvictedOrCompleted() []podRunnerPair {
98-
return funk.Filter(r.pairs, func(pair podRunnerPair) bool {
98+
return lo.Filter(r.pairs, func(pair podRunnerPair, _ int) bool {
9999
return util.IsBeingDeleted(&pair.pod) || isEvicted(&pair.pod) || isCompleted(&pair.pod)
100-
}).([]podRunnerPair)
100+
})
101101
}

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ require (
1414
github.com/palantir/go-githubapp v0.22.0
1515
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475
1616
github.com/redhat-cop/operator-utils v1.3.8
17+
github.com/samber/lo v1.39.0
1718
github.com/stretchr/testify v1.8.4
18-
github.com/thoas/go-funk v0.9.3
1919
go.uber.org/zap v1.26.0
2020
k8s.io/api v0.29.1
2121
k8s.io/apimachinery v0.29.1
@@ -88,6 +88,7 @@ require (
8888
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
8989
go.uber.org/multierr v1.11.0 // indirect
9090
golang.org/x/crypto v0.18.0 // indirect
91+
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect
9192
golang.org/x/net v0.20.0 // indirect
9293
golang.org/x/oauth2 v0.16.0 // indirect
9394
golang.org/x/sync v0.2.0 // indirect

go.sum

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncj
230230
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
231231
github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A=
232232
github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
233+
github.com/samber/lo v1.39.0 h1:4gTz1wUhNYLhFSKl6O+8peW0v2F4BCY034GRpU9WnuA=
234+
github.com/samber/lo v1.39.0/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
233235
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
234236
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
235237
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
@@ -250,16 +252,13 @@ github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
250252
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
251253
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
252254
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
253-
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
254255
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
255256
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
256257
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
257258
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
258259
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
259260
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
260261
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
261-
github.com/thoas/go-funk v0.9.3 h1:7+nAEx3kn5ZJcnDm2Bh23N2yOtweO14bi//dvRtgLpw=
262-
github.com/thoas/go-funk v0.9.3/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q=
263262
github.com/xlab/treeprint v1.2.0 h1:HzHnuAF1plUN2zGlAFHbSQP2qJ0ZAD3XF5XD7OesXRQ=
264263
github.com/xlab/treeprint v1.2.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0=
265264
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
@@ -288,6 +287,8 @@ golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4
288287
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
289288
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
290289
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
290+
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 h1:3MTrJm4PyNL9NBqvYDSj3DHl46qQakyfqfWo4jgfaEM=
291+
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
291292
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
292293
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
293294
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=

0 commit comments

Comments
 (0)