Repository navigation
cover external bootc status changes #264
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
Merged
alicefr
merged 2 commits into
bootc-dev:main
from
HarshwardhanPatil07:test/e2e-external-bootc-status-change
Oct 30, 2026
+142
−6
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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
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,131 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package e2e | ||
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
| "os/exec" | ||
| "strings" | ||
| "testing" | ||
| "time" | ||
|
|
||
| . "github.com/onsi/gomega" | ||
| corev1 "k8s.io/api/core/v1" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
|
|
||
| bootcv1alpha1 "github.com/bootc-dev/bootc-operator/api/v1alpha1" | ||
| "github.com/bootc-dev/bootc-operator/internal/daemon" | ||
| "github.com/bootc-dev/bootc-operator/test/e2e/e2eutil" | ||
| testutil "github.com/bootc-dev/bootc-operator/test/util" | ||
| ) | ||
|
|
||
| // TestExternalBootcStatusChange verifies that an external host operation is | ||
| // reflected in BootcNode status through fsnotify, without a spec change or | ||
| // daemon restart triggering reconciliation. | ||
| func TestExternalBootcStatusChange(t *testing.T) { | ||
| e2eutil.Providers(t, "bink") | ||
| t.Parallel() | ||
| g := NewWithT(t) | ||
| g.SetDefaultEventuallyTimeout(pollTimeout) | ||
| g.SetDefaultEventuallyPollingInterval(pollInterval) | ||
| env := e2eutil.New(t) | ||
| workerCreationStart := time.Now() | ||
| nodeName := env.AddNode(t) | ||
| ctx, cancelTest := context.WithTimeout(context.Background(), 10*time.Minute) | ||
| defer cancelTest() | ||
|
|
||
| // Keep the desired image equal to the booted image so the daemon itself | ||
| // has no staging work. Pausing also prevents new reboot slots. | ||
| pool := env.NewPool( | ||
| "external-status", | ||
| env.NodeImageDigestedPullSpec(), | ||
| testutil.WithPaused(true), | ||
| ) | ||
| g.Expect(env.Client.Create(ctx, pool)).To(Succeed()) | ||
| testutil.WaitForNodeIdle(t, g, ctx, env.Client, nodeName, 3*time.Minute, | ||
| HaveField("Booted", imageMatchesDigest(env.NodeImageDigest())), | ||
| HaveField("Staged", BeNil()), | ||
| ) | ||
|
|
||
| var before bootcv1alpha1.BootcNode | ||
| g.Expect(env.Client.Get(ctx, client.ObjectKey{Name: nodeName}, &before)).To(Succeed()) | ||
| pods, err := testutil.DaemonPodsOnNode(ctx, env.Client, nodeName)() | ||
| g.Expect(err).NotTo(HaveOccurred()) | ||
| g.Expect(pods).To(HaveLen(1)) | ||
| pod := pods[0] | ||
| g.Expect(pod.Status.ContainerStatuses).To(ConsistOf(HaveField("RestartCount", int32(0)))) | ||
| g.Expect(pod.Spec.Containers).To(HaveLen(1)) | ||
| g.Expect(append(pod.Spec.Containers[0].Command, pod.Spec.Containers[0].Args...)). | ||
| NotTo(ContainElement(ContainSubstring("bootc-poll-interval")), | ||
| "the test relies on the daemon's default polling interval") | ||
|
|
||
| const stageUnit = "bootc-e2e-external-switch.service" | ||
| // Killing kubectl does not stop a transient service on the host. Run this | ||
| // cleanup before the harness gathers logs and removes the worker, with a | ||
| // fresh context so a failed or timed-out test can still stop the service. | ||
| t.Cleanup(func() { | ||
| cleanupCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | ||
| defer cancel() | ||
| run := func(args ...string) ([]byte, error) { | ||
| base := []string{ | ||
| "--kubeconfig", os.Getenv("KUBECONFIG"), "-n", pod.Namespace, | ||
| "exec", pod.Name, "-c", "daemon", "--", | ||
| "nsenter", "--target", "1", "--mount", "--pid", "--cgroup", | ||
| "--setuid", "0", "--setgid", "0", "--env", "--", "systemctl", | ||
| } | ||
| return exec.CommandContext(cleanupCtx, "kubectl", append(base, args...)...). | ||
| CombinedOutput() | ||
| } | ||
| if out, err := run("stop", stageUnit); err != nil { | ||
| // --collect removes a completed unit; stopping it then reports an | ||
| // error. Ignore only that case, preserving transport/stop failures. | ||
| state, stateErr := run("show", stageUnit, "--property=LoadState", "--value") | ||
| if stateErr != nil || strings.TrimSpace(string(state)) != "not-found" { | ||
| t.Errorf("stopping external staging unit: %s: %v (load state: %s, %v)", | ||
| out, err, state, stateErr) | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| // Use a separate unit from the daemon's bootc-operator-switch.service. | ||
| // Enter the host environment as the daemon does, avoiding container env | ||
| // and SELinux restrictions on running bootc directly inside the pod. | ||
| stageCtx, cancel := context.WithTimeout(ctx, 5*time.Minute) | ||
| defer cancel() | ||
| execOnNode(t, g, env, stageCtx, nodeName, | ||
| "nsenter", "--target", "1", "--mount", "--pid", "--cgroup", | ||
| "--setuid", "0", "--setgid", "0", "--env", "--", | ||
| "systemd-run", "--wait", "--collect", "--unit="+stageUnit, | ||
| "--property=RuntimeMaxSec=240s", "--property=TimeoutStopSec=15s", | ||
| "bootc", "switch", env.NodeImageUpdateDigestedPullSpec(), | ||
| ) | ||
|
|
||
| // This is well below the daemon's default fallback polling interval. | ||
| observationCtx, cancelObservation := context.WithTimeout(ctx, 30*time.Second) | ||
| defer cancelObservation() | ||
| testutil.WaitForNodeIdle(t, g, observationCtx, env.Client, nodeName, 30*time.Second, | ||
| HaveField("Booted", imageMatchesDigest(env.NodeImageDigest())), | ||
| HaveField("Staged", imageMatchesDigest(env.NodeImageUpdateDigest())), | ||
| ) | ||
| g.Expect(observationCtx.Err()). | ||
| NotTo(HaveOccurred(), "status must be observed within 30 seconds") | ||
|
|
||
| // Fallback polling waits for the default interval after watcher startup. | ||
| // This bound starts before the worker exists and uses the runner's clock, | ||
| // so a fallback poll cannot account for the observed status update. | ||
| g.Expect(time.Since(workerCreationStart)).To(BeNumerically("<", daemon.DefaultPollInterval), | ||
| "status must be observed before the first possible fallback poll") | ||
|
|
||
| var after bootcv1alpha1.BootcNode | ||
| g.Expect(env.Client.Get(ctx, client.ObjectKey{Name: nodeName}, &after)).To(Succeed()) | ||
| g.Expect(after.UID).To(Equal(before.UID)) | ||
| g.Expect(after.Generation). | ||
| To(Equal(before.Generation), "the BootcNode spec must remain unchanged") | ||
|
|
||
| var currentPod corev1.Pod | ||
| g.Expect(env.Client.Get(ctx, client.ObjectKeyFromObject(&pod), ¤tPod)).To(Succeed()) | ||
| g.Expect(currentPod.UID).To(Equal(pod.UID)) | ||
| g.Expect(currentPod.Status.ContainerStatuses).To(ConsistOf(HaveField("RestartCount", int32(0))), | ||
| "a daemon restart must not supply a fresh startup status read") | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.