Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ linters:
disable:
- go-require

unused:
field-writes-are-uses: false
exported-fields-are-used: false

usetesting:
os-mkdir-temp: false

Expand Down
16 changes: 5 additions & 11 deletions applicationset/generators/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (

log "github.com/sirupsen/logrus"

"github.com/argoproj/argo-cd/v3/util/settings"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
Expand All @@ -27,21 +25,17 @@ type ClusterGenerator struct {
ctx context.Context
clientset kubernetes.Interface
// namespace is the Argo CD namespace
namespace string
settingsManager *settings.SettingsManager
namespace string
}

var render = &utils.Render{}

func NewClusterGenerator(ctx context.Context, c client.Client, clientset kubernetes.Interface, namespace string) Generator {
settingsManager := settings.NewSettingsManager(ctx, clientset, namespace)

g := &ClusterGenerator{
Client: c,
ctx: ctx,
clientset: clientset,
namespace: namespace,
settingsManager: settingsManager,
Client: c,
ctx: ctx,
clientset: clientset,
namespace: namespace,
}
return g
}
Expand Down
22 changes: 8 additions & 14 deletions applicationset/generators/duck_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
log "github.com/sirupsen/logrus"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/argoproj/argo-cd/v3/util/settings"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand All @@ -26,22 +24,18 @@ var _ Generator = (*DuckTypeGenerator)(nil)

// DuckTypeGenerator generates Applications for some or all clusters registered with ArgoCD.
type DuckTypeGenerator struct {
ctx context.Context
dynClient dynamic.Interface
clientset kubernetes.Interface
namespace string // namespace is the Argo CD namespace
settingsManager *settings.SettingsManager
ctx context.Context
dynClient dynamic.Interface
clientset kubernetes.Interface
namespace string // namespace is the Argo CD namespace
}

func NewDuckTypeGenerator(ctx context.Context, dynClient dynamic.Interface, clientset kubernetes.Interface, namespace string) Generator {
settingsManager := settings.NewSettingsManager(ctx, clientset, namespace)

g := &DuckTypeGenerator{
ctx: ctx,
dynClient: dynClient,
clientset: clientset,
namespace: namespace,
settingsManager: settingsManager,
ctx: ctx,
dynClient: dynClient,
clientset: clientset,
namespace: namespace,
}
return g
}
Expand Down
7 changes: 1 addition & 6 deletions applicationset/generators/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/jeremywohl/flatten"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"
"sigs.k8s.io/controller-runtime/pkg/client"

argoprojiov1alpha1 "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
Expand All @@ -27,16 +26,12 @@ var _ Generator = (*PluginGenerator)(nil)

type PluginGenerator struct {
client client.Client
ctx context.Context
clientset kubernetes.Interface
namespace string
}

func NewPluginGenerator(ctx context.Context, client client.Client, clientset kubernetes.Interface, namespace string) Generator {
func NewPluginGenerator(client client.Client, namespace string) Generator {
g := &PluginGenerator{
client: client,
ctx: ctx,
clientset: clientset,
namespace: namespace,
}
return g
Expand Down
8 changes: 1 addition & 7 deletions applicationset/generators/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
corev1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
kubefake "k8s.io/client-go/kubernetes/fake"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"

Expand Down Expand Up @@ -628,8 +626,6 @@ func TestPluginGenerateParams(t *testing.T) {
},
}

ctx := t.Context()

for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
generatorConfig := argoprojiov1alpha1.ApplicationSetGenerator{
Expand Down Expand Up @@ -666,11 +662,9 @@ func TestPluginGenerateParams(t *testing.T) {
testCase.configmap.Data["baseUrl"] = fakeServer.URL
}

fakeClient := kubefake.NewSimpleClientset(append([]runtime.Object{}, testCase.configmap, testCase.secret)...)

fakeClientWithCache := fake.NewClientBuilder().WithObjects([]client.Object{testCase.configmap, testCase.secret}...).Build()

pluginGenerator := NewPluginGenerator(ctx, fakeClientWithCache, fakeClient, "default")
pluginGenerator := NewPluginGenerator(fakeClientWithCache, "default")

applicationSetInfo := argoprojiov1alpha1.ApplicationSet{
ObjectMeta: metav1.ObjectMeta{
Expand Down
2 changes: 1 addition & 1 deletion applicationset/generators/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func GetGenerators(ctx context.Context, c client.Client, k8sClient kubernetes.In
"SCMProvider": NewSCMProviderGenerator(c, scmConfig),
"ClusterDecisionResource": NewDuckTypeGenerator(ctx, dynamicClient, k8sClient, namespace),
"PullRequest": NewPullRequestGenerator(c, scmConfig),
"Plugin": NewPluginGenerator(ctx, c, k8sClient, namespace),
"Plugin": NewPluginGenerator(c, namespace),
}

nestedGenerators := map[string]Generator{
Expand Down
3 changes: 1 addition & 2 deletions applicationset/services/scm_provider/azure_devops.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func (factory *devopsFactoryImpl) GetClient(ctx context.Context) (azureGit.Clien
type AzureDevOpsProvider struct {
organization string
teamProject string
accessToken string
clientFactory AzureDevOpsClientFactory
allBranches bool
}
Expand All @@ -69,7 +68,7 @@ func NewAzureDevOpsProvider(accessToken string, org string, url string, project

connection := azuredevops.NewPatConnection(devOpsURL, accessToken)

return &AzureDevOpsProvider{organization: org, teamProject: project, accessToken: accessToken, clientFactory: &devopsFactoryImpl{connection: connection}, allBranches: allBranches}, nil
return &AzureDevOpsProvider{organization: org, teamProject: project, clientFactory: &devopsFactoryImpl{connection: connection}, allBranches: allBranches}, nil
}

func (g *AzureDevOpsProvider) ListRepos(ctx context.Context, _ string) ([]*Repository, error) {
Expand Down
4 changes: 1 addition & 3 deletions applicationset/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const payloadQueueSize = 50000

type WebhookHandler struct {
sync.WaitGroup // for testing
namespace string
github *github.Webhook
gitlab *gitlab.Webhook
azuredevops *azuredevops.Webhook
Expand Down Expand Up @@ -69,7 +68,7 @@ type prGeneratorGitlabInfo struct {
APIHostname string
}

func NewWebhookHandler(namespace string, webhookParallelism int, argocdSettingsMgr *argosettings.SettingsManager, client client.Client, generators map[string]generators.Generator) (*WebhookHandler, error) {
func NewWebhookHandler(webhookParallelism int, argocdSettingsMgr *argosettings.SettingsManager, client client.Client, generators map[string]generators.Generator) (*WebhookHandler, error) {
// register the webhook secrets stored under "argocd-secret" for verifying incoming payloads
argocdSettings, err := argocdSettingsMgr.GetSettings()
if err != nil {
Expand All @@ -89,7 +88,6 @@ func NewWebhookHandler(namespace string, webhookParallelism int, argocdSettingsM
}

webhookHandler := &WebhookHandler{
namespace: namespace,
github: githubHandler,
gitlab: gitlabHandler,
azuredevops: azuredevopsHandler,
Expand Down
2 changes: 1 addition & 1 deletion applicationset/webhook/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func TestWebhookHandler(t *testing.T) {
fakeAppWithMergeAndNestedGitGenerator("merge-nested-git-github", namespace, "https://github.com/org/repo"),
).Build()
set := argosettings.NewSettingsManager(t.Context(), fakeClient, namespace)
h, err := NewWebhookHandler(namespace, webhookParallelism, set, fc, mockGenerators())
h, err := NewWebhookHandler(webhookParallelism, set, fc, mockGenerators())
require.NoError(t, err)

req := httptest.NewRequest(http.MethodPost, "/api/webhook", nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func NewCommand() *cobra.Command {
topLevelGenerators := generators.GetGenerators(ctx, mgr.GetClient(), k8sClient, namespace, argoCDService, dynamicClient, scmConfig)

// start a webhook server that listens to incoming webhook payloads
webhookHandler, err := webhook.NewWebhookHandler(namespace, webhookParallelism, argoSettingsMgr, mgr.GetClient(), topLevelGenerators)
webhookHandler, err := webhook.NewWebhookHandler(webhookParallelism, argoSettingsMgr, mgr.GetClient(), topLevelGenerators)
if err != nil {
log.Error(err, "failed to create webhook handler")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/argocd/commands/admin/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,5 +479,5 @@ func reconcileApplications(
}

func newLiveStateCache(argoDB db.ArgoDB, appInformer kubecache.SharedIndexInformer, settingsMgr *settings.SettingsManager, server *metrics.MetricsServer) cache.LiveStateCache {
return cache.NewLiveStateCache(argoDB, appInformer, settingsMgr, kubeutil.NewKubectl(), server, func(_ map[string]bool, _ corev1.ObjectReference) {}, &sharding.ClusterSharding{}, argo.NewResourceTracking())
return cache.NewLiveStateCache(argoDB, appInformer, settingsMgr, server, func(_ map[string]bool, _ corev1.ObjectReference) {}, &sharding.ClusterSharding{}, argo.NewResourceTracking())
}
16 changes: 7 additions & 9 deletions cmd/argocd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,6 @@ func NewApplicationDiffCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co

diffOption.res = res
diffOption.revisions = revisions
diffOption.sourcePositions = sourcePositions
case revision != "":
q := application.ApplicationManifestQuery{
Name: &appName,
Expand Down Expand Up @@ -1423,14 +1422,13 @@ func NewApplicationDiffCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co

// DifferenceOption struct to store diff options
type DifferenceOption struct {
local string
localRepoRoot string
revision string
cluster *argoappv1.Cluster
res *repoapiclient.ManifestResponse
serversideRes *repoapiclient.ManifestResponse
revisions []string
sourcePositions []int64
local string
localRepoRoot string
revision string
cluster *argoappv1.Cluster
res *repoapiclient.ManifestResponse
serversideRes *repoapiclient.ManifestResponse
revisions []string
}

// findandPrintDiff ... Prints difference between application current state and state stored in git or locally, returns boolean as true if difference is found else returns false
Expand Down
2 changes: 1 addition & 1 deletion cmd/argocd/commands/headless/headless.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func MaybeStartLocalServer(ctx context.Context, clientOpts *apiclient.ClientOpti
AppClientset: appClientset,
DisableAuth: true,
RedisClient: redis.NewClient(redisOptions),
Cache: servercache.NewCache(appstateCache, 0, 0, 0),
Cache: servercache.NewCache(appstateCache, 0, 0),
KubeClientset: kubeClientset,
DynamicClientset: dynamicClientset,
KubeControllerClientset: controllerClientset,
Expand Down
2 changes: 0 additions & 2 deletions cmpserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (

// ArgoCDCMPServer is the config management plugin server implementation
type ArgoCDCMPServer struct {
log *log.Entry
opts []grpc.ServerOption
initConstants plugin.CMPServerInitConstants
stopCh chan os.Signal
Expand Down Expand Up @@ -75,7 +74,6 @@ func NewServer(initConstants plugin.CMPServerInitConstants) (*ArgoCDCMPServer, e
}

return &ArgoCDCMPServer{
log: serverLog,
opts: serverOpts,
stopCh: make(chan os.Signal),
doneCh: make(chan any),
Expand Down
2 changes: 0 additions & 2 deletions commitserver/commit/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ import (

// Service is the service that handles commit requests.
type Service struct {
gitCredsStore git.CredsStore
metricsServer *metrics.Server
repoClientFactory RepoClientFactory
}

// NewService returns a new instance of the commit service.
func NewService(gitCredsStore git.CredsStore, metricsServer *metrics.Server) *Service {
return &Service{
gitCredsStore: gitCredsStore,
metricsServer: metricsServer,
repoClientFactory: NewRepoClientFactory(gitCredsStore, metricsServer),
}
Expand Down
4 changes: 2 additions & 2 deletions controller/appcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func NewApplicationController(
statusRefreshJitter: appResyncJitter,
refreshRequestedApps: make(map[string]CompareWith),
refreshRequestedAppsMutex: &sync.Mutex{},
auditLogger: argo.NewAuditLogger(namespace, kubeClientset, common.ApplicationController, enableK8sEvent),
auditLogger: argo.NewAuditLogger(kubeClientset, common.ApplicationController, enableK8sEvent),
settingsMgr: settingsMgr,
selfHealTimeout: selfHealTimeout,
selfHealBackOff: selfHealBackoff,
Expand Down Expand Up @@ -327,7 +327,7 @@ func NewApplicationController(
return nil, err
}
}
stateCache := statecache.NewLiveStateCache(db, appInformer, ctrl.settingsMgr, kubectl, ctrl.metricsServer, ctrl.handleObjectUpdated, clusterSharding, argo.NewResourceTracking())
stateCache := statecache.NewLiveStateCache(db, appInformer, ctrl.settingsMgr, ctrl.metricsServer, ctrl.handleObjectUpdated, clusterSharding, argo.NewResourceTracking())
appStateManager := NewAppStateManager(db, applicationClientset, repoClientset, namespace, kubectl, ctrl.onKubectlRun, ctrl.settingsMgr, stateCache, projInformer, ctrl.metricsServer, argoCache, ctrl.statusRefreshTimeout, argo.NewResourceTracking(), persistResourceHealth, repoErrorGracePeriod, serverSideDiff, ignoreNormalizerOpts)
ctrl.appInformer = appInformer
ctrl.appLister = appLister
Expand Down
3 changes: 0 additions & 3 deletions controller/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ func NewLiveStateCache(
db db.ArgoDB,
appInformer cache.SharedIndexInformer,
settingsMgr *settings.SettingsManager,
kubectl kube.Kubectl,
metricsServer *metrics.MetricsServer,
onObjectUpdated ObjectUpdatedHandler,
clusterSharding sharding.ClusterShardingCache,
Expand All @@ -201,7 +200,6 @@ func NewLiveStateCache(
db: db,
clusters: make(map[string]clustercache.ClusterCache),
onObjectUpdated: onObjectUpdated,
kubectl: kubectl,
settingsMgr: settingsMgr,
metricsServer: metricsServer,
clusterSharding: clusterSharding,
Expand All @@ -225,7 +223,6 @@ type liveStateCache struct {
db db.ArgoDB
appInformer cache.SharedIndexInformer
onObjectUpdated ObjectUpdatedHandler
kubectl kube.Kubectl
settingsMgr *settings.SettingsManager
metricsServer *metrics.MetricsServer
clusterSharding sharding.ClusterShardingCache
Expand Down
1 change: 0 additions & 1 deletion controller/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func TestHandleModEvent_ClusterExcluded(t *testing.T) {
appInformer: nil,
onObjectUpdated: func(_ map[string]bool, _ corev1.ObjectReference) {
},
kubectl: nil,
settingsMgr: &argosettings.SettingsManager{},
metricsServer: &metrics.MetricsServer{},
// returns a shard that never process any cluster
Expand Down
10 changes: 7 additions & 3 deletions controller/hydrator/hydrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,14 @@ type HydrationQueueKey struct {

// uniqueHydrationDestination is used to detect duplicate hydrate destinations.
type uniqueHydrationDestination struct {
sourceRepoURL string
//nolint:unused // used as part of a map key
sourceRepoURL string
//nolint:unused // used as part of a map key
sourceTargetRevision string
destinationBranch string
destinationPath string
//nolint:unused // used as part of a map key
destinationBranch string
//nolint:unused // used as part of a map key
destinationPath string
}

func (h *Hydrator) ProcessHydrationQueueItem(hydrationKey HydrationQueueKey) (processNext bool) {
Expand Down
Loading
Loading