cybozu-go / accurate

Kubernetes controller for multi-tenancy. It propagates resources between namespaces accurately and allows tenant users to create/delete sub-namespaces.
https://cybozu-go.github.io/accurate/
Apache License 2.0
34 stars 5 forks source link

fix: should ignore create errors when namespace terminating #133

Closed erikgb closed 1 month ago

erikgb commented 1 month ago

This is fixing a log-spam issue in busy clusters. Accurate should just ignore namespace terminating errors on create. If not, the logs are filled with annoying errors like this (example):

{"level":"error","ts":"2024-06-04T11:22:32Z","msg":"failed to handle deleted object","controller":"rolebinding","controllerGroup":"rbac.authorization.k8s.io","controllerKind":"RoleBinding","RoleBinding":{"name":"gitops-admins","namespace":"strm-rev-r-5d7d3652a0"},"namespace":"strm-rev-r-5d7d3652a0","name":"gitops-admins","reconcileID":"f5ab2512-5558-4d2b-92e0-cba652a84eca","error":"failed to re-create strm-rev-r-5d7d3652a0/gitops-admins: rolebindings.rbac.authorization.k8s.io \"gitops-admins\" is forbidden: unable to create new content in namespace strm-rev-r-5d7d3652a0 because it is being terminated","stacktrace":"github.com/cybozu-go/accurate/controllers.(*PropagateController).Reconcile\n\t/work/controllers/propagate.go:90\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile\n\t/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.17.0/pkg/internal/controller/controller.go:119\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler\n\t/go/pkg/mod/sigs.k8s...

I created a simple helper to make this code a bit more readable. Hope you like it! It might be possible to make further improvements with even more consistent error handling.