From 32301ac7d9488298f96fa227b1afd93e8a8f7f7f Mon Sep 17 00:00:00 2001 From: Oleksandr Andriienko Date: Sat, 13 Feb 2021 00:17:31 +0200 Subject: [PATCH] Fix logs. Fix user deletion: first off all we should remove secret, then user, identity and update oauth. Signed-off-by: Oleksandr Andriienko --- pkg/controller/che/che_controller.go | 8 ++++---- pkg/controller/che/oauth_initial_htpasswd_provider.go | 9 +++++---- pkg/controller/che/update.go | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pkg/controller/che/che_controller.go b/pkg/controller/che/che_controller.go index d7aff1047..dbb53df28 100644 --- a/pkg/controller/che/che_controller.go +++ b/pkg/controller/che/che_controller.go @@ -387,15 +387,15 @@ func (r *ReconcileChe) Reconcile(request reconcile.Request) (reconcile.Result, e if err := r.userHandler.DeleteOAuthInitialUser(deployContext); err != nil { logrus.Errorf("Unable to delete initial OpenShift OAuth user from a cluster. Cause: %s", err.Error()) instance.Spec.Auth.InitialOpenShiftOAuthUser = nil - err := r.UpdateCheCRSpec(instance, "InitialOpenShiftOAuthUser", "nil") + err := r.UpdateCheCRSpec(instance, "initialOpenShiftOAuthUser", "nil") return reconcile.Result{}, err } instance.Spec.Auth.OpenShiftoAuth = nil instance.Spec.Auth.InitialOpenShiftOAuthUser = nil updateFields := map[string]string{ - "OpenShiftoAuth": "nil", - "InitialOpenShiftOAuthUser": "nil", + "openShiftoAuth": "nil", + "initialOpenShiftOAuthUser": "nil", } if err := r.UpdateCheCRSpecByFields(instance, updateFields); err != nil { @@ -1203,7 +1203,7 @@ func (r *ReconcileChe) autoEnableOAuth(deployContext *deploy.DeployContext, requ newOAuthValue := util.NewBoolPointer(oauth) if !util.CompareBoolPointers(newOAuthValue, cr.Spec.Auth.OpenShiftoAuth) { cr.Spec.Auth.OpenShiftoAuth = newOAuthValue - if err := r.UpdateCheCRSpec(cr, "OpenShiftoAuth", strconv.FormatBool(oauth)); err != nil { + if err := r.UpdateCheCRSpec(cr, "openShiftoAuth", strconv.FormatBool(oauth)); err != nil { return reconcile.Result{Requeue: true, RequeueAfter: time.Second * 1}, err } } diff --git a/pkg/controller/che/oauth_initial_htpasswd_provider.go b/pkg/controller/che/oauth_initial_htpasswd_provider.go index cd8781d02..13a02a8fa 100644 --- a/pkg/controller/che/oauth_initial_htpasswd_provider.go +++ b/pkg/controller/che/oauth_initial_htpasswd_provider.go @@ -114,6 +114,11 @@ func (iuh *OpenShiftOAuthUserOperatorHandler) DeleteOAuthInitialUser(deployConte cr := deployContext.CheCluster userName := deploy.DefaultCheFlavor(cr) + + if err := deploy.DeleteSecret(htpasswdSecretName, ocConfigNamespace, iuh.runtimeClient); err != nil { + return err + } + if err := deleteUser(iuh.runtimeClient, userName); err != nil { return err } @@ -126,10 +131,6 @@ func (iuh *OpenShiftOAuthUserOperatorHandler) DeleteOAuthInitialUser(deployConte return err } - if err := deploy.DeleteSecret(htpasswdSecretName, ocConfigNamespace, iuh.runtimeClient); err != nil { - return err - } - if err := deploy.DeleteSecret(openShiftOAuthUserCredentialsSecret, cr.Namespace, iuh.runtimeClient); err != nil { return err } diff --git a/pkg/controller/che/update.go b/pkg/controller/che/update.go index eddbfe63a..822dfe289 100644 --- a/pkg/controller/che/update.go +++ b/pkg/controller/che/update.go @@ -40,11 +40,11 @@ func (r *ReconcileChe) UpdateCheCRStatus(instance *orgv1.CheCluster, updatedFiel // UpdateCheCRSpecByFields - updates Che CR "spec" fields by field map func (r *ReconcileChe) UpdateCheCRSpecByFields(instance *orgv1.CheCluster, fields map[string]string) (err error) { - updateInfo := append([]string{}, fmt.Sprintf("Updating multiple CR %s fields: \n", instance.Name)) + updateInfo := []string{} for updatedField, value := range fields { updateInfo = append(updateInfo, fmt.Sprintf("%s: %s", updatedField, value)) } - logrus.Infof(strings.Join(updateInfo, ", ")) + logrus.Infof(fmt.Sprintf("Updating multiple CR %s fields: ", instance.Name) + strings.Join(updateInfo, ", ")) err = r.client.Update(context.TODO(), instance) if err != nil {