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

refactor: remove util/slice and use standard slices library #13775

Merged
merged 1 commit into from
Oct 24, 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
7 changes: 4 additions & 3 deletions pkg/apis/workflow/v1alpha1/workflow_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"reflect"
"regexp"
"runtime"
"slices"
"sort"
"strings"
"time"
Expand All @@ -26,7 +27,6 @@ import (
log "github.com/sirupsen/logrus"

argoerrs "github.com/argoproj/argo-workflows/v3/errors"
"github.com/argoproj/argo-workflows/v3/util/slice"
)

// TemplateType is the type of a template
Expand Down Expand Up @@ -3786,7 +3786,7 @@ func (ss *SemaphoreStatus) LockAcquired(holderKey, lockKey string, currentHolder
if i < 0 {
ss.Holding = append(ss.Holding, SemaphoreHolding{Semaphore: lockKey, Holders: []string{holdingName}})
return true
} else if !slice.ContainsString(semaphoreHolding.Holders, holdingName) {
} else if !slices.Contains(semaphoreHolding.Holders, holdingName) {
semaphoreHolding.Holders = append(semaphoreHolding.Holders, holdingName)
ss.Holding[i] = semaphoreHolding
return true
Expand All @@ -3799,7 +3799,8 @@ func (ss *SemaphoreStatus) LockReleased(holderKey, lockKey string) bool {
holdingName := holderKey

if i >= 0 {
semaphoreHolding.Holders = slice.RemoveString(semaphoreHolding.Holders, holdingName)
semaphoreHolding.Holders = slices.DeleteFunc(semaphoreHolding.Holders,
func(x string) bool { return x == holdingName })
ss.Holding[i] = semaphoreHolding
return true
}
Expand Down
21 changes: 0 additions & 21 deletions util/slice/slice.go

This file was deleted.

69 changes: 0 additions & 69 deletions util/slice/slice_test.go

This file was deleted.

7 changes: 4 additions & 3 deletions workflow/controller/artifact_gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"hash/fnv"
"slices"
"sort"

"golang.org/x/exp/maps"
Expand All @@ -16,7 +17,6 @@ import (

"github.com/argoproj/argo-workflows/v3/pkg/apis/workflow"
wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
"github.com/argoproj/argo-workflows/v3/util/slice"
"github.com/argoproj/argo-workflows/v3/workflow/common"
"github.com/argoproj/argo-workflows/v3/workflow/controller/indexes"
"github.com/argoproj/argo-workflows/v3/workflow/util"
Expand All @@ -38,7 +38,7 @@ func (woc *wfOperationCtx) addArtifactGCFinalizer() {

// only do Artifact GC if we have a Finalizer for it (i.e. Artifact GC is configured for this Workflow
// and there's work left to do for it)
if !slice.ContainsString(woc.wf.Finalizers, common.FinalizerArtifactGC) {
if !slices.Contains(woc.wf.Finalizers, common.FinalizerArtifactGC) {
if woc.wf.Status.ArtifactGCStatus.NotSpecified {
return // we already verified it's not required for this workflow
}
Expand Down Expand Up @@ -549,7 +549,8 @@ func (woc *wfOperationCtx) processArtifactGCCompletion(ctx context.Context) erro
}
if removeFinalizer {
woc.log.Infof("no remaining artifacts to GC, removing artifact GC finalizer (forceFinalizerRemoval=%v)", forceFinalizerRemoval)
woc.wf.Finalizers = slice.RemoveString(woc.wf.Finalizers, common.FinalizerArtifactGC)
woc.wf.Finalizers = slices.DeleteFunc(woc.wf.Finalizers,
func(x string) bool { return x == common.FinalizerArtifactGC })
woc.updated = true
}
return nil
Expand Down
9 changes: 5 additions & 4 deletions workflow/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"os"
"slices"
"strconv"
gosync "sync"
"syscall"
Expand All @@ -15,7 +16,6 @@ import (
"github.com/argoproj/pkg/errors"
syncpkg "github.com/argoproj/pkg/sync"
log "github.com/sirupsen/logrus"
"golang.org/x/exp/slices"
"golang.org/x/time/rate"
apiv1 "k8s.io/api/core/v1"
apierr "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -53,7 +53,6 @@ import (
"github.com/argoproj/argo-workflows/v3/util/diff"
"github.com/argoproj/argo-workflows/v3/util/env"
errorsutil "github.com/argoproj/argo-workflows/v3/util/errors"
"github.com/argoproj/argo-workflows/v3/util/slice"
"github.com/argoproj/argo-workflows/v3/util/telemetry"
"github.com/argoproj/argo-workflows/v3/workflow/artifactrepositories"
"github.com/argoproj/argo-workflows/v3/workflow/common"
Expand Down Expand Up @@ -546,7 +545,9 @@ func (wfc *WorkflowController) getPodCleanupPatch(pod *apiv1.Pod, labelPodComple

finalizerEnabled := os.Getenv(common.EnvVarPodStatusCaptureFinalizer) == "true"
if finalizerEnabled && pod.Finalizers != nil {
finalizers := slice.RemoveString(pod.Finalizers, common.FinalizerPodStatus)
finalizers := slices.Clone(pod.Finalizers)
finalizers = slices.DeleteFunc(finalizers,
func(s string) bool { return s == common.FinalizerPodStatus })
if len(finalizers) != len(pod.Finalizers) {
un.SetFinalizers(finalizers)
un.SetResourceVersion(pod.ObjectMeta.ResourceVersion)
Expand Down Expand Up @@ -1108,7 +1109,7 @@ func (wfc *WorkflowController) addWorkflowInformerHandlers(ctx context.Context)
log.WithError(err).Error("Failed to list pods")
}
for _, p := range podList.Items {
if slice.ContainsString(p.Finalizers, common.FinalizerPodStatus) {
if slices.Contains(p.Finalizers, common.FinalizerPodStatus) {
wfc.queuePodForCleanup(p.Namespace, p.Name, removeFinalizer)
}
}
Expand Down
2 changes: 1 addition & 1 deletion workflow/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ spec:
assert.Empty(t, pods.Items)
}

func TestPodCleaupPatch(t *testing.T) {
func TestPodCleanupPatch(t *testing.T) {
wfc := &WorkflowController{}

pod := &apiv1.Pod{
Expand Down
5 changes: 3 additions & 2 deletions workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"reflect"
"regexp"
"runtime/debug"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -50,7 +51,6 @@ import (
"github.com/argoproj/argo-workflows/v3/util/retry"
argoruntime "github.com/argoproj/argo-workflows/v3/util/runtime"
"github.com/argoproj/argo-workflows/v3/util/secrets"
"github.com/argoproj/argo-workflows/v3/util/slice"
"github.com/argoproj/argo-workflows/v3/util/template"
waitutil "github.com/argoproj/argo-workflows/v3/util/wait"
"github.com/argoproj/argo-workflows/v3/workflow/common"
Expand Down Expand Up @@ -1769,7 +1769,8 @@ func (woc *wfOperationCtx) deletePVCs(ctx context.Context) error {
if err != nil {
return err
}
x.Finalizers = slice.RemoveString(x.Finalizers, "kubernetes.io/pvc-protection")
x.Finalizers = slices.DeleteFunc(x.Finalizers,
func(s string) bool { return s == "kubernetes.io/pvc-protection" })
_, err = pvcClient.Update(ctx, x, metav1.UpdateOptions{})
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions workflow/executor/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"os"
"path/filepath"
"slices"
"strings"
"syscall"
"time"
Expand All @@ -15,7 +16,6 @@ import (
v1 "k8s.io/api/core/v1"

envutil "github.com/argoproj/argo-workflows/v3/util/env"
"github.com/argoproj/argo-workflows/v3/util/slice"
)

const (
Expand Down Expand Up @@ -96,7 +96,7 @@ func TerminatePodWithContainerNames(ctx context.Context, c KubernetesClientInter
return err
}
for _, s := range containerStatuses {
if !slice.ContainsString(containerNames, s.Name) {
if !slices.Contains(containerNames, s.Name) {
continue
}
if s.State.Terminated != nil {
Expand Down
Loading