8000 fix: filter 0.9 api events bug by wangyelei · Pull Request #8630 · apecloud/kubeblocks · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000

fix: filter 0.9 api events bug #8630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,24 +429,22 @@ func main() {
os.Exit(1)
}

if !viper.GetBool(constant.DualOperatorsMode) {
if err = (&appscontrollers.OpsDefinitionReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("ops-definition-controller"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "OpsDefinition")
os.Exit(1)
}
if err = (&appscontrollers.OpsDefinitionReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("ops-definition-controller"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "OpsDefinition")
os.Exit(1)
}

if err = (&appscontrollers.OpsRequestReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("ops-request-controller"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "OpsRequest")
os.Exit(1)
}
if err = (&appscontrollers.OpsRequestReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("ops-request-controller"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "OpsRequest")
os.Exit(1)
}

if !viper.GetBool(constant.DualOperatorsMode) {
Expand Down
4 changes: 3 additions & 1 deletion controllers/apps/componentdefinition_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ func (r *ComponentDefinitionReconciler) Reconcile(ctx context.Context, req ctrl.
if err := r.Client.Get(rctx.Ctx, rctx.Req.NamespacedName, cmpd); err != nil {
return intctrlutil.CheckedRequeueWithError(err, rctx.Log, "")
}

if !intctrlutil.ObjectAPIVersionSupported(cmpd) {
return intctrlutil.Reconciled()
}
return r.reconcile(rctx, cmpd)
}

Expand Down
3 changes: 3 additions & 0 deletions controllers/apps/opsrequest_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ func (r *OpsRequestReconciler) handleOpsReqDeletedDuringRunning(reqCtx intctrlut
return err
}
for _, cluster := range clusterList.Items {
if !intctrlutil.ObjectAPIVersionSupported(&cluster) {
continue
}
if err := r.cleanupOpsAnnotationForCluster(reqCtx, &cluster); err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion controllers/apps/transformer_cluster_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ func (t *clusterInitTransformer) Transform(ctx graph.TransformContext, dag *grap
graphCli, _ := transCtx.Client.(model.GraphClient)

// init dag
graphCli.Root(dag, transCtx.OrigCluster, transCtx.Cluster, model.ActionStatusPtr())
if !intctrlutil.ObjectAPIVersionSupported(transCtx.Cluster) {
graphCli.Root(dag, transCtx.OrigCluster, transCtx.Cluster, model.ActionNoopPtr())
return graph.ErrPrematureStop
}
graphCli.Root(dag, transCtx.OrigCluster, transCtx.Cluster, model.ActionStatusPtr())
return nil
}
1 change: 1 addition & 0 deletions controllers/apps/transformer_component_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func (t *componentInitTransformer) Transform(ctx graph.TransformContext, dag *gr
transCtx.Context = intoContext(transCtx.Context, placement(transCtx.Component))

if !intctrlutil.ObjectAPIVersionSupported(transCtx.Component) {
rootVertex.Action = model.ActionNoopPtr()
return graph.ErrPrematureStop
}
return nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/instanceset/reconciler_api_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ func (r *apiVersionReconciler) PreCondition(tree *kubebuilderx.ObjectTree) *kube
}

func (r *apiVersionReconciler) Reconcile(tree *kubebuilderx.ObjectTree) (kubebuilderx.Result, error) {
if intctrlutil.ObjectAPIVersionSupported(tree.GetRoot()) {
return kubebuilderx.Continue, nil
if !intctrlutil.ObjectAPIVersionSupported(tree.GetRoot()) {
return kubebuilderx.Commit, nil
}
return kubebuilderx.Commit, nil
return kubebuilderx.Continue, nil
}

func NewAPIVersionReconciler() kubebuilderx.Reconciler {
Expand Down
20 changes: 18 additions & 2 deletions pkg/controller/kubebuilderx/plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,31 @@ func (b *PlanBuilder) Build() (graph.Plan, error) {
}

func buildOrderedVertices(ctx context.Context, currentTree *ObjectTree, desiredTree *ObjectTree) []*model.ObjectVertex {
getStatusField := func(obj client.Object) interface{} {
objValue := reflect.ValueOf(obj)
if objValue.Kind() != reflect.Ptr || objValue.Elem().Kind() != reflect.Struct {
return nil
}
field := objValue.Elem().FieldByName("Status")
if !field.IsValid() {
return nil
}
return field.Interface()
}

var vertices []*model.ObjectVertex

// handle root object
if desiredTree.GetRoot() == nil {
root := model.NewObjectVertex(currentTree.GetRoot(), currentTree.GetRoot(), model.ActionDeletePtr())
vertices = append(vertices, root)
} else {
root := model.NewObjectVertex(currentTree.GetRoot(), desiredTree.GetRoot(), model.ActionStatusPtr())
vertices = append(vertices, root)
currentStatus := getStatusField(currentTree.GetRoot())
desiredStatus := getStatusField(desiredTree.GetRoot())
if !reflect.DeepEqual(currentStatus, desiredStatus) {
root := model.NewObjectVertex(currentTree.GetRoot(), desiredTree.GetRoot(), model.ActionStatusPtr())
vertices = append(vertices, root)
}
// if annotations, labels or finalizers updated, do both meta patch and status update.
if !reflect.DeepEqual(currentTree.GetRoot().GetAnnotations(), desiredTree.GetRoot().GetAnnotations()) ||
< 2E18 /td> !reflect.DeepEqual(currentTree.GetRoot().GetLabels(), desiredTree.GetRoot().GetLabels()) ||
Expand Down
6 changes: 4 additions & 2 deletions pkg/controller/kubebuilderx/plan_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,17 @@ var _ = Describe("plan builder test", func() {
env := builder.NewConfigMapBuilder(namespace, name+"-env").GetObject()

var verticesExpected []*model.ObjectVertex
verticesExpected = append(verticesExpected, newVertex(its.DeepCopy(), its, model.ActionStatusPtr()))
itsCopy := its.DeepCopy()
itsCopy.Status.Replicas = *itsCopy.Spec.Replicas
verticesExpected = append(verticesExpected, newVertex(its, itsCopy, model.ActionStatusPtr()))
verticesExpected = append(verticesExpected, newVertex(nil, pod, model.ActionCreatePtr()))
verticesExpected = append(verticesExpected, newVertex(nil, headlessSvc, model.ActionCreatePtr()))
verticesExpected = append(verticesExpected, newVertex(nil, svc, model.ActionCreatePtr()))
verticesExpected = append(verticesExpected, newVertex(nil, env, model.ActionCreatePtr()))

// build ordered vertices
currentTree.SetRoot(its)
desiredTree.SetRoot(its)
desiredTree.SetRoot(itsCopy)
Expect(desiredTree.Add(pod, headlessSvc, svc, env)).Should(Succeed())
vertices := buildOrderedVertices(ctx, currentTree, desiredTree)

Expand Down
Loading
0