Gracefully ignore the error when trying to delete an unexisting OAuthClient (#48)

Signed-off-by: David Festal <dfestal@redhat.com>
pull/50/head
David Festal 2019-07-16 12:01:46 +02:00 committed by GitHub
parent 61b2e9902d
commit 6e56d28841
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package che
import (
"k8s.io/apimachinery/pkg/api/errors"
"context"
orgv1 "github.com/eclipse/che-operator/pkg/apis/org/v1"
"github.com/eclipse/che-operator/pkg/util"
@ -20,14 +21,15 @@ func (r *ReconcileChe) ReconcileFinalizer(instance *orgv1.CheCluster) (err error
oAuthClientName := instance.Spec.Auth.OauthClientName
logrus.Infof("Custom resource %s is being deleted. Deleting oAuthClient %s first", instance.Name, oAuthClientName)
oAuthClient, err := r.GetOAuthClient(oAuthClientName)
if err != nil {
if err == nil {
if err := r.client.Delete(context.TODO(), oAuthClient); err != nil {
logrus.Errorf("Failed to delete %s oAuthClient: %s", oAuthClientName, err)
return err
}
} else if !errors.IsNotFound(err) {
logrus.Errorf("Failed to get %s oAuthClient: %s", oAuthClientName, err)
return err
}
if err := r.client.Delete(context.TODO(), oAuthClient); err != nil {
logrus.Errorf("Failed to delete %s oAuthClient: %s", oAuthClientName, err)
return err
}
instance.ObjectMeta.Finalizers = util.DoRemoveString(instance.ObjectMeta.Finalizers, oAuthFinalizerName)
logrus.Infof("Updating %s CR", instance.Name)