From 6b24fcb32cd16de6da02b0db84ce73448c2a32f2 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Mon, 16 Jun 2025 18:09:08 +0200 Subject: [PATCH] chore(lint): enable typeDefFirst rule from go-critic (#23414) Signed-off-by: Matthieu MOREL --- .golangci.yaml | 1 - .../controllers/clustereventhandler_test.go | 18 ++++++------- .../controller/controller.go | 16 ++++++------ reposerver/cache/cache.go | 26 +++++++++---------- 4 files changed, 30 insertions(+), 31 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 5fc1da8064..4a7204ad8b 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -69,7 +69,6 @@ linters: - rangeValCopy - sloppyReassign - tooManyResultsChecker - - typeDefFirst - unnamedResult - whyNoLint diff --git a/applicationset/controllers/clustereventhandler_test.go b/applicationset/controllers/clustereventhandler_test.go index 02b17551f6..b87bfc1a39 100644 --- a/applicationset/controllers/clustereventhandler_test.go +++ b/applicationset/controllers/clustereventhandler_test.go @@ -20,6 +20,15 @@ import ( argov1alpha1 "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1" ) +type mockAddRateLimitingInterface struct { + addedItems []reconcile.Request +} + +// Add checks the type, and adds it to the internal list of received additions +func (obj *mockAddRateLimitingInterface) Add(item reconcile.Request) { + obj.addedItems = append(obj.addedItems, item) +} + func TestClusterEventHandler(t *testing.T) { scheme := runtime.NewScheme() err := argov1alpha1.AddToScheme(scheme) @@ -556,15 +565,6 @@ func TestClusterEventHandler(t *testing.T) { } } -// Add checks the type, and adds it to the internal list of received additions -func (obj *mockAddRateLimitingInterface) Add(item reconcile.Request) { - obj.addedItems = append(obj.addedItems, item) -} - -type mockAddRateLimitingInterface struct { - addedItems []reconcile.Request -} - func TestNestedGeneratorHasClusterGenerator_NestedClusterGenerator(t *testing.T) { nested := argov1alpha1.ApplicationSetNestedGenerator{ Clusters: &argov1alpha1.ClusterGenerator{}, diff --git a/notification_controller/controller/controller.go b/notification_controller/controller/controller.go index 2402abe662..c985345f7f 100644 --- a/notification_controller/controller/controller.go +++ b/notification_controller/controller/controller.go @@ -54,6 +54,14 @@ type NotificationController interface { Init(ctx context.Context) error } +type notificationController struct { + ctrl controller.NotificationController + appInformer cache.SharedIndexInformer + appProjInformer cache.SharedIndexInformer + secretInformer cache.SharedIndexInformer + configMapInformer cache.SharedIndexInformer +} + func NewController( k8sClient kubernetes.Interface, client dynamic.Interface, @@ -171,14 +179,6 @@ func newInformer(resClient dynamic.ResourceInterface, controllerNamespace string return informer } -type notificationController struct { - ctrl controller.NotificationController - appInformer cache.SharedIndexInformer - appProjInformer cache.SharedIndexInformer - secretInformer cache.SharedIndexInformer - configMapInformer cache.SharedIndexInformer -} - func (c *notificationController) Init(ctx context.Context) error { // resolve certificates using injected "argocd-tls-certs-cm" ConfigMap httputil.SetCertResolver(argocert.GetCertificateForConnect) diff --git a/reposerver/cache/cache.go b/reposerver/cache/cache.go index 71a374210b..ec5d7faedb 100644 --- a/reposerver/cache/cache.go +++ b/reposerver/cache/cache.go @@ -43,6 +43,19 @@ type ClusterRuntimeInfo interface { GetKubeVersion() string } +// CachedManifestResponse represents a cached result of a previous manifest generation operation, including the caching +// of a manifest generation error, plus additional information on previous failures +type CachedManifestResponse struct { + // NOTE: When adding fields to this struct, you MUST also update shallowCopy() + + CacheEntryHash string `json:"cacheEntryHash"` + ManifestResponse *apiclient.ManifestResponse `json:"manifestResponse"` + MostRecentError string `json:"mostRecentError"` + FirstFailureTimestamp int64 `json:"firstFailureTimestamp"` + NumberOfConsecutiveFailures int `json:"numberOfConsecutiveFailures"` + NumberOfCachedResponsesReturned int `json:"numberOfCachedResponsesReturned"` +} + func NewCache(cache *cacheutil.Cache, repoCacheExpiration time.Duration, revisionCacheExpiration time.Duration, revisionCacheLockTimeout time.Duration) *Cache { return &Cache{cache, repoCacheExpiration, revisionCacheExpiration, revisionCacheLockTimeout} } @@ -535,16 +548,3 @@ func (cmr *CachedManifestResponse) generateCacheEntryHash() (string, error) { fnvHash := h.Sum(nil) return base64.URLEncoding.EncodeToString(fnvHash), nil } - -// CachedManifestResponse represents a cached result of a previous manifest generation operation, including the caching -// of a manifest generation error, plus additional information on previous failures -type CachedManifestResponse struct { - // NOTE: When adding fields to this struct, you MUST also update shallowCopy() - - CacheEntryHash string `json:"cacheEntryHash"` - ManifestResponse *apiclient.ManifestResponse `json:"manifestResponse"` - MostRecentError string `json:"mostRecentError"` - FirstFailureTimestamp int64 `json:"firstFailureTimestamp"` - NumberOfConsecutiveFailures int `json:"numberOfConsecutiveFailures"` - NumberOfCachedResponsesReturned int `json:"numberOfCachedResponsesReturned"` -}