fix a few bugs with kube waiting container backend (#39690)

This commit is contained in:
Andrew LeFevre
2024-03-21 17:42:53 +00:00
committed by GitHub
parent b88251a278
commit ca51fb4700
2 changed files with 24 additions and 4 deletions
+12
View File
@@ -113,6 +113,7 @@ type testPack struct {
userLoginStates services.UserLoginStates
secReports services.SecReports
accessLists services.AccessLists
kubeWaitingContainers services.KubeWaitingContainer
}
// testFuncs are functions to support testing an object in a cache.
@@ -288,6 +289,12 @@ func newPackWithoutCache(dir string, opts ...packOption) (*testPack, error) {
}
p.accessLists = accessListsSvc
kubeWaitingContSvc, err := local.NewKubeWaitingContainerService(p.backend)
if err != nil {
return nil, trace.Wrap(err)
}
p.kubeWaitingContainers = kubeWaitingContSvc
return p, nil
}
@@ -329,6 +336,7 @@ func newPack(dir string, setupConfig func(c Config) Config, opts ...packOption)
UserLoginStates: p.userLoginStates,
SecReports: p.secReports,
AccessLists: p.accessLists,
KubeWaitingContainers: p.kubeWaitingContainers,
MaxRetryPeriod: 200 * time.Millisecond,
EventsC: p.eventsC,
}))
@@ -727,6 +735,7 @@ func TestCompletenessInit(t *testing.T) {
UserLoginStates: p.userLoginStates,
SecReports: p.secReports,
AccessLists: p.accessLists,
KubeWaitingContainers: p.kubeWaitingContainers,
MaxRetryPeriod: 200 * time.Millisecond,
EventsC: p.eventsC,
}))
@@ -799,6 +808,7 @@ func TestCompletenessReset(t *testing.T) {
UserLoginStates: p.userLoginStates,
SecReports: p.secReports,
AccessLists: p.accessLists,
KubeWaitingContainers: p.kubeWaitingContainers,
MaxRetryPeriod: 200 * time.Millisecond,
EventsC: p.eventsC,
}))
@@ -983,6 +993,7 @@ func TestListResources_NodesTTLVariant(t *testing.T) {
UserLoginStates: p.userLoginStates,
SecReports: p.secReports,
AccessLists: p.accessLists,
KubeWaitingContainers: p.kubeWaitingContainers,
MaxRetryPeriod: 200 * time.Millisecond,
EventsC: p.eventsC,
neverOK: true, // ensure reads are never healthy
@@ -1066,6 +1077,7 @@ func initStrategy(t *testing.T) {
UserLoginStates: p.userLoginStates,
SecReports: p.secReports,
AccessLists: p.accessLists,
KubeWaitingContainers: p.kubeWaitingContainers,
MaxRetryPeriod: 200 * time.Millisecond,
EventsC: p.eventsC,
}))
+12 -4
View File
@@ -144,10 +144,18 @@ func (g *genericCollection[T, R, _]) processEvent(ctx context.Context, event typ
}
}
case types.OpPut:
resource, ok := event.Resource.(T)
var resource T
var ok bool
switch r := event.Resource.(type) {
case types.Resource153Unwrapper:
resource, ok = r.Unwrap().(T)
default:
resource, ok = event.Resource.(T)
}
if !ok {
return trace.BadParameter("unexpected type %T", event.Resource)
}
if err := g.exec.upsert(ctx, g.cache, resource); err != nil {
return trace.Wrap(err)
}
@@ -658,8 +666,8 @@ func setupCollections(c *Cache, watches []types.WatchKind) (*cacheCollections, e
collections.accessListReviews = &genericCollection[*accesslist.Review, accessListReviewsGetter, accessListReviewExecutor]{cache: c, watch: watch}
collections.byKind[resourceKind] = collections.accessListReviews
case types.KindKubeWaitingContainer:
if c.Presence == nil {
return nil, trace.BadParameter("missing parameter Presence")
if c.KubeWaitingContainers == nil {
return nil, trace.BadParameter("missing parameter KubeWaitingContainers")
}
collections.kubeWaitingContainers = &genericCollection[*kubewaitingcontainerpb.KubernetesWaitingContainer, kubernetesWaitingContainerGetter, kubeWaitingContainerExecutor]{
cache: c,
@@ -2100,7 +2108,7 @@ func (kubeWaitingContainerExecutor) getAll(ctx context.Context, cache *Cache, lo
allConts []*kubewaitingcontainerpb.KubernetesWaitingContainer
)
for {
conts, nextKey, err := cache.kubeWaitingContsCache.ListKubernetesWaitingContainers(ctx, 0, startKey)
conts, nextKey, err := cache.KubeWaitingContainers.ListKubernetesWaitingContainers(ctx, 0, startKey)
if err != nil {
return nil, trace.Wrap(err)
}