From 1ed542233337eeca121b24a25db5b1e96a722c6d Mon Sep 17 00:00:00 2001 From: Nima Kaviani <17132353+nimakaviani@users.noreply.github.com> Date: Wed, 15 May 2024 19:12:53 -0700 Subject: [PATCH] fix gitea client timeout (#258) --- pkg/controllers/gitrepository/controller.go | 6 +++++- pkg/controllers/gitrepository/gitea.go | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/controllers/gitrepository/controller.go b/pkg/controllers/gitrepository/controller.go index 78062776..d98a7da7 100644 --- a/pkg/controllers/gitrepository/controller.go +++ b/pkg/controllers/gitrepository/controller.go @@ -70,8 +70,12 @@ func GetGitProvider(ctx context.Context, repo *v1alpha1.GitRepository, kubeClien case v1alpha1.GitProviderGitea: tr := &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + DialContext: (&net.Dialer{ + Timeout: gitTCPTimeout, + KeepAlive: 30 * time.Second, // from http.DefaultTransport + }).DialContext, } - c := &http.Client{Transport: tr} + c := &http.Client{Transport: tr, Timeout: gitHTTPTimeout} giteaClient, err := NewGiteaClient(repo.Spec.Provider.GitURL, gitea.SetHTTPClient(c)) if err != nil { return nil, err diff --git a/pkg/controllers/gitrepository/gitea.go b/pkg/controllers/gitrepository/gitea.go index 8a5b3b65..288c1cc4 100644 --- a/pkg/controllers/gitrepository/gitea.go +++ b/pkg/controllers/gitrepository/gitea.go @@ -83,7 +83,7 @@ func (g *giteaProvider) setProviderCredentials(ctx context.Context, repo *v1alph func (g *giteaProvider) getRepository(ctx context.Context, repo *v1alpha1.GitRepository) (repoInfo, error) { resp, repoResp, err := g.giteaClient.GetRepo(getOrganizationName(*repo), getRepositoryName(*repo)) if err != nil { - if repoResp.StatusCode == 404 { + if repoResp != nil && repoResp.StatusCode == 404 { return repoInfo{}, notFoundError{} } return repoInfo{}, err