Skip to content

fix kubernetes waiting containers cache index#60284

Merged
tigrato merged 3 commits intomasterfrom
tigrato/fix-kube-containers
Oct 16, 2025
Merged

fix kubernetes waiting containers cache index#60284
tigrato merged 3 commits intomasterfrom
tigrato/fix-kube-containers

Conversation

@tigrato
Copy link
Copy Markdown
Contributor

@tigrato tigrato commented Oct 15, 2025

This PR resolves an issue with the Kubernetes ephemeral containers cache used by Kubernetes agents, where the keys used in the index and get methods did not match.

This mismatch caused the get method to fail with not found error, preventing the debug container from being created.

Fixes #60283

Changelog: Fixed an issue that caused Kubernetes debug containers to fail with a “container not valid” error when launched by a user requiring moderated sessions.

This PR resolves an issue with the Kubernetes ephemeral containers cache
used by Kubernetes agents, where the keys used in the index and get methods
did not match.

This mismatch caused the get method to fail with not found error, preventing the
debug container from being created.

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
Comment thread lib/cache/kube_test.go
Copy link
Copy Markdown
Contributor

@camscale camscale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thought in the comments - I'll leave it up to you if you feel it's worthwhile.

Comment thread lib/cache/kube.go Outdated
map[kubeWaitingContainerIndex]func(*kubewaitingcontainerv1.KubernetesWaitingContainer) string{
kubeWaitingContainerNameIndex: func(u *kubewaitingcontainerv1.KubernetesWaitingContainer) string {
return u.GetMetadata().GetName()
return u.GetSpec().GetUsername() + "/" + u.GetSpec().GetCluster() + "/" + u.GetSpec().GetNamespace() + "/" + u.GetSpec().GetPodName() + "/" + u.GetMetadata().GetName()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This same construction is done in two other places - ListKubernetesWaitingContainers() which is identical and GetKubernetesWaitingContainer() which constructs the cache key from a request and not a resource.

At the very least, can this be factored out into a separate function that is used here and in ListKubernetesWaitingContainers()? It would be nice if it could also be used by GetKubernetesWaitingContainer(), which something like this poorly named code snippet does:

type kubernetesWaitingContainerCacheKeyFieldGetter interface {
        GetUsername() string
        GetCluster() string
        GetNamespace() string
        GetPodName() string
}

func kubernetesWaitingContainerCacheKey(c kubernetesWaitingContainerCacheKeyFieldGetter, containerName string) string {
        return c.GetUsername() + "/" + c.GetCluster() + "/" + c.GetNamespace() + "/" + c.GetPodName() + "/" + containerName
}

This would help prevent them diverging in future causing this issue again.

Then again, perhaps with the tests there now, this isn't necessary - if they do diverge again, the tests should pick it up.

@public-teleport-github-review-bot public-teleport-github-review-bot bot removed the request for review from fspmarshall October 16, 2025 01:08
@tigrato tigrato enabled auto-merge October 16, 2025 07:30
@tigrato tigrato added this pull request to the merge queue Oct 16, 2025
Merged via the queue into master with commit c14ae33 Oct 16, 2025
44 checks passed
@tigrato tigrato deleted the tigrato/fix-kube-containers branch October 16, 2025 08:11
@backport-bot-workflows
Copy link
Copy Markdown
Contributor

@tigrato See the table below for backport results.

Branch Result
branch/v16 Failed
branch/v17 Failed
branch/v18 Create PR

mmcallister pushed a commit that referenced this pull request Nov 6, 2025
* fix kubernetes waiting containers cache index

This PR resolves an issue with the Kubernetes ephemeral containers cache
used by Kubernetes agents, where the keys used in the index and get methods
did not match.

This mismatch caused the get method to fail with not found error, preventing the
debug container from being created.

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>

* fix issue with headerTransform

* unify cache keys

---------

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
mmcallister pushed a commit that referenced this pull request Nov 19, 2025
* fix kubernetes waiting containers cache index

This PR resolves an issue with the Kubernetes ephemeral containers cache
used by Kubernetes agents, where the keys used in the index and get methods
did not match.

This mismatch caused the get method to fail with not found error, preventing the
debug container from being created.

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>

* fix issue with headerTransform

* unify cache keys

---------

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
mmcallister pushed a commit that referenced this pull request Nov 20, 2025
* fix kubernetes waiting containers cache index

This PR resolves an issue with the Kubernetes ephemeral containers cache
used by Kubernetes agents, where the keys used in the index and get methods
did not match.

This mismatch caused the get method to fail with not found error, preventing the
debug container from being created.

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>

* fix issue with headerTransform

* unify cache keys

---------

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kubernetes ephemeral containers broken in v18

3 participants