fix: ks-account abnormal restart
Signed-off-by: hongming <talonwan@yunify.com>
This commit is contained in:
@@ -142,9 +142,11 @@ func (r *ReconcileClusterRoleBinding) updateRoleBindings(clusterRoleBinding *rba
|
||||
log.Info("Creating default role binding", "namespace", namespace.Name, "name", adminBinding.Name)
|
||||
err = r.Create(context.TODO(), adminBinding)
|
||||
if err != nil {
|
||||
return err
|
||||
log.Error(err, "default role binding create failed", "namespace", namespace.Name, "name", adminBinding.Name)
|
||||
}
|
||||
return err
|
||||
} else if err != nil {
|
||||
log.Error(err, "default role binding not found", "namespace", namespace.Name, "name", adminBinding.Name)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -182,9 +184,7 @@ func (r *ReconcileClusterRoleBinding) updateRoleBindings(clusterRoleBinding *rba
|
||||
if errors.IsNotFound(err) {
|
||||
log.Info("Creating default role binding", "namespace", namespace.Name, "name", viewerBinding.Name)
|
||||
err = r.Create(context.TODO(), viewerBinding)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return err
|
||||
} else if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -232,6 +232,7 @@ func (r *ReconcileNamespace) checkAndCreateRoleBindings(namespace *corev1.Namesp
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
found = adminBinding
|
||||
} else if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -276,6 +277,7 @@ func (r *ReconcileNamespace) checkAndCreateRoleBindings(namespace *corev1.Namesp
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
found = viewerBinding
|
||||
} else if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -309,7 +311,8 @@ func (r *ReconcileNamespace) checkAndCreateRuntime(namespace *corev1.Namespace)
|
||||
}
|
||||
|
||||
cm := &corev1.ConfigMap{}
|
||||
err := r.Get(context.TODO(), types.NamespacedName{Namespace: constants.KubeSphereControlNamespace, Name: constants.AdminUserName}, cm)
|
||||
configName := fmt.Sprintf("kubeconfig-%s", constants.AdminUserName)
|
||||
err := r.Get(context.TODO(), types.NamespacedName{Namespace: constants.KubeSphereControlNamespace, Name: configName}, cm)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -353,12 +356,8 @@ func (r *ReconcileNamespace) checkAndBindWorkspace(namespace *corev1.Namespace)
|
||||
|
||||
if err != nil {
|
||||
if errors.IsNotFound(err) {
|
||||
log.Error(err, "namespace", namespace.Name)
|
||||
delete(namespace.Labels, constants.WorkspaceLabelKey)
|
||||
err = r.Update(context.TODO(), namespace)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Error(err, fmt.Sprintf("namespace %s bind workspace %s but not found", namespace.Name, workspaceName))
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -188,9 +188,10 @@ func (r *ReconcileWorkspace) createWorkspaceAdmin(instance *tenantv1alpha1.Works
|
||||
}
|
||||
|
||||
// Update the found object and write the result back if there are any changes
|
||||
if !reflect.DeepEqual(admin.Rules, found.Rules) || !reflect.DeepEqual(admin.Labels, found.Labels) {
|
||||
if !reflect.DeepEqual(admin.Rules, found.Rules) || !reflect.DeepEqual(admin.Labels, found.Labels) || !reflect.DeepEqual(admin.Annotations, found.Annotations) {
|
||||
found.Rules = admin.Rules
|
||||
found.Labels = admin.Labels
|
||||
found.Annotations = admin.Annotations
|
||||
log.Info("Updating workspace role", "workspace", instance.Name, "name", admin.Name)
|
||||
err = r.Update(context.TODO(), found)
|
||||
if err != nil {
|
||||
@@ -226,9 +227,10 @@ func (r *ReconcileWorkspace) createWorkspaceRegular(instance *tenantv1alpha1.Wor
|
||||
}
|
||||
|
||||
// Update the found object and write the result back if there are any changes
|
||||
if !reflect.DeepEqual(regular.Rules, found.Rules) || !reflect.DeepEqual(regular.Labels, found.Labels) {
|
||||
if !reflect.DeepEqual(regular.Rules, found.Rules) || !reflect.DeepEqual(regular.Labels, found.Labels) || !reflect.DeepEqual(regular.Annotations, found.Annotations) {
|
||||
found.Rules = regular.Rules
|
||||
found.Labels = regular.Labels
|
||||
found.Annotations = regular.Annotations
|
||||
log.Info("Updating workspace role", "workspace", instance.Name, "name", regular.Name)
|
||||
err = r.Update(context.TODO(), found)
|
||||
if err != nil {
|
||||
@@ -264,9 +266,10 @@ func (r *ReconcileWorkspace) createWorkspaceViewer(instance *tenantv1alpha1.Work
|
||||
}
|
||||
|
||||
// Update the found object and write the result back if there are any changes
|
||||
if !reflect.DeepEqual(viewer.Rules, found.Rules) || !reflect.DeepEqual(viewer.Labels, found.Labels) {
|
||||
if !reflect.DeepEqual(viewer.Rules, found.Rules) || !reflect.DeepEqual(viewer.Labels, found.Labels) || !reflect.DeepEqual(viewer.Annotations, found.Annotations) {
|
||||
found.Rules = viewer.Rules
|
||||
found.Labels = viewer.Labels
|
||||
found.Annotations = viewer.Annotations
|
||||
log.Info("Updating workspace role", "workspace", instance.Name, "name", viewer.Name)
|
||||
err = r.Update(context.TODO(), found)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user