Repository navigation
Fix K3s startup failure when /dev/kmsg is missing on Linux #12184
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
Open
amitdako
wants to merge
5
commits into
testcontainers:main
Choose a base branch
from
amitdako:fix/k3s-missing-dev-kmsg
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8693297
Enable KubeletInUserNamespace feature gate in K3s when /dev/kmsg is m…
dakoamit e13e4a3
Gate KubeletInUserNamespace flag on K3s version >= 1.22
dakoamit 6825730
Ignore opaque tags and digest references when checking K3s version
dakoamit d4f587c
Parse major/minor version explicitly and exclude digest references
dakoamit 867bf57
Handle NumberFormatException for oversized version numbers
dakoamit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
modules/k3s/src/test/java/org/testcontainers/k3s/K3sContainerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| package org.testcontainers.k3s; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.testcontainers.utility.DockerImageName; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| class K3sContainerTest { | ||
|
|
||
| private static final DockerImageName SUPPORTED_IMAGE = DockerImageName.parse("rancher/k3s:v1.22.0-k3s1"); | ||
| private static final DockerImageName LEGACY_IMAGE = DockerImageName.parse("rancher/k3s:v1.21.3-k3s1"); | ||
|
|
||
| @Test | ||
| void shouldNotIncludeUserNamespaceFeatureGateByDefault() { | ||
| List<String> args = K3sContainer.buildCommandArgs(SUPPORTED_IMAGE, "localhost", false); | ||
|
|
||
| assertThat(args).containsExactly("server", "--disable=traefik", "--tls-san=localhost"); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldIncludeUserNamespaceFeatureGateWhenKmsgMissingOnLinuxForSupportedVersion() { | ||
| List<String> args = K3sContainer.buildCommandArgs(SUPPORTED_IMAGE, "localhost", true); | ||
|
|
||
| assertThat(args) | ||
| .containsExactly( | ||
| "server", | ||
| "--disable=traefik", | ||
| "--tls-san=localhost", | ||
| "--kubelet-arg=--feature-gates=KubeletInUserNamespace=true" | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldNotIncludeUserNamespaceFeatureGateForLegacyVersionEvenWhenKmsgMissing() { | ||
| List<String> args = K3sContainer.buildCommandArgs(LEGACY_IMAGE, "localhost", true); | ||
|
|
||
| assertThat(args).containsExactly("server", "--disable=traefik", "--tls-san=localhost"); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldNotIncludeUserNamespaceFeatureGateForOpaqueTag() { | ||
| DockerImageName opaqueImage = DockerImageName.parse("rancher/k3s:legacy"); | ||
| List<String> args = K3sContainer.buildCommandArgs(opaqueImage, "localhost", true); | ||
|
|
||
| assertThat(args).containsExactly("server", "--disable=traefik", "--tls-san=localhost"); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldNotIncludeUserNamespaceFeatureGateForDigestReference() { | ||
| DockerImageName digestImage = DockerImageName.parse( | ||
| "rancher/k3s@sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" | ||
| ); | ||
| List<String> args = K3sContainer.buildCommandArgs(digestImage, "localhost", true); | ||
|
|
||
| assertThat(args).containsExactly("server", "--disable=traefik", "--tls-san=localhost"); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldNotIncludeUserNamespaceFeatureGateForLegacyVersionWithoutPatch() { | ||
| DockerImageName legacyMinorOnly = DockerImageName.parse("rancher/k3s:v1.21-k3s1"); | ||
| List<String> args = K3sContainer.buildCommandArgs(legacyMinorOnly, "localhost", true); | ||
|
|
||
| assertThat(args).containsExactly("server", "--disable=traefik", "--tls-san=localhost"); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldNotIncludeUserNamespaceFeatureGateForTaggedDigestReference() { | ||
| DockerImageName taggedDigestImage = DockerImageName.parse( | ||
| "rancher/k3s:v1.22.0-k3s1@sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" | ||
| ); | ||
| List<String> args = K3sContainer.buildCommandArgs(taggedDigestImage, "localhost", true); | ||
|
|
||
| assertThat(args).containsExactly("server", "--disable=traefik", "--tls-san=localhost"); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldNotThrowOrIncludeGateForOversizedVersionNumbers() { | ||
| DockerImageName oversizedImage = DockerImageName.parse("rancher/k3s:202611240001.0"); | ||
| List<String> args = K3sContainer.buildCommandArgs(oversizedImage, "localhost", true); | ||
|
|
||
| assertThat(args).containsExactly("server", "--disable=traefik", "--tls-san=localhost"); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep the kubelet feature gate consistent with the image that starts.
The gate is added at construction, based on the image passed to the constructor. The inherited
setDockerImageNamechanges only the image. It does not update the stored command.K3sContainerdoes not overrideconfigure()or recompute the command at start. A container built withrancher/k3s:v1.22.0-k3s1and then changed torancher/k3s:v1.21.3-k3s1can start the legacy image with--kubelet-arg=--feature-gates=KubeletInUserNamespace=true. The legacy kubelet can reject that unknown gate, so startup can fail.Derive the feature gate from the final image before startup, or keep it in sync when the image changes. Preserve any command that the caller set explicitly.