Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix endless recursion when a workload uses the same name as its owner. #3615

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ items:
- version: 2.18.5
date: (TBD)
notes:
- type: bugfix
title: Fix bug in workload cache, causing endless recursion when a workload uses the same name as its owner.
body: >-
The workload cache was keyed by name and namespace, but not by kind, so a workload named the same as its
owner workload would be found using the same key. This led to the workload finding itself when looking up
its owner, which in turn resulted in an endless recursion when searching for the topmost owner.
- type: bugfix
title: FailedScheduling events mentioning node availability considered fatal when waiting for agent to arrive.
body: >-
Expand Down
3 changes: 2 additions & 1 deletion pkg/agentmap/workload_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
type workloadKey struct {
name string
namespace string
kind string
}

type workloadValue struct {
Expand Down Expand Up @@ -71,7 +72,7 @@ func (w workloadCache) gc(ctx context.Context) {

func (w workloadCache) GetWorkload(c context.Context, name, namespace, workloadKind string) (k8sapi.Workload, error) {
dlog.Debugf(c, "GetWorkload(%s,%s,%s)", name, namespace, workloadKind)
wv, _ := w.Compute(workloadKey{name: name, namespace: namespace}, func(wv workloadValue, loaded bool) (workloadValue, bool) {
wv, _ := w.Compute(workloadKey{name: name, namespace: namespace, kind: workloadKind}, func(wv workloadValue, loaded bool) (workloadValue, bool) {
now := time.Now().UnixNano()
if loaded && wv.cTime >= now-int64(w.maxAge) {
return wv, false
Expand Down
Loading