Skip to content

Commit 7213b8c

Browse files
fix pr automation not found bug (#2898)
1 parent 3cb596c commit 7213b8c

File tree

8 files changed

+15
-15
lines changed

8 files changed

+15
-15
lines changed
-9 Bytes
Binary file not shown.
-1 Bytes
Binary file not shown.
-14 Bytes
Binary file not shown.
-1 Bytes
Binary file not shown.

go/controller/internal/controller/prautomation_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import (
1919
console "github.com/pluralsh/console/go/client"
2020
"github.com/pluralsh/console/go/controller/api/v1alpha1"
2121
consoleclient "github.com/pluralsh/console/go/controller/internal/client"
22-
"github.com/pluralsh/console/go/controller/internal/errors"
2322
"github.com/pluralsh/console/go/controller/internal/utils"
23+
"k8s.io/apimachinery/pkg/api/errors"
2424
)
2525

2626
// PrAutomationReconciler reconciles a v1alpha1.PrAutomation object.

go/controller/internal/controller/servicecontext_controller.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
console "github.com/pluralsh/console/go/client"
77
consoleclient "github.com/pluralsh/console/go/controller/internal/client"
88
"github.com/pluralsh/console/go/controller/internal/common"
9-
internalerror "github.com/pluralsh/console/go/controller/internal/errors"
109
"github.com/pluralsh/console/go/controller/internal/utils"
1110
"github.com/samber/lo"
1211
"k8s.io/apimachinery/pkg/api/errors"
@@ -68,8 +67,7 @@ func (r *ServiceContextReconciler) Reconcile(ctx context.Context, req ctrl.Reque
6867
return *result, reterr
6968
}
7069

71-
exists, err := r.handleExisting(serviceContext)
72-
if !exists && err == nil && !serviceContext.DriftDetect() {
70+
if !r.handleExisting(serviceContext) && !serviceContext.DriftDetect() {
7371
utils.MarkCondition(serviceContext.SetCondition, v1alpha1.SynchronizedConditionType, v1.ConditionTrue, v1alpha1.SynchronizedConditionReason, "")
7472
utils.MarkCondition(serviceContext.SetCondition, v1alpha1.ReadonlyConditionType, v1.ConditionTrue, v1alpha1.ReadyConditionReason, v1alpha1.ReadonlyTrueConditionMessage.String())
7573
return serviceContext.Spec.Reconciliation.Requeue(), err
@@ -119,24 +117,21 @@ func (r *ServiceContextReconciler) sync(sc *v1alpha1.ServiceContext, project *v1
119117
return r.ConsoleClient.SaveServiceContext(sc.ConsoleName(), attributes)
120118
}
121119

122-
func (r *ServiceContextReconciler) handleExisting(sc *v1alpha1.ServiceContext) (bool, error) {
123-
apiServiceContext, err := r.ConsoleClient.GetServiceContext(sc.ConsoleName())
124-
if err != nil || apiServiceContext == nil {
120+
func (r *ServiceContextReconciler) handleExisting(sc *v1alpha1.ServiceContext) bool {
121+
apiServiceContext, _ := r.ConsoleClient.GetServiceContext(sc.ConsoleName())
122+
if apiServiceContext == nil {
125123
utils.MarkCondition(sc.SetCondition, v1alpha1.SynchronizedConditionType, v1.ConditionFalse, v1alpha1.SynchronizedConditionReasonNotFound, v1alpha1.SynchronizedNotFoundConditionMessage.String())
126124
utils.MarkCondition(sc.SetCondition, v1alpha1.ReadyConditionType, v1.ConditionFalse, v1alpha1.ReadyConditionReason, "")
127-
if internalerror.IsNotFound(err) || err == nil {
128-
sc.Status.ID = nil
129-
return false, nil
130-
}
131-
return false, err
125+
sc.Status.ID = nil
126+
return false
132127
}
133128

134129
sc.Status.ID = &apiServiceContext.ID
135130

136131
utils.MarkCondition(sc.SetCondition, v1alpha1.SynchronizedConditionType, v1.ConditionTrue, v1alpha1.SynchronizedConditionReason, "")
137132
utils.MarkCondition(sc.SetCondition, v1alpha1.ReadyConditionType, v1.ConditionTrue, v1alpha1.ReadyConditionReason, "")
138133

139-
return true, nil
134+
return true
140135
}
141136

142137
func (r *ServiceContextReconciler) addOrRemoveFinalizer(serviceContext *v1alpha1.ServiceContext) *ctrl.Result {

go/controller/internal/errors/base.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package errors
22

33
import (
44
"errors"
5+
"strings"
56

67
client "github.com/Yamashou/gqlgenc/clientv2"
78
"github.com/vektah/gqlparser/v2/gqlerror"
@@ -19,6 +20,7 @@ func (k KnownError) Error() string {
1920

2021
const (
2122
ErrorNotFound KnownError = "could not find resource"
23+
ErrorNotFound2 KnownError = "not found"
2224
ErrorNotFoundOIDCProvider KnownError = "the resource you requested was not found"
2325
ErrDeleteRepository = "could not delete repository"
2426
)
@@ -43,8 +45,9 @@ func (er *wrappedErrorResponse) Has(err KnownError) bool {
4345
return false
4446
}
4547

48+
expected := string(err)
4649
for _, g := range *er.err.GqlErrors {
47-
if g.Message == string(err) {
50+
if strings.Contains(g.Message, expected) {
4851
return true
4952
}
5053
}
@@ -69,7 +72,9 @@ func IsNotFound(err error) bool {
6972
return false
7073
}
7174

72-
return newAPIError(errorResponse).Has(ErrorNotFound) || newAPIError(errorResponse).Has(ErrorNotFoundOIDCProvider)
75+
return (newAPIError(errorResponse).Has(ErrorNotFound) ||
76+
newAPIError(errorResponse).Has(ErrorNotFoundOIDCProvider) ||
77+
newAPIError(errorResponse).Has(ErrorNotFound2))
7378
}
7479

7580
func IgnoreNotFound(err error) error {
-9 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)