diff --git a/controllers/discoveryconfig_controller.go b/controllers/discoveryconfig_controller.go index a787743..0a5e44d 100644 --- a/controllers/discoveryconfig_controller.go +++ b/controllers/discoveryconfig_controller.go @@ -158,7 +158,7 @@ func (r *DiscoveryConfigReconciler) updateDiscoveredClusters(ctx context.Context } if err != nil { - if ocm.IsUnrecoverable(err) || ocm.IsUnauthorizedClient(err) { + if ocm.IsUnrecoverable(err) || ocm.IsUnauthorizedClient(err) || ocm.IsInvalidClient(err) { logf.Info("Error encountered. Cleaning up clusters.", "Error", err.Error()) return r.deleteAllClusters(ctx, config) } diff --git a/pkg/ocm/auth/provider.go b/pkg/ocm/auth/provider.go index f260ab6..bf52168 100644 --- a/pkg/ocm/auth/provider.go +++ b/pkg/ocm/auth/provider.go @@ -20,6 +20,7 @@ var ( AuthProvider IAuthProvider = &authProvider{} ErrInvalidToken = errors.New("invalid token") + ErrInvalidClient = errors.New("invalid_client") ErrUnauthorizedClient = errors.New("unauthorized_client") ) diff --git a/pkg/ocm/ocm.go b/pkg/ocm/ocm.go index 3943dd6..b892b1b 100644 --- a/pkg/ocm/ocm.go +++ b/pkg/ocm/ocm.go @@ -86,6 +86,14 @@ func formatCluster(sub subscription.Subscription) (discovery.DiscoveredCluster, return discoveredCluster, true } +// IsInvalidClient returns true if the specified error is invalid client side error. +func IsInvalidClient(err error) bool { + if err != nil { + return strings.Contains(err.Error(), auth.ErrInvalidClient.Error()) + } + return false +} + // IsUnauthorizedClient returns true if the specified error is unauthorized client side error. func IsUnauthorizedClient(err error) bool { if err != nil { diff --git a/pkg/ocm/ocm_test.go b/pkg/ocm/ocm_test.go index 8c54b81..8d24db9 100644 --- a/pkg/ocm/ocm_test.go +++ b/pkg/ocm/ocm_test.go @@ -338,6 +338,38 @@ func Test_IsRecoverable(t *testing.T) { } +func Test_IsInvalidClient(t *testing.T) { + tests := []struct { + name string + err error + want bool + }{ + { + name: "Unrecoverable Invalid Client Error", + err: auth.ErrInvalidClient, + want: true, + }, + { + name: "Recoverable Error", + err: errors.New("test error"), + want: false, + }, + { + name: "Empty Error", + err: nil, + want: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := IsInvalidClient(tt.err); got != tt.want { + t.Errorf("IsInvalidClient() = %v, want %v", got, tt.want) + } + }) + } + +} + // BOOKMARK: This is the test for No ExternalClusterID func TestFormatCLusterError(t *testing.T) { tests := []struct {