Revision e6567463ac838605f3386dd10f2c5a244706d47c authored by David Bimmler on 26 February 2024, 13:58:22 UTC, committed by Louis DeLosSantos on 27 February 2024, 14:34:49 UTC
The test assumed that the initial list and watch of the underlying k8s
reflector would complete before the 'Get' query would establish, but
that wasn't guaranteed.

Instead, explicitly synchronise for this case.

Fixes: 0554ca6811 (statedb/reflector: Add Kubernetes to StateDB reflector)

Signed-off-by: David Bimmler <david.bimmler@isovalent.com>
1 parent 1eb12e0
Raw File
watcher_cache.go
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium

package kvstore

type watchState struct {
	deletionMark bool
}

type watcherCache map[string]watchState

func (wc watcherCache) Exists(key []byte) bool {
	if _, ok := wc[string(key)]; ok {
		return true
	}

	return false
}

func (wc watcherCache) RemoveDeleted(f func(string)) {
	for k, localKey := range wc {
		if localKey.deletionMark {
			f(k)
			delete(wc, k)
		}
	}
}

func (wc watcherCache) MarkAllForDeletion() {
	for k := range wc {
		wc[k] = watchState{deletionMark: true}
	}
}

func (wc watcherCache) MarkInUse(key []byte) {
	wc[string(key)] = watchState{deletionMark: false}
}

func (wc watcherCache) RemoveKey(key []byte) {
	delete(wc, string(key))
}
back to top