Builder's `For`, `Owns` and `Watches` methods overwrite multiple options

オープン
#945 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
go
領域
api, backend

調査の方向性

Builder's の For、Owns、Watches のエントリポイントと、対応する ForOption、OwnsOption、WatchesOption の実装を特定します。各 ApplyTo メソッドが複数のオプションをどのように処理するかを比較し、そのうえで、リポジトリの関連するテストを使って、指定されたすべてのオプションの述語が上書きされずに保持されることを確認します。

索引モデルが issue の本文から書いたものです。

説明

lifecycle/frozen

The Builder struct's For, Owns and Watches methods all follow the same pattern of having a variable number of modifying Option structs as the final parameter to the method. Here is the code for the For method:

// For defines the type of Object being *reconciled*, and configures the ControllerManagedBy to respond to create / delete /
// update events by *reconciling the object*.
// This is the equivalent of calling
// Watches(&source.Kind{Type: apiType}, &handler.EnqueueRequestForObject{})
func (blder *Builder) For(object runtime.Object, opts ...ForOption) *Builder {
	input := ForInput{object: object}
	for _, opt := range opts {
		opt.ApplyToFor(&input)
	}

	blder.forInput = input
	return blder
}

The problem with the above is if you call For with more than one ForOption, the builder's forInput member ends up containing only the predicates contained in the last ForOption. The reason is because the ForOption.ApplyToFor assigns the ForOption.predicates member to the supplied ForInput.predicates member (note: ForOption is an interface that is implemented by the Predicates struct):

// ApplyToFor applies this configuration to the given ForInput options.
func (w Predicates) ApplyToFor(opts *ForInput) {
	opts.predicates = w.predicates
}

The solution is to append w.predicates to the supplied opt.predicates instead of assigning/overwriting the value of opts.predicates:

// ApplyToFor applies this configuration to the given ForInput options.
func (w Predicates) ApplyToFor(opts *ForInput) {
	opts.predicates = append(opts.predicates, w.predicates...)
}
主要言語
Go
スター
3k
フォーク
1.3k
平均マージ
1日 7時間
マージ済み PR(30日)
48

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

kubernetes-sigs/controller-runtime のほかの issue

kubernetes-sigs/controller-runtime の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。