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
2 changes: 1 addition & 1 deletion cmd/argo/commands/executorplugin/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func loadPluginManifest(pluginDir string) (*spec.Plugin, error) {
}

func addHeader(x []byte, h string) []byte {
return []byte(fmt.Sprintf("%s\n%s", h, string(x)))
return fmt.Appendf(nil, "%s\n%s", h, string(x))
}

func addCodegenHeader(x []byte) []byte {
Expand Down
5 changes: 3 additions & 2 deletions cmd/argoexec/commands/emissary_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
"os"
"testing"

cmdutil "github.com/argoproj/argo-workflows/v3/util/cmd"
"github.com/argoproj/argo-workflows/v3/util/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

cmdutil "github.com/argoproj/argo-workflows/v3/util/cmd"
"github.com/argoproj/argo-workflows/v3/util/errors"
)

func TestEmissary(t *testing.T) {
Expand Down
12 changes: 6 additions & 6 deletions hack/docs/configdoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,19 +274,19 @@ func createTypeLinkWithSpacing(baseType string) (string, bool) {
return fmt.Sprintf("[`%s`](#%s)", cleanBaseType, strings.ToLower(baseType)), true
}

if strings.HasPrefix(baseType, "wfv1.") {
wfType := strings.TrimPrefix(baseType, "wfv1.")
if after, ok := strings.CutPrefix(baseType, "wfv1."); ok {
wfType := after
return fmt.Sprintf("[`%s`](fields.md#%s)", wfType, strings.ToLower(wfType)), true
}

if strings.HasPrefix(baseType, "apiv1.") {
typeName := strings.TrimPrefix(baseType, "apiv1.")
if after, ok := strings.CutPrefix(baseType, "apiv1."); ok {
typeName := after
anchor := strings.ToLower(typeName)
return fmt.Sprintf("[`%s`](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.32/#%s-v1-core)", typeName, anchor), true
}

if strings.HasPrefix(baseType, "metav1.") {
typeName := strings.TrimPrefix(baseType, "metav1.")
if after, ok := strings.CutPrefix(baseType, "metav1."); ok {
typeName := after
anchor := strings.ToLower(typeName)
return fmt.Sprintf("[`%s`](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.32/#%s-v1-meta)", typeName, anchor), true
}
Expand Down
2 changes: 1 addition & 1 deletion hack/featuregen/contents.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func format(version string, features []feature) string {
output.WriteString(fmt.Sprintf("- %s by %s %s\n", feature.Description, feature.Author, issuesStr))

if feature.Details != "" {
for _, line := range strings.Split(feature.Details, "\n") {
for line := range strings.SplitSeq(feature.Details, "\n") {
if line != "" {
output.WriteString(fmt.Sprintf(" %s\n", line))
}
Expand Down
18 changes: 9 additions & 9 deletions server/utils/list_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ func BuildListOptions(options metav1.ListOptions, ns, namePrefix, nameFilter, cr
}
}
showRemainingItemCount := false
for _, selector := range strings.Split(options.FieldSelector, ",") {
for selector := range strings.SplitSeq(options.FieldSelector, ",") {
if len(selector) == 0 {
continue
}
if strings.HasPrefix(selector, "metadata.namespace=") {
if after, ok := strings.CutPrefix(selector, "metadata.namespace="); ok {
// for backward compatibility, the field selector 'metadata.namespace' is supported for now despite the addition
// of the new 'namespace' query parameter, which is what the UI uses
fieldSelectedNamespace := strings.TrimPrefix(selector, "metadata.namespace=")
fieldSelectedNamespace := after
switch namespace {
case "":
namespace = fieldSelectedNamespace
Expand All @@ -109,16 +109,16 @@ func BuildListOptions(options metav1.ListOptions, ns, namePrefix, nameFilter, cr
return ListOptions{}, status.Errorf(codes.InvalidArgument,
"'namespace' query param (%q) and fieldselector 'metadata.namespace' (%q) are both specified and contradict each other", namespace, fieldSelectedNamespace)
}
} else if strings.HasPrefix(selector, "metadata.name=") {
name = strings.TrimPrefix(selector, "metadata.name=")
} else if strings.HasPrefix(selector, "spec.startedAt>") {
minStartedAt, err = time.Parse(time.RFC3339, strings.TrimPrefix(selector, "spec.startedAt>"))
} else if after, ok := strings.CutPrefix(selector, "metadata.name="); ok {
name = after
} else if after, ok := strings.CutPrefix(selector, "spec.startedAt>"); ok {
minStartedAt, err = time.Parse(time.RFC3339, after)
if err != nil {
// startedAt is populated by us, it should therefore be valid.
return ListOptions{}, ToStatusError(err, codes.Internal)
}
} else if strings.HasPrefix(selector, "spec.startedAt<") {
maxStartedAt, err = time.Parse(time.RFC3339, strings.TrimPrefix(selector, "spec.startedAt<"))
} else if after, ok := strings.CutPrefix(selector, "spec.startedAt<"); ok {
maxStartedAt, err = time.Parse(time.RFC3339, after)
if err != nil {
// no need to use sutils here
return ListOptions{}, ToStatusError(err, codes.Internal)
Expand Down
5 changes: 1 addition & 4 deletions server/workflow/workflow_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,7 @@ func (s *workflowServer) ListWorkflows(ctx context.Context, req *workflowpkg.Wor
var remainCount int64
if options.ShowRemainingItemCount {
// Calculate exact remaining count when requested
remainCount = totalCount - int64(options.Offset) - int64(len(wfs))
if remainCount < 0 {
remainCount = 0
}
remainCount = max(totalCount-int64(options.Offset)-int64(len(wfs)), 0)
meta.RemainingItemCount = &remainCount
} else {
// For pagination without remaining count, use the efficient HasMoreWorkflows method
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/fixtures/given.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ func (g *Given) WorkflowWorkflow(wf *wfv1.Workflow) *Given {
func (g *Given) readResource(text string, v metav1.Object) {
g.t.Helper()
var file string
if strings.HasPrefix(text, "@") {
file = strings.TrimPrefix(text, "@")
if after, ok := strings.CutPrefix(text, "@"); ok {
file = after
} else {
f, err := os.CreateTemp("", "argo_e2e")
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/fixtures/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ func (mb *MetricBaseline) ExpectIncrease() {
func parseMetricValue(body, metricPattern string) float64 {
// Escape special regex characters in the metric pattern, but keep the spaces
// We'll look for lines that match the pattern and extract the value
lines := strings.Split(body, "\n")
lines := strings.SplitSeq(body, "\n")

for _, line := range lines {
for line := range lines {
line = strings.TrimSpace(line)
if line == "" || strings.HasPrefix(line, "#") {
continue
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/fixtures/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func Exec(name string, args ...string) (string, error) {
if err != nil {
errorln(err)
}
for _, s := range strings.Split(output, "\n") {
for s := range strings.SplitSeq(output, "\n") {
_, _ = fmt.Println(s)
}
return output, err
Expand Down Expand Up @@ -56,8 +56,8 @@ func runWithTimeout(cmd *exec.Cmd) (string, error) {
// LoadObject is used to load yaml to runtime.Object
func LoadObject(text string) (runtime.Object, error) {
var yaml string
if strings.HasPrefix(text, "@") {
file := strings.TrimPrefix(text, "@")
if after, ok := strings.CutPrefix(text, "@"); ok {
file := after
f, err := os.ReadFile(filepath.Clean(file))
if err != nil {
return nil, err
Expand Down
9 changes: 3 additions & 6 deletions test/e2e/fixtures/when.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"maps"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -601,9 +602,7 @@ func (w *When) CreateConfigMap(name string, data map[string]string, customLabels

labels := map[string]string{Label: "true"}

for k, v := range customLabels {
labels[k] = v
}
maps.Copy(labels, customLabels)

ctx := logging.TestContext(w.t.Context())
_, err := w.kubeClient.CoreV1().ConfigMaps(Namespace).Create(ctx, &corev1.ConfigMap{
Expand All @@ -621,9 +620,7 @@ func (w *When) UpdateConfigMap(name string, data map[string]string, customLabels

labels := map[string]string{Label: "true"}

for k, v := range customLabels {
labels[k] = v
}
maps.Copy(labels, customLabels)

ctx := logging.TestContext(w.t.Context())
_, err := w.kubeClient.CoreV1().ConfigMaps(Namespace).Update(ctx, &corev1.ConfigMap{
Expand Down
2 changes: 1 addition & 1 deletion util/fields/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func NewCleaner(x string) Cleaner {
x = x[1:]
y.exclude = true
}
for _, field := range strings.Split(x, ",") {
for field := range strings.SplitSeq(x, ",") {
y.fields[field] = true
}
}
Expand Down
13 changes: 4 additions & 9 deletions util/logging/slog.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"log/slog"
"maps"
"os"
)

Expand Down Expand Up @@ -80,13 +81,9 @@ func (s *slogLogger) Level() Level {
func (s *slogLogger) WithFields(fields Fields) Logger {
newFields := make(Fields)

for k, v := range s.fields {
newFields[k] = v
}
maps.Copy(newFields, s.fields)

for k, v := range fields {
newFields[k] = v
}
maps.Copy(newFields, fields)

return &slogLogger{
fields: newFields,
Expand All @@ -101,9 +98,7 @@ func (s *slogLogger) WithFields(fields Fields) Logger {
func (s *slogLogger) WithField(name string, value any) Logger {
newFields := make(Fields)

for k, v := range s.fields {
newFields[k] = v
}
maps.Copy(newFields, s.fields)

newFields[name] = value

Expand Down
10 changes: 4 additions & 6 deletions util/resource/duration.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package resource

import (
"maps"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"

Expand All @@ -18,12 +20,8 @@ func DurationForPod(pod *corev1.Pod) wfv1.ResourcesDuration {
corev1.ResourceMemory: resource.MustParse("100Mi"),
}}
// Update with user-configured resources (falls back to limits as == requests, same as Kubernetes).
for name, quantity := range c.Resources.Limits {
summaries[c.Name].ResourceList[name] = quantity
}
for name, quantity := range c.Resources.Requests {
summaries[c.Name].ResourceList[name] = quantity
}
maps.Copy(summaries[c.Name].ResourceList, c.Resources.Limits)
maps.Copy(summaries[c.Name].ResourceList, c.Resources.Requests)
}
for _, c := range append(pod.Status.InitContainerStatuses, pod.Status.ContainerStatuses...) {
summaries[c.Name] = Summary{ResourceList: summaries[c.Name].ResourceList, ContainerState: c.State}
Expand Down
2 changes: 1 addition & 1 deletion util/telemetry/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func upperToSnake(in string) string {
in = string(append([]rune{unicode.ToLower(runes[0])}, runes[1:]...))
re := regexp.MustCompile(`[A-Z]`)
return string(re.ReplaceAllFunc([]byte(in), func(in []byte) []byte {
return []byte(fmt.Sprintf("_%s", strings.ToLower(string(in[0]))))
return fmt.Appendf(nil, "_%s", strings.ToLower(string(in[0])))
}))
}

Expand Down
2 changes: 1 addition & 1 deletion util/template/expression_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func expressionReplace(ctx context.Context, w io.Writer, expression string, env
log := logging.RequireLoggerFromContext(ctx)
// The template is JSON-marshaled. This JSON-unmarshals the expression to undo any character escapes.
var unmarshalledExpression string
err := json.Unmarshal([]byte(fmt.Sprintf(`"%s"`, expression)), &unmarshalledExpression)
err := json.Unmarshal(fmt.Appendf(nil, `"%s"`, expression), &unmarshalledExpression)
if err != nil && allowUnresolved {
log.WithError(err).Debug(ctx, "unresolved is allowed ")
return fmt.Fprintf(w, "{{%s%s}}", kindExpression, expression)
Expand Down
4 changes: 2 additions & 2 deletions util/template/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ func registerKind(k kind) {

func parseTag(tag string) (kind, string) {
for _, k := range kinds {
if strings.HasPrefix(tag, k) {
return k, jsonutil.Fix(strings.TrimPrefix(tag, k))
if after, ok := strings.CutPrefix(tag, k); ok {
return k, jsonutil.Fix(after)
}
}
return kindSimple, tag
Expand Down
9 changes: 3 additions & 6 deletions workflow/common/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package common

import (
"context"
"maps"
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -94,14 +95,10 @@ func toWorkflow(cronWf wfv1.CronWorkflow, objectMeta metav1.ObjectMeta) *wfv1.Wo

wf.Labels[LabelKeyCronWorkflow] = cronWf.Name
if cronWf.Spec.WorkflowMetadata != nil {
for key, label := range cronWf.Spec.WorkflowMetadata.Labels {
wf.Labels[key] = label
}
maps.Copy(wf.Labels, cronWf.Spec.WorkflowMetadata.Labels)

if len(cronWf.Spec.WorkflowMetadata.Annotations) > 0 {
for key, annotation := range cronWf.Spec.WorkflowMetadata.Annotations {
wf.Annotations[key] = annotation
}
maps.Copy(wf.Annotations, cronWf.Spec.WorkflowMetadata.Annotations)
}

wf.Finalizers = append(wf.Finalizers, cronWf.Spec.WorkflowMetadata.Finalizers...)
Expand Down
10 changes: 4 additions & 6 deletions workflow/common/params.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
package common

import "maps"

// Parameters extends string map with useful methods.
type Parameters map[string]string

// Merge merges given parameters.
func (ps Parameters) Merge(args ...Parameters) Parameters {
newParams := ps.DeepCopy()
for _, params := range args {
for k, v := range params {
newParams[k] = v
}
maps.Copy(newParams, params)
}
return newParams
}

// DeepCopy returns a new instance which has the same parameters as the receiver.
func (ps Parameters) DeepCopy() Parameters {
newParams := make(Parameters)
for k, v := range ps {
newParams[k] = v
}
maps.Copy(newParams, ps)
return newParams
}
16 changes: 4 additions & 12 deletions workflow/controller/artifact_gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,12 +538,8 @@ func (woc *wfOperationCtx) createArtifactGCPod(ctx context.Context, strategy wfv
if podInfo.serviceAccount != "" {
pod.Spec.ServiceAccountName = podInfo.serviceAccount
}
for label, labelVal := range podInfo.podMetadata.Labels {
pod.Labels[label] = labelVal
}
for annotation, annotationVal := range podInfo.podMetadata.Annotations {
pod.Annotations[annotation] = annotationVal
}
maps.Copy(pod.Labels, podInfo.podMetadata.Labels)
maps.Copy(pod.Annotations, podInfo.podMetadata.Annotations)

if v := woc.controller.Config.InstanceID; v != "" {
pod.Labels[common.EnvVarInstanceID] = v
Expand Down Expand Up @@ -771,15 +767,11 @@ func (woc *wfOperationCtx) updateArtifactGCPodInfo(artifactGC *wfv1.ArtifactGC,
if len(artifactGC.PodMetadata.Labels) > 0 && podInfo.podMetadata.Labels == nil {
podInfo.podMetadata.Labels = make(map[string]string)
}
for labelKey, labelValue := range artifactGC.PodMetadata.Labels {
podInfo.podMetadata.Labels[labelKey] = labelValue
}
maps.Copy(podInfo.podMetadata.Labels, artifactGC.PodMetadata.Labels)
if len(artifactGC.PodMetadata.Annotations) > 0 && podInfo.podMetadata.Annotations == nil {
podInfo.podMetadata.Annotations = make(map[string]string)
}
for annotationKey, annotationValue := range artifactGC.PodMetadata.Annotations {
podInfo.podMetadata.Annotations[annotationKey] = annotationValue
}
maps.Copy(podInfo.podMetadata.Annotations, artifactGC.PodMetadata.Annotations)
}

}
5 changes: 2 additions & 3 deletions workflow/controller/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"maps"

"github.com/expr-lang/expr"

Expand Down Expand Up @@ -61,9 +62,7 @@ func (s *wfScope) addArtifactToScope(key string, artifact wfv1.Artifact) {
// resolveVar resolves a parameter or artifact
func (s *wfScope) resolveVar(v string) (interface{}, error) {
m := make(map[string]interface{})
for k, v := range s.scope {
m[k] = v
}
maps.Copy(m, s.scope)
if s.tmpl != nil {
for _, a := range s.tmpl.Inputs.Artifacts {
m["inputs.artifacts."+a.Name] = a // special case for artifacts
Expand Down
Loading
Loading