Skip to content
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
7 changes: 3 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"math"
"net/url"
"slices"
"time"

metricsdk "go.opentelemetry.io/otel/sdk/metric"
Expand Down Expand Up @@ -146,10 +147,8 @@ func (c Config) GetPodGCDeleteDelayDuration() time.Duration {
}

func (c Config) ValidateProtocol(inputProtocol string, allowedProtocol []string) error {
for _, protocol := range allowedProtocol {
if inputProtocol == protocol {
return nil
}
if slices.Contains(allowedProtocol, inputProtocol) {
return nil
}
return fmt.Errorf("protocol %s is not allowed", inputProtocol)
}
Expand Down
14 changes: 2 additions & 12 deletions examples/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,13 @@ import (
"fmt"
"os"
"path/filepath"
"slices"
"strings"

"github.com/xeipuuv/gojsonschema"
"sigs.k8s.io/yaml"
)

// https://stackoverflow.com/questions/10485743/contains-method-for-a-slice
func contains(s []string, e string) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}

func ValidateArgoYamlRecursively(fromPath string, skipFileNames []string) (map[string][]string, error) {
schemaBytes, err := os.ReadFile("../api/jsonschema/schema.json")
if err != nil {
Expand All @@ -34,8 +25,7 @@ func ValidateArgoYamlRecursively(fromPath string, skipFileNames []string) (map[s
if err != nil {
return err
}
if contains(skipFileNames, info.Name()) {
// fmt.Printf("skipping %+v \n", info.Name())
if slices.Contains(skipFileNames, info.Name()) {
return filepath.SkipDir
}
if info.IsDir() {
Expand Down
8 changes: 2 additions & 6 deletions hack/featuregen/components.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"slices"
"strings"
)

Expand All @@ -17,12 +18,7 @@ var validComponents = []string{
}

func isValidComponent(component string) bool {
for _, c := range validComponents {
if c == component {
return true
}
}
return false
return slices.Contains(validComponents, component)
}

func listValidComponents() string {
Expand Down
14 changes: 2 additions & 12 deletions pkg/apis/workflow/v1alpha1/workflow_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2607,12 +2607,7 @@ func (n NodeStatus) GetDuration() time.Duration {
}

func (n NodeStatus) HasChild(childID string) bool {
for _, nodeID := range n.Children {
if childID == nodeID {
return true
}
}
return false
return slices.Contains(n.Children, childID)
}

// S3Bucket contains the access information required for interfacing with an S3 bucket
Expand Down Expand Up @@ -3215,12 +3210,7 @@ func (tmpl *Template) IsLeaf() bool {
}

func (tmpl *Template) IsMainContainerName(containerName string) bool {
for _, c := range tmpl.GetMainContainerNames() {
if c == containerName {
return true
}
}
return false
return slices.Contains(tmpl.GetMainContainerNames(), containerName)
}

func (tmpl *Template) GetMainContainerNames() []string {
Expand Down
7 changes: 3 additions & 4 deletions workflow/artifacts/oss/oss.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"math"
"os"
"path/filepath"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -404,10 +405,8 @@ func isTransientOSSErr(ctx context.Context, err error) bool {
return true
}
if ossErr, ok := err.(oss.ServiceError); ok {
for _, transientErrCode := range ossTransientErrorCodes {
if ossErr.Code == transientErrCode {
return true
}
if slices.Contains(ossTransientErrorCodes, ossErr.Code) {
return true
}
}
return false
Expand Down
8 changes: 3 additions & 5 deletions workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3583,11 +3583,9 @@ func (woc *wfOperationCtx) addChildNode(ctx context.Context, parent string, chil
if err != nil {
woc.log.WithPanic().WithField("nodeID", parentID).Error(ctx, "was unable to obtain node for nodeID")
}
for _, nodeID := range node.Children {
if childID == nodeID {
// already exists
return
}
if slices.Contains(node.Children, childID) {
// already exists
return
}
node.Children = append(node.Children, childID)
woc.wf.Status.Nodes.Set(ctx, parentID, *node)
Expand Down
7 changes: 3 additions & 4 deletions workflow/controller/workflowpod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"path"
"path/filepath"
"slices"
"strconv"
"testing"
"time"
Expand Down Expand Up @@ -812,10 +813,8 @@ func TestOutOfCluster(t *testing.T) {
verifyKubeConfigVolume := func(ctr apiv1.Container, volName, mountPath string) {
for _, vol := range ctr.VolumeMounts {
if vol.Name == volName && vol.MountPath == mountPath {
for _, arg := range ctr.Args {
if arg == fmt.Sprintf("--kubeconfig=%s", mountPath) {
return
}
if slices.Contains(ctr.Args, fmt.Sprintf("--kubeconfig=%s", mountPath)) {
return
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions workflow/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"reflect"
"regexp"
"slices"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -914,14 +915,7 @@ func validateArgumentsValues(prefix string, arguments wfv1.Arguments, allowEmpty
}
return errors.Errorf(errors.CodeBadRequest, "%s%s.value is required", prefix, param.Name)
}
valueSpecifiedInEnumList := false
for _, enum := range param.Enum {
if enum == *param.Value {
valueSpecifiedInEnumList = true
break
}
}
if !valueSpecifiedInEnumList {
if !slices.Contains(param.Enum, *param.Value) {
return errors.Errorf(errors.CodeBadRequest, "%s%s.value should be present in %s%s.enum list", prefix, param.Name, prefix, param.Name)
}
}
Expand Down
Loading