Skip to content

Commit

Permalink
Remove client get from repo reconciler (nephio-project#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
liamfallon authored and PrimalPimmy committed Aug 2, 2024
1 parent b6c0465 commit 63ae05e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions controllers/pkg/giteaclient/giteaclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (

type GiteaClient interface {
Start(ctx context.Context)
IsInitialized() bool
Get() *gitea.Client
GetMyUserInfo() (*gitea.User, *gitea.Response, error)
DeleteRepo(owner string, repo string) (*gitea.Response, error)
Expand Down Expand Up @@ -138,6 +139,10 @@ func getClientAuth(secret *corev1.Secret) gitea.ClientOption {
return gitea.SetBasicAuth(string(secret.Data["username"]), string(secret.Data["password"]))
}

func (r *gc) IsInitialized() bool {
return r.giteaClient != nil
}

func (r *gc) Get() *gitea.Client {
return r.giteaClient
}
Expand Down
3 changes: 1 addition & 2 deletions controllers/pkg/reconcilers/repository/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
}

// check if client exists otherwise retry
giteaClient := r.giteaClient.Get()
if giteaClient == nil {
if !r.giteaClient.IsInitialized() {
err := fmt.Errorf("gitea server unreachable")
log.Error(err, "cannot connect to git server")
cr.SetConditions(infrav1alpha1.Failed(err.Error()))
Expand Down
4 changes: 4 additions & 0 deletions controllers/pkg/reconcilers/repository/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ type NephioGiteaClientMock struct {
editRepoError error
}

func (gc NephioGiteaClientMock) IsInitialized() bool {
return true
}

func (gc NephioGiteaClientMock) Get() *gitea.Client {
return nil
}
Expand Down

0 comments on commit 63ae05e

Please sign in to comment.