From bceab0fa42b88e21afc48b6e31e968d5f0610efe Mon Sep 17 00:00:00 2001 From: Oleksandr Andriienko Date: Wed, 25 Mar 2020 17:01:37 +0200 Subject: [PATCH] Add error status if operator hasn't got permission to count users. (#208) * Add error status if operator hasn't got permission to count users. Signed-off-by: Oleksandr Andriienko * Add proposed changes. Signed-off-by: Oleksandr Andriienko --- pkg/controller/che/che_controller.go | 7 +++++++ pkg/controller/che/update.go | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/controller/che/che_controller.go b/pkg/controller/che/che_controller.go index 22aba4acb8..9ff602b32f 100644 --- a/pkg/controller/che/che_controller.go +++ b/pkg/controller/che/che_controller.go @@ -224,6 +224,7 @@ const ( failedNoOpenshiftUserReason = "InstallOrUpdateFailed" failedNoOpenshiftUserMessage = "No real user exists in the OpenShift cluster." + " Either disable OpenShift OAuth integration or add at least one user (details in the Help link)" + failedUnableToGetOpenshiftUsers = "Unable to get users on the OpenShift cluster." howToCreateAUserLinkOS4 = "https://docs.openshift.com/container-platform/4.1/authentication/understanding-identity-provider.html#identity-provider-overview_understanding-identity-provider" howToCreateAUserLinkOS3 = "https://docs.openshift.com/container-platform/3.11/install_config/configuring_authentication.html" ) @@ -352,8 +353,14 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e users := &userv1.UserList{} listOptions := &client.ListOptions{} if err := r.nonCachedClient.List(context.TODO(), listOptions, users); err != nil { + getUsersErrMsg := failedUnableToGetOpenshiftUsers + " Cause: " + err.Error() + logrus.Errorf(getUsersErrMsg) + if err := r.SetStatusDetails(instance, request, failedNoOpenshiftUserReason, getUsersErrMsg, ""); err != nil { + return reconcile.Result{}, err + } return reconcile.Result{}, err } + if len(users.Items) < 1 { helpLink := "" if isOpenShift4 { diff --git a/pkg/controller/che/update.go b/pkg/controller/che/update.go index a7a37f068a..767387ea2e 100644 --- a/pkg/controller/che/update.go +++ b/pkg/controller/che/update.go @@ -31,7 +31,7 @@ func (r *ReconcileChe) UpdateCheCRStatus(instance *orgv1.CheCluster, updatedFiel logrus.Infof("Updating %s CR with %s: %s", instance.Name, updatedField, value) err = r.client.Status().Update(context.TODO(), instance) if err != nil { - logrus.Warnf("Failed to update %s CR. Fetching the latest CR version: %s", instance.Name, err) + logrus.Errorf("Failed to update %s CR. Fetching the latest CR version: %s", instance.Name, err) return err } logrus.Infof("Custom resource %s updated", instance.Name) @@ -42,7 +42,7 @@ func (r *ReconcileChe) UpdateCheCRSpec(instance *orgv1.CheCluster, updatedField logrus.Infof("Updating %s CR with %s: %s", instance.Name, updatedField, value) err = r.client.Update(context.TODO(), instance) if err != nil { - logrus.Warnf("Failed to update %s CR: %s", instance.Name, err) + logrus.Errorf("Failed to update %s CR: %s", instance.Name, err) return err } logrus.Infof("Custom resource %s updated", instance.Name)