Fix minikube image load exits code when guest-side load fails - #23508
Fix minikube image load exits code when guest-side load fails #23508Ankit4921 wants to merge 3 commits into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Ankit4921 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Welcome @Ankit4921! |
|
Hi @Ankit4921. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
Can one of the admins verify this patch? |
|
Thanks for picking this up, and @nirs thanks for the ping. Reviewed by reading the callers on master and running the test locally. The one-line change in 1. The new test passes without exercising the bug. Running
2. This makes a documented non-fatal race fatal. c, err := config.Load(pName)
if err != nil {
// Non-fatal because it may race with profile deletion
klog.Errorf("Failed to load profile %q: %v", pName, err)
failed = append(failed, pName)plus the 3. Blast radius, for the record.
4. The user still does not learn why it failed. The issue's complaint was a silent no-op, and the new message names the machine but not the cause: return fmt.Errorf("failed to load images to: %s", strings.Join(failed, " "))The actual 5. Nit: For what it is worth on the convention question, I have applied nirs's |
This does not make sense. If you delete a profile while running other commands on the profile the other command should fail. Even if we improve this later to lock profiles during commands one of the commands will fail. |
|
Thanks for the quick turnaround on Note 1: the new test still passes without the fix.
A test that does pin the change. func TestDoLoadImagesReturnsError(t *testing.T) {
home := filepath.Join(t.TempDir(), ".minikube")
t.Setenv("MINIKUBE_HOME", home)
cc := config.ClusterConfig{
Name: "pinprofile",
KubernetesConfig: config.KubernetesConfig{ContainerRuntime: "docker"},
Nodes: []config.Node{{Name: "", ControlPlane: true}},
}
if err := config.SaveProfile("pinprofile", &cc, home); err != nil {
t.Fatalf("SaveProfile: %v", err)
}
// A machine record that exists but cannot be loaded, so Status() errors.
md := filepath.Join(home, "machines", "pinprofile")
if err := os.MkdirAll(md, 0755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(md, "config.json"), []byte("{not json"), 0644); err != nil {
t.Fatal(err)
}
err := DoLoadImages([]string{filepath.Join(home, "nope.tar")},
[]*config.Profile{{Name: "pinprofile", Config: &cc}},
"", false, &run.CommandOptions{})
if err == nil {
t.Fatal("expected DoLoadImages to return an error when a machine could not be reached, got nil")
}
}On That also exercises note 4, since the cause is now carried in the message. Note 2: I withdraw my own version of it, but this revision moved away from what nirs asked for. He wrote above that a profile deleted mid-run should fail the command. Correcting my own note 2 on scope while I am here: every caller except one passes exactly one profile ( Minor: |
|
Thanks for the detailed review. I've addressed Note 1 by rewriting TestDoLoadImages_ReturnsError with the exact pattern you proposed:
The test now passes with the fix and fails without it. The error message correctly shows: failed to load images to: pinprofile: load: filestore "pinprofile": Error getting migrated host: invalid character 'n' looking for beginning of object key string This truly exercises the production code path in DoLoadImages as you intended. Note 2 remains as a behavioral decision: whether a profile deleted mid-run should fail the command or remain non-fatal. As you noted, this is a question for @nirs and should be settled before merge. I'm ready to adjust the config.Load error handling once that decision is made. Currently it treats that race as non-fatal (continues with a warning). Updated test:- |
|
Verified the rewritten test locally, both directions.
I also ran the substitution the other way round, since a test that still passes without its input is what note 1 was about. Dropping the corrupt One thing worth writing down so the test name is not read too widely later: the Minor and non blocking: Note 2 is still for you and @nirs to settle, agreed. Nothing further from me. |

Fixes #23471