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

util: use slices package for contains #4532

Merged
merged 2 commits into from
Apr 2, 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 actions/retest/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG WORK_DIR="/home/src"
ARG BASE_IMAGE="golang:1.18"
ARG BASE_IMAGE="golang:1.21"

FROM ${BASE_IMAGE} as builder

Expand Down
14 changes: 2 additions & 12 deletions actions/retest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"log"
"os"
"slices"
"strconv"
"strings"

Expand Down Expand Up @@ -145,7 +146,7 @@ func main() {
failedTestFound := false
for _, r := range statusList {
log.Printf("found context %s with status %s\n", r.GetContext(), r.GetState())
if contains([]string{"failed", "failure"}, r.GetState()) {
if slices.Contains([]string{"failed", "failure"}, r.GetState()) {
log.Printf("found failed test %s\n", r.GetContext())
failedTestFound = true
// rebase the pr if it is behind the devel branch.
Expand Down Expand Up @@ -253,17 +254,6 @@ func (c *retestConfig) checkRetestLimitReached(prNumber int, msg string) (bool,
return false, nil
}

// containers check if slice contains string.
func contains(s []string, e string) bool {
for _, a := range s {
if a == e {
return true
}
}

return false
}

// filterStatusesList returns list of unique and recently updated github RepoStatuses.
// Raw github RepoStatus list may contain duplicate and older statuses.
func filterStatusList(rawStatusList []*github.RepoStatus) []*github.RepoStatus {
Expand Down
14 changes: 2 additions & 12 deletions e2e/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"os"
"slices"
"time"

appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -349,17 +350,6 @@ func waitForDeploymentUpdate(
return nil
}

// contains check if slice contains string.
func contains(s []string, e string) bool {
for _, a := range s {
if a == e {
return true
}
}

return false
}

func waitForContainersArgsUpdate(
c kubernetes.Interface,
ns,
Expand Down Expand Up @@ -398,7 +388,7 @@ func waitForContainersArgsUpdate(
}
cid := deployment.Spec.Template.Spec.Containers // cid: read as containers in deployment
for i := range cid {
if contains(containers, cid[i].Name) {
if slices.Contains(containers, cid[i].Name) {
match := false
for j, ak := range cid[i].Args {
if ak == key {
Expand Down
13 changes: 2 additions & 11 deletions internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"math"
"os"
"runtime"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -363,24 +364,14 @@ func MountOptionsAdd(options string, add ...string) string {
}

for _, opt := range add {
if opt != "" && !contains(newOpts, opt) {
if opt != "" && !slices.Contains(newOpts, opt) {
newOpts = append(newOpts, opt)
}
}

return strings.Join(newOpts, ",")
}

func contains(s []string, key string) bool {
for _, v := range s {
if v == key {
return true
}
}

return false
}

// CallStack returns the stack of the calls in the current goroutine. Useful
// for debugging or reporting errors. This is a friendly alternative to
// assert() or panic().
Expand Down