Skip to content
Open
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 applicationset/controllers/requeue_after_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestRequeueAfter(t *testing.T) {
},
}
fakeDynClient := dynfake.NewSimpleDynamicClientWithCustomListKinds(runtime.NewScheme(), gvrToListKind, duckType)
scmConfig := generators.NewSCMConfig("", []string{""}, true, true, nil, true)
scmConfig := generators.NewSCMConfig("", []string{""}, true, true, false, 100, nil, true)
clusterInformer, err := settings.NewClusterInformer(appClientset, "argocd")
require.NoError(t, err)

Expand Down
4 changes: 2 additions & 2 deletions applicationset/generators/pull_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func TestAllowedSCMProviderPullRequest(t *testing.T) {
"gitea.myorg.com",
"bitbucket.myorg.com",
"azuredevops.myorg.com",
}, true, true, nil, true))
}, true, true, false, 100, nil, true))

applicationSetInfo := argoprojiov1alpha1.ApplicationSet{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -421,7 +421,7 @@ func TestAllowedSCMProviderPullRequest(t *testing.T) {
}

func TestSCMProviderDisabled_PRGenerator(t *testing.T) {
generator := NewPullRequestGenerator(nil, NewSCMConfig("", []string{}, false, true, nil, true))
generator := NewPullRequestGenerator(nil, NewSCMConfig("", []string{}, false, true, false, 100, nil, true))

applicationSetInfo := argoprojiov1alpha1.ApplicationSet{
ObjectMeta: metav1.ObjectMeta{
Expand Down
23 changes: 20 additions & 3 deletions applicationset/generators/scm_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,20 @@ type SCMConfig struct {
allowedSCMProviders []string
enableSCMProviders bool
enableGitHubAPIMetrics bool
enableGitHubCache bool
githubCacheSize int
GitHubApps github_app_auth.Credentials
tokenRefStrictMode bool
}

func NewSCMConfig(scmRootCAPath string, allowedSCMProviders []string, enableSCMProviders bool, enableGitHubAPIMetrics bool, gitHubApps github_app_auth.Credentials, tokenRefStrictMode bool) SCMConfig {
func NewSCMConfig(scmRootCAPath string, allowedSCMProviders []string, enableSCMProviders bool, enableGitHubAPIMetrics bool, enableGitHubCache bool, githubCacheSize int, gitHubApps github_app_auth.Credentials, tokenRefStrictMode bool) SCMConfig {
return SCMConfig{
scmRootCAPath: scmRootCAPath,
allowedSCMProviders: allowedSCMProviders,
enableSCMProviders: enableSCMProviders,
enableGitHubAPIMetrics: enableGitHubAPIMetrics,
enableGitHubCache: enableGitHubCache,
githubCacheSize: githubCacheSize,
GitHubApps: gitHubApps,
tokenRefStrictMode: tokenRefStrictMode,
}
Expand Down Expand Up @@ -279,6 +283,7 @@ func (g *SCMProviderGenerator) GenerateParams(appSetGenerator *argoprojiov1alpha

func (g *SCMProviderGenerator) githubProvider(ctx context.Context, github *argoprojiov1alpha1.SCMProviderGeneratorGithub, applicationSetInfo *argoprojiov1alpha1.ApplicationSet) (scm_provider.SCMProviderService, error) {
var metricsCtx *services.MetricsContext
var cacheCtx *services.GitHubCacheContext
var httpClient *http.Client

if g.enableGitHubAPIMetrics {
Expand All @@ -289,13 +294,25 @@ func (g *SCMProviderGenerator) githubProvider(ctx context.Context, github *argop
httpClient = services.NewGitHubMetricsClient(metricsCtx)
}

if g.enableGitHubCache {
cacheCtx = &services.GitHubCacheContext{
AppSecretName: github.AppSecretName,
TokenRef: github.TokenRef,
}
if g.enableGitHubAPIMetrics {
httpClient = services.NewGitHubCache(cacheCtx, g.githubCacheSize, httpClient.Transport)
} else {
httpClient = services.NewGitHubCache(cacheCtx, g.githubCacheSize, nil)
}
}

if github.AppSecretName != "" {
auth, err := g.GitHubApps.GetAuthSecret(ctx, github.AppSecretName)
if err != nil {
return nil, fmt.Errorf("error fetching Github app secret: %w", err)
}

if g.enableGitHubAPIMetrics {
if g.enableGitHubAPIMetrics || g.enableGitHubCache {
return scm_provider.NewGithubAppProviderFor(ctx, *auth, github.Organization, github.API, github.AllBranches, httpClient)
}
return scm_provider.NewGithubAppProviderFor(ctx, *auth, github.Organization, github.API, github.AllBranches)
Expand All @@ -306,7 +323,7 @@ func (g *SCMProviderGenerator) githubProvider(ctx context.Context, github *argop
return nil, fmt.Errorf("error fetching Github token: %w", err)
}

if g.enableGitHubAPIMetrics {
if g.enableGitHubAPIMetrics || g.enableGitHubCache {
return scm_provider.NewGithubProvider(github.Organization, token, github.API, github.AllBranches, httpClient)
}
return scm_provider.NewGithubProvider(github.Organization, token, github.API, github.AllBranches)
Expand Down
Loading
Loading