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 for podman machine init not creating necessary JSON file when an ignition-path is passed #24321

Merged
merged 1 commit into from
Nov 14, 2024

Conversation

gaufde
Copy link

@gaufde gaufde commented Oct 20, 2024

This bug was first described in #23544, and @cheesesashimi did most of the detective work to find the error!

Signed-off-by: Graceson Aufderheide [email protected]

Fixes #23544

Does this PR introduce a user-facing change?

None

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR

}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := Init(tt.args.opts, tt.args.mp); (err != nil) != tt.wantErr {
Copy link
Member

Choose a reason for hiding this comment

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

This is not an acceptable unit test, this is actually creating a real machine in my home dir. A unit test should be independent of any host specifics.

please add such a test to pkg/machine/e2e which runs the actual podman cli on every OS.

Copy link
Author

Choose a reason for hiding this comment

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

@Luap99

Thanks for the feedback! That makes a lot of sense. It looks to me like I can just add a test to pkg/machine/e2e/init_test.go.

However, I'm having trouble running the tests on my machine. Is that expected since seccomp is not available on Mac OS and it is trying to run every OS?

Here is what I am seeing when I try to run machine init with volume in pkg/machine/e2e/init_test.go.

make remoteintegration FOCUS="machine init with volume"
Makefile:152: invalid `override' directive
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build  -ldflags '-X github.com/containers/podman/v5/libpod/define.gitCommit=24c178f39b0bca2c558a803309a93c8bcaef5109-dirty -X github.com/containers/podman/v5/libpod/define.buildInfo=1729524947 -X github.com/containers/podman/v5/libpod/config._installPrefix=/usr/local -X github.com/containers/podman/v5/libpod/config._etcDir=/etc -X github.com/containers/podman/v5/pkg/systemd/quadlet._binDir=/usr/local/bin -X github.com/containers/common/pkg/config.additionalHelperBinariesDir= ' -tags " exclude_graphdriver_btrfs btrfs_noversion   exclude_graphdriver_devicemapper seccomp " -o test/checkseccomp/checkseccomp ./test/checkseccomp
# github.com/containers/podman/v5/test/checkseccomp
test/checkseccomp/checkseccomp.go:13:17: undefined: unix.Prctl
test/checkseccomp/checkseccomp.go:13:28: undefined: unix.PR_GET_SECCOMP
test/checkseccomp/checkseccomp.go:15:18: undefined: unix.Prctl
test/checkseccomp/checkseccomp.go:15:29: undefined: unix.PR_SET_SECCOMP
test/checkseccomp/checkseccomp.go:15:50: undefined: unix.SECCOMP_MODE_FILTER
make: *** [test/checkseccomp/checkseccomp] Error 1

In the meantime, I have modified my test like so:

It("machine init with ignition path", func() {
		skipIfWSL("Ignition is not compatible with WSL machines since they are not based on Fedora CoreOS")

		tmpDir, err := os.MkdirTemp("", "")
		Expect(err).ToNot(HaveOccurred())
		tmpFile, err := os.CreateTemp(tmpDir, "test-ignition-*.ign")
		Expect(err).ToNot(HaveOccurred())

		// Test that all files are written when creating a machine. See https://github.com/containers/podman/issues/23544
		mockIgnitionContent := `{"ignition":{"version":"3.4.0"},"passwd":{"users":[{"name":"core"}]}}`

		_, err = tmpFile.WriteString(mockIgnitionContent)
		Expect(err).ToNot(HaveOccurred())

		err = tmpFile.Close()
		Expect(err).ToNot(HaveOccurred())

		defer func() { _ = utils.GuardedRemoveAll(tmpDir) }()

		name := randomString()
		i := new(initMachine)
		session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath).withIgnitionPath(tmpFile.Name()).withNow()).run()
		Expect(err).ToNot(HaveOccurred())
		Expect(session).To(Exit(0))

		configDir := filepath.Join(testDir, ".config", "containers", "podman", "machine", testProvider.VMType().String())
		fileExtensions := []string{".lock", ".json", ".ign"}

		for _, ext := range fileExtensions {
			filename := filepath.Join(configDir, fmt.Sprintf("%s%s", name, ext))

			_, err := os.Stat(filename)
			Expect(err).ToNot(HaveOccurred())
		}
	})

Does this look more appropriate? If so, I can edit my PR to include this despite not being able to run all the tests.

Copy link
Member

Choose a reason for hiding this comment

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

make localintegration/remoteintegration are for test/e2e which only work on linux.

you need make localmachine for pkg/machine/e2e which should work on macos and linux.

Test wise it looks about right, you should move the defer func() { _ = utils.GuardedRemoveAll(tmpDir) }() direcyl after you created the dir otherwise it is leaked if any of the matches before that fail.

Also I think there is a bit of a testing gap in that sense if podman were to ignore the ignition file argument the test would still pass. To make this solid maybe add some custom random username that would not exists otherwise or create a random filem something like that. Then have the test do a podman machine ssh id RandomUserName to ensure yes the correct ignition was indeed used

Copy link
Author

Choose a reason for hiding this comment

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

you need make localmachine for pkg/machine/e2e which should work on macos and linux.

Ah, this definitely works better. However, it looks like I still have some debugging since I'm getting two errors that look like they might be related to each other:

failed to set TMPDIR: "/var/folders/7m/z_f3vkmd6t30fhydp4z513gw0000gn/T/ path length should be less than 22 characters"
Running Suite: Podman Machine tests - /Users/gaufde/GolandProjects/podman/pkg/machine/e2e
=========================================================================================
Random Seed: 1729527567

Will run 1 of 62 specs
------------------------------
[BeforeSuite] 
/Users/gaufde/GolandProjects/podman/pkg/machine/e2e/machine_test.go:56
  > Enter [BeforeSuite] TOP-LEVEL - /Users/gaufde/GolandProjects/podman/pkg/machine/e2e/machine_test.go:56 @ 10/21/24 09:19:30.188
  [FAILED] failed to pull disk: "invalid machine file path"
  In [BeforeSuite] at: /Users/gaufde/GolandProjects/podman/pkg/machine/e2e/machine_test.go:73 @ 10/21/24 09:19:30.189

I'll have to debug this later when I get a bit more time.

To make this solid maybe add some custom random username that would not exists otherwise or create a random filem something like that. Then have the test do a podman machine ssh id RandomUserName to ensure yes the correct ignition was indeed used

Won't ssh only work if the custom ignition file has the ready.service unit and the ssh key for Podman machine? I agree that this would be a better test, but I'm not exactly sure how I would go about adding those into the mockIgnitionContent. At first glance, I'm guessing I would have to use CreateReadyUnitFile from pkg/machine/ignition/ready.go and addConnection from pkg/machine/connection/connection.go.

@baude originally mentioned in #23544 (comment):

...we should be writing a JSON and we should write a regression test as such with your PR (just init and check the json is there, we dont have to start it).

Anyways, I'm willing to give it a shot, but a bit more guidance might be helpful for me.

Copy link
Member

Choose a reason for hiding this comment

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

ah right I forget about the arbitrary low socket path length limits in the macos kernel this is trying trying to catch.

use TMPDIR=/tmp make localmachine, that is how I used them before IIRC

if booting is to complicated then sure, I am not to familiar with the ignition requirements.

Copy link
Author

Choose a reason for hiding this comment

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

That was it! Though I had to use TMPDIR=/private/tmp make localmachine to match the directory mounted on podman machine.

Copy link
Author

Choose a reason for hiding this comment

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

@Luap99 I have implemented the new test. Rather than trying to build a valid ignition file that would allow the VM to start, I decided to simply check that the ignition file passed to Podman is the same as the one that Podman writes for the machine. It doesn't test that the ignition works, but it should check that Podman passes the ignition through properly. Let me know what you think!

Copy link
Member

Choose a reason for hiding this comment

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

yeah that sounds good enough

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

Please sqash your commits into one, also you need to fix the lint errors

pkg/machine/e2e/init_test.go:253:3: commentFormatting: put a space between `//` and comment text (gocritic)
		//test that all required machine files are created
		^
pkg/machine/e2e/init_test.go:262:3: commentFormatting: put a space between `//` and comment text (gocritic)
		//enforce that the raw ignition is copied over verbatim
		^
pkg/machine/shim/host.go:203:10: unnecessary leading newline (whitespace)

^

Comment on lines 94 to 97
// The exception below is required for testing custom ignition files.
if strings.Contains(session.errorToString(), "failed to remove machines files: unable to find connection named") {
return
}
Copy link
Member

Choose a reason for hiding this comment

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

Can you file a new bug for this add a then add a FIXME: #xxx work around for custom ignition removal comment here? and replace xxx with the real github issue number

@Luap99
Copy link
Member

Luap99 commented Oct 23, 2024

Note your commit message title is to long. Generally speaking commit message lines should not exceed 72 chars and after the title should need to keep an empty line although that is not strictly enforced, but CI does enforce that the title is less than 90 chars. Also we you should add Fixes: #23544 to correctly mark this commit as fix for the issue
https://github.com/containers/podman/blob/main/CONTRIBUTING.md#describe-your-changes-in-commit-messages
This ensures that the issue is automatically closed on merge.

Another thing the DCO check is failing because your git Author fields do not match the ones in the sign of line, while I do consider your sign of valid it is best to match them, i.e. you can update the author on the commit with git commit --amend --author="Author Name <[email protected]>" of course replacing the example with your real name/mail, thanks.

@gaufde gaufde force-pushed the main branch 3 times, most recently from 0871fd8 to f0b47e8 Compare October 23, 2024 14:46
@gaufde
Copy link
Author

gaufde commented Oct 24, 2024

Note your commit message title is to long. Generally speaking commit message lines should not exceed 72 chars and after the title should need to keep an empty line although that is not strictly enforced, but CI does enforce that the title is less than 90 chars. Also we you should add Fixes: #23544 to correctly mark this commit as fix for the issue

https://github.com/containers/podman/blob/main/CONTRIBUTING.md#describe-your-changes-in-commit-messages

This ensures that the issue is automatically closed on merge.

Another thing the DCO check is failing because your git Author fields do not match the ones in the sign of line, while I do consider your sign of valid it is best to match them, i.e. you can update the author on the commit with git commit --amend --author="Author Name <[email protected]>" of course replacing the example with your real name/mail, thanks.

@Luap99 If I understood everything correctly, I believe I have fixed all these issues with my latest commit. Let me know if anything else is needed! Also, thank you for your patience while I learn how to do all of this!

@Luap99
Copy link
Member

Luap99 commented Oct 29, 2024

Your change breaks the machine tests, for some reason the volumes are no longer mounted.

The ignBuilder.Build() call must be made after mp.CreateVM(createOpts, mc, &ignBuilder) I think

@gaufde gaufde force-pushed the main branch 4 times, most recently from f85a6b9 to bef24d0 Compare October 30, 2024 08:43
@gaufde
Copy link
Author

gaufde commented Oct 30, 2024

@Luap99

I made the change as suggested, and it is definitely better than before. However, locally I'm running into a rosetta error now when running TMPDIR=/private/tmp make localmachine FOCUS="Volume ops".

~/GolandProjects/podman git:[main]
TMPDIR=/private/tmp make localmachine FOCUS="Volume ops"
Makefile:152: invalid `override' directive
# gitCommit needed by logformatter, to link to sources
/define.gitCommit=bef24d099b1f6ffad1d173b69b1d619f03be4640-dirty
/Library/Developer/CommandLineTools/usr/bin/make ginkgo-run GINKGO_PARALLEL=n TAGS="remote exclude_graphdriver_btrfs btrfs_noversion exclude_graphdriver_devicemapper containers_image_openpgp" GINKGO_FLAKE_ATTEMPTS=0 FOCUS_FILE= GINKGOWHAT=pkg/machine/e2e/.
Makefile:152: invalid `override' directive
/Library/Developer/CommandLineTools/usr/bin/make -C test/tools build/ginkgo
make[2]: `build/ginkgo' is up to date.
./test/tools/build/ginkgo version
Ginkgo Version 2.20.2
./test/tools/build/ginkgo -vv  --tags "remote exclude_graphdriver_btrfs btrfs_noversion exclude_graphdriver_devicemapper containers_image_openpgp remote" -timeout=90m --flake-attempts 0 \
                --trace --no-color \
                 \
                --focus "Volume ops" --silence-skips \
                 pkg/machine/e2e/.
Running Suite: Podman Machine tests - /Users/gaufde/GolandProjects/podman/pkg/machine/e2e
=========================================================================================
Random Seed: 1730277944

Will run 1 of 62 specs
------------------------------
[BeforeSuite] 
/Users/gaufde/GolandProjects/podman/pkg/machine/e2e/machine_test.go:56
  > Enter [BeforeSuite] TOP-LEVEL - /Users/gaufde/GolandProjects/podman/pkg/machine/e2e/machine_test.go:56 @ 10/30/24 01:45:46.519
Looking up Podman Machine image at quay.io/podman/machine-os:5.3 to create VM
Extracting compressed file: podman-machine.aarch64.applehv.raw: done  
  < Exit [BeforeSuite] TOP-LEVEL - /Users/gaufde/GolandProjects/podman/pkg/machine/e2e/machine_test.go:56 @ 10/30/24 01:45:55.98 (9.462s)
[BeforeSuite] PASSED [9.462 seconds]
------------------------------
run basic podman commands
/Users/gaufde/GolandProjects/podman/pkg/machine/e2e/basic_test.go:20
  Volume ops
  /Users/gaufde/GolandProjects/podman/pkg/machine/e2e/basic_test.go:62
  > Enter [BeforeEach] TOP-LEVEL - /Users/gaufde/GolandProjects/podman/pkg/machine/e2e/machine_test.go:181 @ 10/30/24 01:45:55.981
  < Exit [BeforeEach] TOP-LEVEL - /Users/gaufde/GolandProjects/podman/pkg/machine/e2e/machine_test.go:181 @ 10/30/24 01:45:55.981 (0s)
  > Enter [It] Volume ops - /Users/gaufde/GolandProjects/podman/pkg/machine/e2e/basic_test.go:62 @ 10/30/24 01:45:55.981
  /Users/gaufde/GolandProjects/podman/bin/darwin/podman machine init --disk-size 11 --image /private/tmp/podman-machine.aarch64.applehv.raw --now fa19ff3016ad
  Machine init complete
  Starting machine "fa19ff3016ad"

  This machine is currently configured in rootless mode. If your containers
  require root permissions (e.g. ports < 1024), or if you run into compatibility
  issues with non-podman clients, you can switch using the following command:

        podman machine set --rootful fa19ff3016ad

  API forwarding listening on: /private/tmp/podman/fa19ff3016ad-api.sock

  Another process was listening on the default Docker API socket address.
  You can still connect Docker API clients by setting DOCKER_HOST using the
  following command in your terminal session:

          export DOCKER_HOST='unix:///private/tmp/podman/fa19ff3016ad-api.sock'

  Machine "fa19ff3016ad" started successfully
  [du -ah /private/tmp/podman_test3131004645/.local/share/containers/podman/machine/applehv]
0       /private/tmp/podman_test3131004645/.local/share/containers/podman/machine/applehv/cache
128K    /private/tmp/podman_test3131004645/.local/share/containers/podman/machine/applehv/efi-bl-fa19ff3016ad
8.3G    /private/tmp/podman_test3131004645/.local/share/containers/podman/machine/applehv/fa19ff3016ad-arm64.raw
8.3G    /private/tmp/podman_test3131004645/.local/share/containers/podman/machine/applehv
  [ls -lh /private/tmp/podman_test3131004645/.local/share/containers/podman/machine/applehv]
total 8.3G
drwxr-xr-x 2 gaufde wheel   64 Oct 30 01:45 cache
-rw------- 1 gaufde wheel 128K Oct 30 01:46 efi-bl-fa19ff3016ad
-rw-r--r-- 1 gaufde wheel  11G Oct 30 01:46 fa19ff3016ad-arm64.raw
  [stat /private/tmp/podman_test3131004645/.local/share/containers/podman/machine/applehv/fa19ff3016ad-arm64.raw]
  File: /private/tmp/podman_test3131004645/.local/share/containers/podman/machine/applehv/fa19ff3016ad-arm64.raw
  Size: 11811160064     Blocks: 17294944   IO Block: 4096   regular file
Device: 1,16    Inode: 128528591   Links: 1
Access: (0644/-rw-r--r--)  Uid: (  501/  gaufde)   Gid: (    0/   wheel)
Access: 2024-10-30 01:46:21.458669151 -0700
Modify: 2024-10-30 01:46:21.398231055 -0700
Change: 2024-10-30 01:46:21.398231055 -0700
 Birth: 2024-10-30 01:45:56.062010228 -0700
  /Users/gaufde/GolandProjects/podman/bin/darwin/podman -r run -v /private/tmp/ginkgo3007358289:/test:Z quay.io/libpod/alpine_nginx ls /test/attr-test-file
  Trying to pull quay.io/libpod/alpine_nginx:latest...
  Getting image source signatures
  Copying blob sha256:d2c7362ca710ad35a846a34571a7c3450ea3cce04efcbcb4d3af276eda154ade
  Copying blob sha256:df9b9388f04ad6279a7410b85cedfdcb2208c0a003da7ab5613af71079148139
  Copying blob sha256:71895e83ea49901b7b752bbf3ca19a54148a5f4ab5fdff3dca9bcd59d44c59e3
  Copying config sha256:ecea49d99daa5bd62ebaef1338f6bc4c948bf2651b139160404f9c1c48fcd85c
  Writing manifest to image destination
  WARNING: image platform (linux/amd64) does not match the expected platform (linux/arm64)
  rosetta error: unhandled auxillary vector type 28
     [FAILED] Expected
      <int>: 133
  to match exit code:
      <int>: 0
  In [It] at: /Users/gaufde/GolandProjects/podman/pkg/machine/e2e/basic_test.go:88 @ 10/30/24 01:46:24.381

  Full Stack Trace
    github.com/containers/podman/v5/pkg/machine/e2e_test.init.func6.2()
        /Users/gaufde/GolandProjects/podman/pkg/machine/e2e/basic_test.go:88 +0x554
  < Exit [It] Volume ops - /Users/gaufde/GolandProjects/podman/pkg/machine/e2e/basic_test.go:62 @ 10/30/24 01:46:24.381 (28.4s)
  > Enter [AfterEach] TOP-LEVEL - /Users/gaufde/GolandProjects/podman/pkg/machine/e2e/machine_test.go:84 @ 10/30/24 01:46:24.381
  < Exit [AfterEach] TOP-LEVEL - /Users/gaufde/GolandProjects/podman/pkg/machine/e2e/machine_test.go:84 @ 10/30/24 01:46:24.381 (0s)
  > Enter [DeferCleanup (Each)] run basic podman commands - /Users/gaufde/GolandProjects/podman/pkg/machine/e2e/config_init_test.go:83 @ 10/30/24 01:46:24.381
/Users/gaufde/GolandProjects/podman/bin/darwin/podman machine rm --force fa19ff3016ad
  < Exit [DeferCleanup (Each)] run basic podman commands - /Users/gaufde/GolandProjects/podman/pkg/machine/e2e/config_init_test.go:83 @ 10/30/24 01:46:25.138 (756ms)
  > Enter [DeferCleanup (Each)] run basic podman commands - /Users/gaufde/GolandProjects/podman/vendor/github.com/onsi/ginkgo/v2/internal/testingtproxy/testing_t_proxy.go:153 @ 10/30/24 01:46:25.138
  < Exit [DeferCleanup (Each)] run basic podman commands - /Users/gaufde/GolandProjects/podman/vendor/github.com/onsi/ginkgo/v2/internal/testingtproxy/testing_t_proxy.go:153 @ 10/30/24 01:46:25.138 (0s)
  > Enter [DeferCleanup (Each)] TOP-LEVEL - /Users/gaufde/GolandProjects/podman/pkg/machine/e2e/machine_test.go:183 @ 10/30/24 01:46:25.138
  < Exit [DeferCleanup (Each)] TOP-LEVEL - /Users/gaufde/GolandProjects/podman/pkg/machine/e2e/machine_test.go:183 @ 10/30/24 01:46:25.14 (2ms)
• [FAILED] [29.160 seconds]
run basic podman commands
/Users/gaufde/GolandProjects/podman/pkg/machine/e2e/basic_test.go:20
  [It] Volume ops
  /Users/gaufde/GolandProjects/podman/pkg/machine/e2e/basic_test.go:62
------------------------------
[SynchronizedAfterSuite] 
/Users/gaufde/GolandProjects/podman/pkg/machine/e2e/machine_test.go:92
  > Enter [SynchronizedAfterSuite] TOP-LEVEL - /Users/gaufde/GolandProjects/podman/pkg/machine/e2e/machine_test.go:92 @ 10/30/24 01:46:25.141
  < Exit [SynchronizedAfterSuite] TOP-LEVEL - /Users/gaufde/GolandProjects/podman/pkg/machine/e2e/machine_test.go:92 @ 10/30/24 01:46:25.141 (0s)
  > Enter [SynchronizedAfterSuite] TOP-LEVEL - /Users/gaufde/GolandProjects/podman/pkg/machine/e2e/machine_test.go:92 @ 10/30/24 01:46:25.141
  run basic podman commands Volume ops          28.400365 seconds
  < Exit [SynchronizedAfterSuite] TOP-LEVEL - /Users/gaufde/GolandProjects/podman/pkg/machine/e2e/machine_test.go:92 @ 10/30/24 01:46:25.141 (0s)
[SynchronizedAfterSuite] PASSED [0.000 seconds]
------------------------------

Summarizing 1 Failure:
  [FAIL] run basic podman commands [It] Volume ops
  /Users/gaufde/GolandProjects/podman/pkg/machine/e2e/basic_test.go:88

Ran 1 of 62 Specs in 38.622 seconds
FAIL! -- 0 Passed | 1 Failed | 0 Pending | 61 Skipped
--- FAIL: TestMachine (38.62s)
FAIL

Ginkgo ran 1 suite in 40.915416625s

Test Suite Failed
make[1]: *** [ginkgo-run] Error 1
make: *** [localmachine] Error 2

Interestingly, if I revert my changes in pkg/machine/shim/host.go back to the original, I get the same rosetta error, so maybe that isn't something I introduced.

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

LGTM, for the future the "Fixes: #..." part in the commit message should be at the end of the body not the title. The title should be a short summary of the change, i.e. "fix podman machine init --ignition-path". Anyhow I am not going to block over it and make you force push again.

Restarted the last test failures as they are flakes and not related to your change.

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 30, 2024
@Luap99
Copy link
Member

Luap99 commented Oct 30, 2024

@l0rd @baude PTAL

if err != nil {
return err
if len(opts.IgnitionPath) == 0 {
err = ignBuilder.Build()
Copy link
Member

Choose a reason for hiding this comment

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

your choice but I think that the if err := ignBuilder.Build(); err != nil { syntax is cleaner here? nit

Copy link
Author

Choose a reason for hiding this comment

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

Whose choice are you referring to? I'm happy to change it, I'm just unsure if this is an internal discussion between you and @Luap99, or if I should change it.

@@ -196,30 +196,33 @@ func Init(opts machineDefine.InitOptions, mp vmconfigs.VMProvider) error {
// copy it into the conf dir
if len(opts.IgnitionPath) > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

should we just create a new function to deal with this given the more complexity here? wdyt @Luap99

Copy link
Member

Choose a reason for hiding this comment

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

The function is pretty long already so splitting it up makes sense but I would not force a community contributor to do that work. It only adds one more if/else here so I don't think it is required to rework just for that.

Copy link
Member

Choose a reason for hiding this comment

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

im cool with that

@Luap99
Copy link
Member

Luap99 commented Nov 5, 2024

machine init with ignition path
  C:/Users/Administrator/AppData/Local/cirrus-ci-build/repo[/pkg/machine/e2e/init_test.go:227](https://github.com/containers/podman/blob/bef24d099b1f6ffad1d173b69b1d619f03be4640/pkg/machine/e2e/init_test.go#L227)
  → Enter [BeforeEach] TOP-LEVEL - C:/Users/Administrator/AppData/Local/cirrus-ci-build/repo[/pkg/machine/e2e/machine_test.go:181](https://github.com/containers/podman/blob/bef24d099b1f6ffad1d173b69b1d619f03be4640/pkg/machine/e2e/machine_test.go#L181) @ 11/01/24 16:20:30.985
  ← Exit  [BeforeEach] TOP-LEVEL - C:/Users/Administrator/AppData/Local/cirrus-ci-build/repo[/pkg/machine/e2e/machine_test.go:181](https://github.com/containers/podman/blob/bef24d099b1f6ffad1d173b69b1d619f03be4640/pkg/machine/e2e/machine_test.go#L181) @ 11/01/24 16:20:30.985 (0s)
  → Enter [It] machine init with ignition path - C:/Users/Administrator/AppData/Local/cirrus-ci-build/repo[/pkg/machine/e2e/init_test.go:227](https://github.com/containers/podman/blob/bef24d099b1f6ffad1d173b69b1d619f03be4640/pkg/machine/e2e/init_test.go#L227) @ 11/01/24 16:20:30.985
  C> podman.exe machine init --disk-size 11 --ignition-path C:\Users\ADMINI~1\AppData\Local\Temp\847462015\test-ignition-3741392465.ign --image C:\Users\ADMINI~1\AppData\Local\Temp\podman-machine.x86_64.hyperv.vhdx 14fe438c3c75
  An ignition path was provided.  No SSH connection was added to Podman
  panic: runtime error: invalid memory address or nil pointer dereference
  [signal 0xc0000005 code=0x0 addr=0x0 pc=0x1546c46]

  goroutine 1 [running]:
  github.com/containers/podman/v5/pkg/machine/hyperv.HyperVStubber.CreateVM({{{{0x0, 0x0}, 0x0, 0x0, {0x0, 0x0}, 0x0}, {{0x0, 0x0}, 0x0, ...}}}, ...)
  	/var/tmp/go/src/github.com[/containers/podman/pkg/machine/hyperv/stubber.go:63](https://github.com/containers/podman/blob/bef24d099b1f6ffad1d173b69b1d619f03be4640/pkg/machine/hyperv/stubber.go#L63) +0x206
  github.com/containers/podman/v5/pkg/machine/shim.Init({0x18, 0xb, {0xc000224050, 0x4b}, {0xc0002240a0, 0x46}, {0xc00061c240, 0x2, 0x2}, 0x0, ...}, ...)
  	/var/tmp/go/src/github.com[/containers/podman/pkg/machine/shim/host.go:246](https://github.com/containers/podman/blob/bef24d099b1f6ffad1d173b69b1d619f03be4640/pkg/machine/shim/host.go#L246) +0xe08
  github.com/containers/podman/v5/cmd/podman/machine.initMachine(0x262bfe0, {0xc0003082a0, 0x1, 0x7})
  	/var/tmp/go/src/github.com[/containers/podman/cmd/podman/machine/init.go:221](https://github.com/containers/podman/blob/bef24d099b1f6ffad1d173b69b1d619f03be4640/cmd/podman/machine/init.go#L221) +0x6d8
  github.com/spf13/cobra.(*Command).execute(0x262bfe0, {0xc00022c030, 0x7, 0xd})
  	/var/tmp/go/src/github.com[/containers/podman/vendor/github.com/spf13/cobra/command.go:985](https://github.com/containers/podman/blob/bef24d099b1f6ffad1d173b69b1d619f03be4640/vendor/github.com/spf13/cobra/command.go#L985) +0xaca
  github.com/spf13/cobra.(*Command).ExecuteC(0x261f6a0)
  	/var/tmp/go/src/github.com[/containers/podman/vendor/github.com/spf13/cobra/command.go:1117](https://github.com/containers/podman/blob/bef24d099b1f6ffad1d173b69b1d619f03be4640/vendor/github.com/spf13/cobra/command.go#L1117) +0x3ff
  github.com/spf13/cobra.(*Command).Execute(...)
  	/var/tmp/go/src/github.com[/containers/podman/vendor/github.com/spf13/cobra/command.go:1041](https://github.com/containers/podman/blob/bef24d099b1f6ffad1d173b69b1d619f03be4640/vendor/github.com/spf13/cobra/command.go#L1041)
  github.com/spf13/cobra.(*Command).ExecuteContext(...)
  	/var/tmp/go/src/github.com[/containers/podman/vendor/github.com/spf13/cobra/command.go:1034](https://github.com/containers/podman/blob/bef24d099b1f6ffad1d173b69b1d619f03be4640/vendor/github.com/spf13/cobra/command.go#L1034)
  main.Execute()
  	/var/tmp/go/src/github.com[/containers/podman/cmd/podman/root.go:116](https://github.com/containers/podman/blob/bef24d099b1f6ffad1d173b69b1d619f03be4640/cmd/podman/root.go#L116) +0xb4
  main.main()
  	/var/tmp/go/src/github.com[/containers/podman/cmd/podman/main.go:61](https://github.com/containers/podman/blob/bef24d099b1f6ffad1d173b69b1d619f03be4640/cmd/podman/main.go#L61) +0x4ed

  [FAILED] Expected
      <int>: 2
  to match exit code:
      <int>: 0
  In [It] at: C:/Users/Administrator/AppData/Local/cirrus-ci-build/repo[/pkg/machine/e2e/init_test.go:249](https://github.com/containers/podman/blob/bef24d099b1f6ffad1d173b69b1d619f03be4640/pkg/machine/e2e/init_test.go#L249) @ 11/01/24 16:20:35.127

HyperV still seems to be broken
https://api.cirrus-ci.com/v1/artifact/task/5333546137550848/html/machine-hyperv-podman-windows-rootless-host-sqlite.log.html#t--podman-machine-init-machine-init-with-ignition-path--1

@gaufde
Copy link
Author

gaufde commented Nov 5, 2024

Hmm, it looks a bit different than the one I couldn't get past on my machine.

Do you think this one is related to my changes, or is it another example of that test being flaky?

Oh wait...that line is in my new test. I'll have to test it again, but I'm pretty sure the e2e tests for the test I added worked for me.

@Luap99
Copy link
Member

Luap99 commented Nov 5, 2024

@gaufde yes I restarted it a few times so it seems to fail consistently (which makes sense given it is a nil deref)

This is the hyperV test so it is only failing on windows with the hyperV hypervisor, macos and linux both pass. That is the difficult thing with machine support. I cannot really help with windows. So if you do not use windows either I can try to ask someone else to take a look.

@gaufde
Copy link
Author

gaufde commented Nov 5, 2024

So if you do not use windows either I can try to ask someone else to take a look.

That would be very helpful! I don't use windows either.

@Luap99
Copy link
Member

Luap99 commented Nov 6, 2024

@l0rd Can you look at the hyperV issue here?

@l0rd
Copy link
Member

l0rd commented Nov 6, 2024

@Luap99 Yep, I will look at it later today

@l0rd
Copy link
Member

l0rd commented Nov 7, 2024

I confirm that the new test machine init with ignition path is failing locally on my local windows as well. The error is the same invalid memory address or nil pointer dereference.

@l0rd
Copy link
Member

l0rd commented Nov 7, 2024

mc.HyperVHypervisor is nil when it tries to assign the NetworkVSock:

mc.HyperVHypervisor.NetworkVSock = *networkHVSock

Comment on lines 198 to 209
err = ignBuilder.BuildWithIgnitionFile(opts.IgnitionPath)
return err
}

err = ignBuilder.GenerateIgnitionConfig()
if err != nil {
return err
}
if err != nil {
return err
}
} else {
err = ignBuilder.GenerateIgnitionConfig()
if err != nil {
return err
}

readyIgnOpts, err := mp.PrepareIgnition(mc, &ignBuilder)
if err != nil {
return err
}
readyIgnOpts, err := mp.PrepareIgnition(mc, &ignBuilder)
if err != nil {
return err
}

readyUnitFile, err := ignition.CreateReadyUnitFile(mp.VMType(), readyIgnOpts)
if err != nil {
return err
}
readyUnitFile, err := ignition.CreateReadyUnitFile(mp.VMType(), readyIgnOpts)
if err != nil {
return err
}

readyUnit := ignition.Unit{
Enabled: ignition.BoolToPtr(true),
Name: "ready.service",
Contents: ignition.StrToPtr(readyUnitFile),
readyUnit := ignition.Unit{
Enabled: ignition.BoolToPtr(true),
Name: "ready.service",
Contents: ignition.StrToPtr(readyUnitFile),
}
ignBuilder.WithUnit(readyUnit)
}
ignBuilder.WithUnit(readyUnit)

Copy link
Member

Choose a reason for hiding this comment

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

The Hyper-V test is passing with this change

Suggested change
err = ignBuilder.BuildWithIgnitionFile(opts.IgnitionPath)
return err
}
err = ignBuilder.GenerateIgnitionConfig()
if err != nil {
return err
}
if err != nil {
return err
}
} else {
err = ignBuilder.GenerateIgnitionConfig()
if err != nil {
return err
}
readyIgnOpts, err := mp.PrepareIgnition(mc, &ignBuilder)
if err != nil {
return err
}
readyIgnOpts, err := mp.PrepareIgnition(mc, &ignBuilder)
if err != nil {
return err
}
readyUnitFile, err := ignition.CreateReadyUnitFile(mp.VMType(), readyIgnOpts)
if err != nil {
return err
}
readyUnitFile, err := ignition.CreateReadyUnitFile(mp.VMType(), readyIgnOpts)
if err != nil {
return err
}
readyUnit := ignition.Unit{
Enabled: ignition.BoolToPtr(true),
Name: "ready.service",
Contents: ignition.StrToPtr(readyUnitFile),
readyUnit := ignition.Unit{
Enabled: ignition.BoolToPtr(true),
Name: "ready.service",
Contents: ignition.StrToPtr(readyUnitFile),
}
ignBuilder.WithUnit(readyUnit)
}
ignBuilder.WithUnit(readyUnit)
err = ignBuilder.BuildWithIgnitionFile(opts.IgnitionPath)
if err != nil {
return err
}
} else {
err = ignBuilder.GenerateIgnitionConfig()
if err != nil {
return err
}
}
readyIgnOpts, err := mp.PrepareIgnition(mc, &ignBuilder)
if err != nil {
return err
}
readyUnitFile, err := ignition.CreateReadyUnitFile(mp.VMType(), readyIgnOpts)
if err != nil {
return err
}
readyUnit := ignition.Unit{
Enabled: ignition.BoolToPtr(true),
Name: "ready.service",
Contents: ignition.StrToPtr(readyUnitFile),
}
ignBuilder.WithUnit(readyUnit)

@mheon
Copy link
Member

mheon commented Nov 7, 2024

/cherry-pick v5.3

@openshift-cherrypick-robot
Copy link
Collaborator

@mheon: once the present PR merges, I will cherry-pick it on top of v5.3 in a new PR and assign it to you.

In response to this:

/cherry-pick v5.3

Instructions 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.

@baude baude added the 5.3 label Nov 7, 2024
@baude
Copy link
Member

baude commented Nov 8, 2024

we are going to cut a 5.3 release next week. if you would like this PR included, please use what was provided to fix the test failure by EOD Nov 11

@gaufde
Copy link
Author

gaufde commented Nov 11, 2024

@baude I made the suggested changes and tested them in my Mac environment. Looks like the windows test is still failing, but I'm not sure if that is the flakiness that @Luap99 mentioned before.

@baude
Copy link
Member

baude commented Nov 12, 2024

look legit to me unfortunately.

machine init with ignition path
  C:/Users/Administrator/AppData/Local/cirrus-ci-build/repo/pkg/machine/e2e/init_test.go:227
  > Enter [BeforeEach] TOP-LEVEL - C:/Users/Administrator/AppData/Local/cirrus-ci-build/repo/pkg/machine/e2e/machine_test.go:181 @ 11/11/24 22:20:35.787
  < Exit [BeforeEach] TOP-LEVEL - C:/Users/Administrator/AppData/Local/cirrus-ci-build/repo/pkg/machine/e2e/machine_test.go:181 @ 11/11/24 22:20:35.787 (0s)
  > Enter [It] machine init with ignition path - C:/Users/Administrator/AppData/Local/cirrus-ci-build/repo/pkg/machine/e2e/init_test.go:227 @ 11/11/24 22:20:35.787
  C:\Users\Administrator\AppData\Local\cirrus-ci-build\repo\bin\windows\podman.exe machine init --disk-size 11 --ignition-path C:\Users\ADMINI~1\AppData\Local\Temp\4154279865\test-ignition-839492978.ign --image C:\Users\ADMINI~1\AppData\Local\Temp\podman-machine.x86_64.hyperv.vhdx 6bea2d70eea2
  An ignition path was provided.  No SSH connection was added to Podman
  panic: runtime error: invalid memory address or nil pointer dereference
  [signal 0xc0000005 code=0x0 addr=0x0 pc=0xfd6c46]

  goroutine 1 [running]:
  github.com/containers/podman/v5/pkg/machine/hyperv.HyperVStubber.CreateVM({{{{0x0, 0x0}, 0x0, 0x0, {0x0, 0x0}, 0x0}, {{0x0, 0x0}, 0x0, ...}}}, ...)
  	/var/tmp/go/src/github.com/containers/podman/pkg/machine/hyperv/stubber.go:63 +0x206
  github.com/containers/podman/v5/pkg/machine/shim.Init({0x18, 0xb, {0xc000226050, 0x4b}, {0xc0002260a0, 0x46}, {0xc0000da460, 0x2, 0x2}, 0x0, ...}, ...)
  	/var/tmp/go/src/github.com/containers/podman/pkg/machine/shim/host.go:246 +0xe08
  github.com/containers/podman/v5/cmd/podman/machine.initMachine(0x20bbfe0, {0xc000192310, 0x1, 0x7})
  	/var/tmp/go/src/github.com/containers/podman/cmd/podman/machine/init.go:221 +0x6d8
  github.com/spf13/cobra.(*Command).execute(0x20bbfe0, {0xc00022e030, 0x7, 0xd})
  	/var/tmp/go/src/github.com/containers/podman/vendor/github.com/spf13/cobra/command.go:985 +0xaca
  github.com/spf13/cobra.(*Command).ExecuteC(0x20af6a0)
  	/var/tmp/go/src/github.com/containers/podman/vendor/github.com/spf13/cobra/command.go:1117 +0x3ff
  github.com/spf13/cobra.(*Command).Execute(...)
  	/var/tmp/go/src/github.com/containers/podman/vendor/github.com/spf13/cobra/command.go:1041
  github.com/spf13/cobra.(*Command).ExecuteContext(...)
  	/var/tmp/go/src/github.com/containers/podman/vendor/github.com/spf13/cobra/command.go:1034
  main.Execute()
  	/var/tmp/go/src/github.com/containers/podman/cmd/podman/root.go:116 +0xb4
  main.main()
  	/var/tmp/go/src/github.com/containers/podman/cmd/podman/main.go:61 +0x4ed
  [FAILED] Expected
      <int>: 2
  to match exit code:
      <int>: 0
  In [It] at: C:/Users/Administrator/AppData/Local/cirrus-ci-build/repo/pkg/machine/e2e/init_test.go:249 @ 11/11/24 22:20:40.385

  Full Stack Trace
    github.com/containers/podman/v5/pkg/machine/e2e_test.init.func10.7()
    	C:/Users/Administrator/AppData/Local/cirrus-ci-build/repo/pkg/machine/e2e/init_test.go:249 +0x3ca
  < Exit [It] machine init with ignition path - C:/Users/Administrator/AppData/Local/cirrus-ci-build/repo/pkg/machine/e2e/init_test.go:227 @ 11/11/24 22:20:40.385 (4.598s)
  > Enter [AfterEach] TOP-LEVEL - C:/Users/Administrator/AppData/Local/cirrus-ci-build/repo/pkg/machine/e2e/machine_test.go:84 @ 11/11/24 22:20:40.385
  < Exit [AfterEach] TOP-LEVEL - C:/Users/Administrator/AppData/Local/cirrus-ci-build/repo/pkg/machine/e2e/machine_test.go:84 @ 11/11/24 22:20:40.385 (0s)
  > Enter [DeferCleanup (Each)] podman machine init - C:/Users/Administrator/AppData/Local/cirrus-ci-build/repo/pkg/machine/e2e/config_init_test.go:83 @ 11/11/24 22:20:40.385
  C:\Users\Administrator\AppData\Local\cirrus-ci-build\repo\bin\windows\podman.exe machine rm --force 6bea2d70eea2
  Error: 6bea2d70eea2: VM does not exist
  < Exit [DeferCleanup (Each)] podman machine init - C:/Users/Administrator/AppData/Local/cirrus-ci-build/repo/pkg/machine/e2e/config_init_test.go:83 @ 11/11/24 22:20:40.489 (104ms)
  > Enter [DeferCleanup (Each)] TOP-LEVEL - C:/Users/Administrator/AppData/Local/cirrus-ci-build/repo/pkg/machine/e2e/machine_test.go:183 @ 11/11/24 22:20:40.489
  < Exit [DeferCleanup (Each)] TOP-LEVEL - C:/Users/Administrator/AppData/Local/cirrus-ci-build/repo/pkg/machine/e2e/machine_test.go:183 @ 11/11/24 22:20:40.643 (154ms)
+ [FAILED] [4.855 seconds]
podman machine init
C:/Users/Administrator/AppData/Local/cirrus-ci-build/repo/pkg/machine/e2e/init_test.go:22
  [It] machine init with ignition path

@gaufde
Copy link
Author

gaufde commented Nov 12, 2024

@baude I think I somehow forgot to add my changes before committing them a few days ago. I should have that fixed now. Is it a problem that 54c81be is included now for some reason? I don't think I did anything unusual when I squashed my commits together, but I'm also not that confident with VCS yet.

I'm now hoping I did everything correctly now. I was able to fix my bad rebase and do it again.

@gaufde gaufde force-pushed the main branch 2 times, most recently from 6357f37 to 76442bd Compare November 13, 2024 00:48
Fix the issue where podman machine init does not create
all the necessary machine files when ignition-path is used. Fixes: containers#23544

Signed-off-by: Graceson Aufderheide <[email protected]>
@baude
Copy link
Member

baude commented Nov 13, 2024

congrats, it passed

@baude
Copy link
Member

baude commented Nov 13, 2024

LGTM

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Nov 14, 2024
Copy link
Contributor

openshift-ci bot commented Nov 14, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gaufde, Luap99

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot bot merged commit 5dbb567 into containers:main Nov 14, 2024
82 of 83 checks passed
@openshift-cherrypick-robot
Copy link
Collaborator

@mheon: new pull request created: #24560

In response to this:

/cherry-pick v5.3

Instructions 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5.3 approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. machine release-note-none
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Podman Machine VM config does not get created when an Ignition file is provided
6 participants