Skip to content

Commit f892ff2

Browse files
committed
Make specific function for PodNotFound error
1 parent 92bb1e1 commit f892ff2

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

pkg/controller/mysqlcluster/internal/syncer/errors.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,21 @@ func NewError(code SyncErrCode, syncer, details string) error {
4646
}
4747
}
4848

49-
// IsError check if a error is of given code
50-
func IsError(err error, code SyncErrCode) bool {
49+
// NewPodNotFoundError returns a PodNotFound error
50+
func NewPodNotFoundError() error {
51+
return &SyncError{
52+
syncer: "PodSyncer",
53+
code: PodNotFound,
54+
details: "",
55+
}
56+
}
57+
58+
// IsPodNotFound check if it's a PodNotFound error
59+
func IsPodNotFound(err error) bool {
5160
switch t := err.(type) {
5261
default:
5362
return false
5463
case *SyncError:
55-
return t.code == code
64+
return t.code == PodNotFound
5665
}
5766
}

pkg/controller/mysqlcluster/internal/syncer/pod.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (s *podSyncer) SyncFn(in runtime.Object) error {
6565

6666
// raise error if pod is not created
6767
if out.CreationTimestamp.IsZero() {
68-
return NewError(PodNotFound, "PodSyncer", "pod is not found")
68+
return NewPodNotFoundError()
6969
}
7070

7171
master := s.cluster.GetNodeCondition(s.hostname, api.NodeConditionMaster)

pkg/controller/mysqlcluster/mysqlcluster_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func (r *ReconcileMysqlCluster) Reconcile(request reconcile.Request) (reconcile.
200200
for _, sync := range r.getPodSyncers(cluster) {
201201
if err = syncer.Sync(context.TODO(), sync, r.recorder); err != nil {
202202
// if it's pod not found then skip the error
203-
if !clustersyncer.IsError(err, clustersyncer.PodNotFound) {
203+
if !clustersyncer.IsPodNotFound(err) {
204204
return reconcile.Result{}, err
205205
}
206206
}

0 commit comments

Comments
 (0)