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

Aperta
#945 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
go
Ambito
api, backend

Direzione di ricerca

Individua i punti di ingresso For, Owns e Watches di Builder's e le implementazioni corrispondenti di ForOption, OwnsOption e WatchesOption. Confronta il modo in cui ciascun metodo ApplyTo gestisce più opzioni, quindi verifica tramite i test pertinenti del repository che i predicati di ogni opzione fornita vengano mantenuti invece di essere sovrascritti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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...)
}
Lingua principale
Go
Stelle
3k
Fork
1.3k
Merge medio
1g 7h
PR unite (30g)
48

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di kubernetes-sigs/controller-runtime

Tutte le issue di kubernetes-sigs/controller-runtime

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.