Lossy map functions
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
まず、controller-runtime における MapFunc と EnqueueRequestsFromMapFunc の定義、およびその周辺の EventHandler の動作を読んでください。リンクされた使用例と、フォールトトレラントなマッピング設計について合意された議論を確認してください。プロジェクトがマッピングエラーに対する方針を決定し、それに対応する実装とテストを備えていることが完了の条件であり、提案された回避策だけでは不十分です。
索引モデルが issue の本文から書いたものです。
説明
Preface
This relates to a conversation I brought up at the community meeting on 2022-09-08, @camilamacedo86 and @jmrodri suggested I create an issue so we can discuss it further.
Background
Currently in controller-runtime we have the following tools:
type MapFunc func(client.Object) []reconcile.Request
func EnqueueRequestsFromMapFunc(fn MapFunc) EventHandler {
return &enqueueRequestsFromMapFunc{
toRequests: fn,
}
}
With these it's possible to express a Watch() on one source.Kind which enqueues objects of another kind by some arbitrary relation:
ctrl.NewControllerManagedBy(mgr).Watches(
&source.Kind{Type: &customapi.Tree},
handler.EnqueueRequestsFromMapFunc(r.mapFruitsFromTree),
)
Now ideally you use metav1.ObjectReference when dealing with relationships between objects, however it can sometimes be the case that you need to use the API client or some other utility that may produce an error to map the related objects, e.g.:
func (r *myReconciler) mapFruitsFromTree(tree client.Object) []reconcile.Request {
var fruits customapi.FruitList
if err := r.client.List(context.Background(), &fruits); err != nil {
r.log.WithError(err).Error("error listing fruits")
return nil
}
var req []reconcile.Request
for _, fruit := range fruits.Items {
if isRelated(tree, fruit) {
req = append(req, reconcile.Request{
NamespacedName: types.NamespacedName{
Namespace: fruit.Namespace,
Name: fruit.Name,
},
})
}
}
return req
}
In these cases it would appear there is effectively no provisions to handle error conditions.
This kind of implementation and use case is not uncommon. I was able to find several examples of notable open source projects which are using it this way:
- https://github.com/projectcontour/contour/blob/2e758465348d8ebc32b037fbc5ce899e36cf036f/internal/controller/gateway.go#L124
- https://github.com/kumahq/kuma/blob/abd89b44c5ee3bf5b57c13d7379b3c2b15ed5aba/pkg/plugins/runtime/k8s/controllers/configmap_controller.go#L100
- https://github.com/cert-manager/cert-manager/blob/e82c72cff03dda703ca918d32ab11f719edfcd88/pkg/controller/cainjector/indexers.go#L40
- https://github.com/Kong/kubernetes-ingress-controller/blob/185f9d7c842869179dda844e6a28926468657b7f/internal/controllers/gateway/gateway_controller.go#L178
Problem
The EnqueueRequestsFromMapFunc generator for EventHandlers has no concept of handling errors that may occur when making the mapping. As such in the example above and all the links provided for projects which are doing this that process is currently "lossy": that is to say, it appears the machinery could effectively end up dropping an enqueued object from the queue if a failure occurred during the mapping process.
For a specific example using the Tree and Fruit sample above: if the object listing produces an error (e.g. performed at a time when the API server is having trouble and cache can't be used) this failure means that the Tree object is consumed from the queue but the related objects don't get enqueued. This would cause the resource state to become "stuck" and this wont heal without adding some other mechanism to re-queue it, or some unrelated action to re-trigger it.
Exploring Solutions
The purpose of this issue is to ask for community guidance on an existing or new provision to support this kind of mapping in a manner that is fault tolerant and can heal from an error.
Some of the workarounds that I have conceived of are:
- using object references as mentioned above (wont work in all cases)
- some fallback process which would actively re-enqueue all relevant objects (messy, costly)
- watching a custom backup
source.Channelwhere objects are re-enqueued in an implementation-specific manner (clunky)
So far I think the third option there might be the most effective strategy with what we have today, but ideally what I would like to see is the ability to cleanly trigger a re-queue from within the mapping function as part of the function return. I would very much appreciate community feedback on this.
- 主要言語
- Go
- スター
- 3k
- フォーク
- 1.3k
- 平均マージ
- 1日 7時間
- マージ済み PR(30日)
- 48
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
kubernetes-sigs/controller-runtime のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
kubernetes-sigs/controller-runtime#3704 ·
メンテナーはふだん 1 日以内に返信
-
lifecycle/rotten
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
kubernetes-sigs/controller-runtime#3537 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
Read-your-writes consistency is not applied to unstructured objects written with Update or Patch対応中かも @7616e5a9c573ffb221843a498885ab0f が 1 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 25/100
kubernetes-sigs/controller-runtime#3702 ·
メンテナーはふだん 1 日以内に返信
-
Client and DynamicRESTMapper keep a kind's old scope after its CRD is recreated with a different `scope`対応中かも @AdamMagued が 1 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
kubernetes-sigs/controller-runtime#3671 ·
メンテナーはふだん 1 日以内に返信
-
ReadYourWrite doesn't correctly deal with mutating requests removing the last finalizer対応中かも @AdamMagued が 1 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 28/100
kubernetes-sigs/controller-runtime#3670 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
kubernetes-sigs/controller-runtime の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
OneBusAway/watchdog#470 ·
メンテナーはふだん 1 日以内に返信
-
area: session
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
charmbracelet/crush#4484 ·
メンテナーはふだん 1 日以内に返信
-
[Resource]: Hearthオープンresource-submission validation-passed
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
hesreallyhim/awesome-claude-code#3713 · コメント 1 件 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
expr-lang/expr#1037 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
provider-key submission
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
opentofu/registry#6740 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信