Fix workspacerole sync condition (#2142)

* fix: Fixed the issue that role and rolebinding do not trigger synchronization when binding a workspace to a cluster

Signed-off-by: peng wu <2030047311@qq.com>

* fix: update goimports

Signed-off-by: peng wu <2030047311@qq.com>

* fix: update workspace sync condition && update list options

Signed-off-by: peng wu <2030047311@qq.com>

* fix: rename enqueue request map func for workspacerole and workspacerolebinding

Signed-off-by: peng wu <2030047311@qq.com>

* fix: workspace role sync logic

Signed-off-by: peng wu <2030047311@qq.com>

---------

Signed-off-by: peng wu <2030047311@qq.com>
Signed-off-by: hongming <coder.scala@gmail.com>
(cherry picked from commit bc128dcf78)
This commit is contained in:
smartcat999
2024-12-26 13:48:08 +08:00
committed by hongming
parent 114f5a6e79
commit 942d3be9d4
3 changed files with 122 additions and 11 deletions

View File

@@ -0,0 +1,46 @@
/*
* Please refer to the LICENSE file in the root directory of the project.
* https://github.com/kubesphere/kubesphere/blob/master/LICENSE
*/
package predicate
import (
"reflect"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/predicate"
tenantv1alpha1 "kubesphere.io/api/tenant/v1beta1"
)
type WorkspaceStatusChangedPredicate struct {
predicate.Funcs
}
func (WorkspaceStatusChangedPredicate) Update(e event.UpdateEvent) bool {
oldWorkspaceTemplate, ok := e.ObjectOld.(*tenantv1alpha1.WorkspaceTemplate)
if !ok {
return false
}
newWorkspaceTemplate, ok := e.ObjectNew.(*tenantv1alpha1.WorkspaceTemplate)
if !ok {
return false
}
if !reflect.DeepEqual(oldWorkspaceTemplate.Spec, newWorkspaceTemplate.Spec) {
return true
}
return false
}
func (WorkspaceStatusChangedPredicate) Create(_ event.CreateEvent) bool {
return false
}
func (WorkspaceStatusChangedPredicate) Delete(_ event.DeleteEvent) bool {
return false
}
func (WorkspaceStatusChangedPredicate) Generic(_ event.GenericEvent) bool {
return false
}