77 "os"
88 "strconv"
99 "strings"
10- "sync/atomic"
1110 "time"
1211
1312 "k8s.io/apimachinery/pkg/util/strategicpatch"
@@ -29,6 +28,7 @@ import (
2928 "k8s.io/kubectl/pkg/util/openapi"
3029
3130 "github.com/argoproj/argo-cd/v3/controller/metrics"
31+ "github.com/argoproj/argo-cd/v3/controller/syncid"
3232 "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
3333 listersv1alpha1 "github.com/argoproj/argo-cd/v3/pkg/client/listers/application/v1alpha1"
3434 applog "github.com/argoproj/argo-cd/v3/util/app/log"
@@ -38,11 +38,8 @@ import (
3838 kubeutil "github.com/argoproj/argo-cd/v3/util/kube"
3939 logutils "github.com/argoproj/argo-cd/v3/util/log"
4040 "github.com/argoproj/argo-cd/v3/util/lua"
41- "github.com/argoproj/argo-cd/v3/util/rand"
4241)
4342
44- var syncIdPrefix uint64
45-
4643const (
4744 // EnvVarSyncWaveDelay is an environment variable which controls the delay in seconds between
4845 // each sync-wave
@@ -96,6 +93,7 @@ func (m *appStateManager) SyncAppState(app *v1alpha1.Application, state *v1alpha
9693 // concrete git commit SHA, the SHA is remembered in the status.operationState.syncResult field.
9794 // This ensures that when resuming an operation, we sync to the same revision that we initially
9895 // started with.
96+
9997 var revision string
10098 var syncOp v1alpha1.SyncOperation
10199 var syncRes * v1alpha1.SyncOperationResult
@@ -248,15 +246,12 @@ func (m *appStateManager) SyncAppState(app *v1alpha1.Application, state *v1alpha
248246 return
249247 }
250248
251- atomic .AddUint64 (& syncIdPrefix , 1 )
252- randSuffix , err := rand .String (5 )
249+ syncId , err := syncid .Generate ()
253250 if err != nil {
254251 state .Phase = common .OperationError
255- state .Message = fmt .Sprintf ("Failed generate random sync ID: %v" , err )
252+ state .Message = fmt .Sprintf ("Failed to generate sync ID: %v" , err )
256253 return
257254 }
258- syncId := fmt .Sprintf ("%05d-%s" , syncIdPrefix , randSuffix )
259-
260255 logEntry := log .WithFields (applog .GetAppLogFields (app )).WithField ("syncId" , syncId )
261256 initialResourcesRes := make ([]common.ResourceSyncResult , len (syncRes .Resources ))
262257 for i , res := range syncRes .Resources {
0 commit comments