@@ -18,6 +18,7 @@ package controller
18
18
19
19
import (
20
20
"context"
21
+ "fmt"
21
22
"time"
22
23
23
24
g "code.gitea.io/sdk/gitea"
@@ -70,29 +71,29 @@ func (r *RepoReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
70
71
return ctrl.Result {}, err
71
72
}
72
73
if h == nil && gitea == nil {
73
- return ctrl.Result {Requeue : true , RequeueAfter : time .Second * 5 }, nil
74
+ return ctrl.Result {Requeue : true , RequeueAfter : time .Second * 5 }, fmt . Errorf ( "failed to get gitea client" )
74
75
}
75
76
r .h = h
76
77
77
78
isRepoMarkedToBeDeleted := repo .GetDeletionTimestamp () != nil
78
79
if isRepoMarkedToBeDeleted {
79
80
if controllerutil .ContainsFinalizer (repo , repoFinalizer ) {
80
81
if err := r .deleteRepo (repo ); err != nil {
81
- return ctrl.Result {}, err
82
+ return ctrl.Result {Requeue : true , RequeueAfter : time . Second * 5 }, err
82
83
}
83
84
controllerutil .RemoveFinalizer (repo , repoFinalizer )
84
85
if err := r .Update (ctx , repo ); err != nil {
85
- return ctrl.Result {}, err
86
+ return ctrl.Result {Requeue : true , RequeueAfter : time . Second * 5 }, err
86
87
}
87
88
}
88
89
return ctrl.Result {}, nil
89
90
}
90
91
91
92
if repo .Spec .User == nil && repo .Spec .Org == nil {
92
- return ctrl.Result {}, nil
93
+ return ctrl.Result {}, fmt . Errorf ( "repo must be created for either user or org" )
93
94
}
94
95
if repo .Spec .User != nil && repo .Spec .Org != nil {
95
- return ctrl.Result {}, nil
96
+ return ctrl.Result {}, fmt . Errorf ( "repo cannot be created for both user and org" )
96
97
}
97
98
want := & g.Repository {
98
99
Description : repo .Spec .Description ,
@@ -101,13 +102,13 @@ func (r *RepoReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
101
102
if repo .Spec .Org != nil {
102
103
gRepo , resp , err := r .h .GetRepo (repo .Spec .Org .Name , repo .Name )
103
104
if err != nil && resp .StatusCode != 404 {
104
- return ctrl.Result {}, err
105
+ return ctrl.Result {Requeue : true , RequeueAfter : time . Second * 5 }, err
105
106
}
106
107
if resp .StatusCode == 200 {
107
108
if ! compareRepo (want , gRepo ) {
108
109
logger .Info ("updating repo" )
109
110
if _ , _ , err := r .h .EditRepo (repo .Spec .Org .Name , repo .Name , g.EditRepoOption {}); err != nil {
110
- return ctrl.Result {}, err
111
+ return ctrl.Result {Requeue : true , RequeueAfter : time . Second * 5 }, err
111
112
}
112
113
}
113
114
}
@@ -125,13 +126,13 @@ func (r *RepoReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
125
126
IssueLabels : repo .Spec .IssueLabels ,
126
127
})
127
128
if err != nil {
128
- return ctrl.Result {}, nil
129
+ return ctrl.Result {Requeue : true , RequeueAfter : time . Second * 5 }, err
129
130
}
130
131
if ! repo .Status .Provisioned {
131
132
repo .Status .Provisioned = true
132
133
if err := r .Client .Status ().Update (ctx , repo ); err != nil {
133
134
logger .Error (err , "Failed to update Repo status" )
134
- return ctrl.Result {}, nil
135
+ return ctrl.Result {Requeue : true , RequeueAfter : time . Second * 5 }, err
135
136
}
136
137
}
137
138
if ! controllerutil .ContainsFinalizer (repo , repoFinalizer ) {
@@ -144,14 +145,14 @@ func (r *RepoReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
144
145
if repo .Spec .User != nil {
145
146
_ , _ , err := r .h .CreateRepo (g.CreateRepoOption {})
146
147
if err != nil {
147
- return ctrl.Result {}, nil
148
+ return ctrl.Result {}, err
148
149
}
149
150
}
150
151
if ! repo .Status .Provisioned {
151
152
repo .Status .Provisioned = true
152
153
if err := r .Client .Status ().Update (ctx , repo ); err != nil {
153
154
logger .Error (err , "Failed to update Repo status" )
154
- return ctrl.Result {}, nil
155
+ return ctrl.Result {}, err
155
156
}
156
157
}
157
158
0 commit comments