mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-09 16:00:22 +00:00
util: use slices package for contains
use slices package to check whether the slice contains the element or not. Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
parent
86b5db90bc
commit
1e0254daba
@ -22,6 +22,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -145,7 +146,7 @@ func main() {
|
|||||||
failedTestFound := false
|
failedTestFound := false
|
||||||
for _, r := range statusList {
|
for _, r := range statusList {
|
||||||
log.Printf("found context %s with status %s\n", r.GetContext(), r.GetState())
|
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())
|
log.Printf("found failed test %s\n", r.GetContext())
|
||||||
failedTestFound = true
|
failedTestFound = true
|
||||||
// rebase the pr if it is behind the devel branch.
|
// rebase the pr if it is behind the devel branch.
|
||||||
@ -253,17 +254,6 @@ func (c *retestConfig) checkRetestLimitReached(prNumber int, msg string) (bool,
|
|||||||
return false, nil
|
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.
|
// filterStatusesList returns list of unique and recently updated github RepoStatuses.
|
||||||
// Raw github RepoStatus list may contain duplicate and older statuses.
|
// Raw github RepoStatus list may contain duplicate and older statuses.
|
||||||
func filterStatusList(rawStatusList []*github.RepoStatus) []*github.RepoStatus {
|
func filterStatusList(rawStatusList []*github.RepoStatus) []*github.RepoStatus {
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"slices"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
appsv1 "k8s.io/api/apps/v1"
|
appsv1 "k8s.io/api/apps/v1"
|
||||||
@ -349,17 +350,6 @@ func waitForDeploymentUpdate(
|
|||||||
return nil
|
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(
|
func waitForContainersArgsUpdate(
|
||||||
c kubernetes.Interface,
|
c kubernetes.Interface,
|
||||||
ns,
|
ns,
|
||||||
@ -398,7 +388,7 @@ func waitForContainersArgsUpdate(
|
|||||||
}
|
}
|
||||||
cid := deployment.Spec.Template.Spec.Containers // cid: read as containers in deployment
|
cid := deployment.Spec.Template.Spec.Containers // cid: read as containers in deployment
|
||||||
for i := range cid {
|
for i := range cid {
|
||||||
if contains(containers, cid[i].Name) {
|
if slices.Contains(containers, cid[i].Name) {
|
||||||
match := false
|
match := false
|
||||||
for j, ak := range cid[i].Args {
|
for j, ak := range cid[i].Args {
|
||||||
if ak == key {
|
if ak == key {
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -363,7 +364,7 @@ func MountOptionsAdd(options string, add ...string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, opt := range add {
|
for _, opt := range add {
|
||||||
if opt != "" && !contains(newOpts, opt) {
|
if opt != "" && !slices.Contains(newOpts, opt) {
|
||||||
newOpts = append(newOpts, opt)
|
newOpts = append(newOpts, opt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -371,16 +372,6 @@ func MountOptionsAdd(options string, add ...string) string {
|
|||||||
return strings.Join(newOpts, ",")
|
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
|
// CallStack returns the stack of the calls in the current goroutine. Useful
|
||||||
// for debugging or reporting errors. This is a friendly alternative to
|
// for debugging or reporting errors. This is a friendly alternative to
|
||||||
// assert() or panic().
|
// assert() or panic().
|
||||||
|
Loading…
Reference in New Issue
Block a user