Skip to content
Open
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
2 changes: 1 addition & 1 deletion pkg/controller/kubebuilderx/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (c *controller) emitFailureEvent() {
return
}
// TODO(free6om): make error message user-friendly
c.tree.EventRecorder.Eventf(c.tree.GetRoot(), corev1.EventTypeWarning, "FailedReconcile", "reconcile failed: %s", c.err.Error())
c.tree.EventRecorder.Eventf(c.tree.GetRoot(), corev1.EventTypeWarning, "FailedReconcile", "%s", c.err.Error())
}

func NewController(ctx context.Context, cli client.Client, req ctrl.Request, recorder record.EventRecorder, logger logr.Logger) Controller {
Expand Down
17 changes: 9 additions & 8 deletions pkg/controller/kubebuilderx/plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/tools/record"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

Expand Down Expand Up @@ -265,7 +266,7 @@ func (b *PlanBuilder) defaultWalkFunc(v graph.Vertex) error {
func (b *PlanBuilder) createObject(ctx context.Context, vertex *model.ObjectVertex) error {
err := b.cli.Create(ctx, vertex.Obj, clientOption(vertex))
if err != nil && !apierrors.IsAlreadyExists(err) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IsAlreadyExists error should be ignored too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean should NOT be ingored? I think ignoring IsAlreadyExists is safe. And similarly, I think ignoring IsNotFound in delete operations is also safe.

return err
return fmt.Errorf("create %T %s failed: %w", vertex.Obj, klog.KObj(vertex.Obj), err)
}
b.emitEvent(vertex.Obj, "SuccessfulCreate", model.CREATE)
return nil
Expand All @@ -281,8 +282,8 @@ func (b *PlanBuilder) updateObject(ctx context.Context, vertex *model.ObjectVert
err = b.cli.Update(ctx, vertex.Obj, clientOption(vertex))
reason = "SuccessfulUpdate"
}
if err != nil && !apierrors.IsNotFound(err) {
return err
if err != nil {
return fmt.Errorf("update %T %s failed: %w", vertex.Obj, klog.KObj(vertex.Obj), err)
}
b.emitEvent(vertex.Obj, reason, model.UPDATE)
return nil
Expand All @@ -299,8 +300,8 @@ func (b *PlanBuilder) patchObject(ctx context.Context, vertex *model.ObjectVerte
err = b.cli.Patch(ctx, vertex.Obj, patch, clientOption(vertex))
reason = "SuccessfulPatch"
}
if err != nil && !apierrors.IsNotFound(err) {
return err
if err != nil {
return fmt.Errorf("patch %T %s failed: %w", vertex.Obj, klog.KObj(vertex.Obj), err)
}
b.emitEvent(vertex.Obj, reason, model.PATCH)
return nil
Expand All @@ -314,14 +315,14 @@ func (b *PlanBuilder) deleteObject(ctx context.Context, vertex *model.ObjectVert
if len(finalizer) > 0 && controllerutil.RemoveFinalizer(vertex.Obj, finalizer) {
err := b.cli.Update(ctx, vertex.Obj, clientOption(vertex))
if err != nil && !apierrors.IsNotFound(err) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

b.transCtx.logger.Error(err, fmt.Sprintf("delete %T error: %s", vertex.Obj, vertex.Obj.GetName()))
return err
b.transCtx.logger.Error(err, fmt.Sprintf("delete %T error: %s", vertex.Obj, klog.KObj(vertex.Obj)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove it.

return fmt.Errorf("delete %T %s failed: %w", vertex.Obj, klog.KObj(vertex.Obj), err)
}
}
if !model.IsObjectDeleting(vertex.Obj) {
err := b.cli.Delete(ctx, vertex.Obj, clientOption(vertex))
if err != nil && !apierrors.IsNotFound(err) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

return err
return fmt.Errorf("delete %T %s failed: %w", vertex.Obj, klog.KObj(vertex.Obj), err)
}
b.emitEvent(vertex.Obj, "SuccessfulDelete", model.DELETE)
}
Expand Down
Loading