Skip to content

cmd, pkg/podman: Turn Container into an interface and make podman.InspectContainer() return a Container - #1490

Merged
debarshiray merged 2 commits into
containers:mainfrom
debarshiray:wip/rishi/cmd-pkg-podman-turn-container-interface
May 17, 2024
Merged

debarshiray merged 2 commits into
containers:mainfrom
debarshiray:wip/rishi/cmd-pkg-podman-turn-container-interface

Conversation

@debarshiray

@debarshiray debarshiray commented May 14, 2024 •

Copy link
Copy Markdown
Member

No description provided.

@debarshiray
debarshiray requested a review from martymichal as a code owner May 14, 2024 15:00
@debarshiray
debarshiray force-pushed the wip/rishi/cmd-pkg-podman-turn-container-interface branch from 4cf809d to 3f0270c Compare May 14, 2024 15:01
debarshiray added a commit to debarshiray/toolbox that referenced this pull request May 14, 2024
A subsequent commit will switch to unmarshalling the JSON returned from
'podman inspect --format json --type container' directly inside
podman.InspectContainer() to limit the details within the podman
package and make it easier to write unit tests for it.  eg., it requires
tracking changes to the JSON output across different Podman versions.

Unfortunately, the JSON from 'podman inspect --type container' and
'podman ps --all' are considerably different and it will be awkward to
use the same implementation of the json.Unmarshaler interface [1] for
both.  This difference can be hidden by hiding the concrete types that
separately implement json.Unmarshaler behind a Container interface
providing access to the values parsed from the JSON.

[1] https://pkg.go.dev/encoding/json#Unmarshaler

containers#1490
@softwarefactory-delete-me

Copy link
Copy Markdown

debarshiray added a commit to debarshiray/toolbox that referenced this pull request May 14, 2024
A subsequent commit will switch to unmarshalling the JSON returned from
'podman inspect --format json --type container' directly inside
podman.InspectContainer() to confine the details within the podman
package and make it easier to write unit tests for it.  eg., it requires
tracking changes to the JSON output across different Podman versions.

Unfortunately, the JSON from 'podman inspect --type container' and
'podman ps --all' are considerably different and it will be awkward to
use the same implementation of the json.Unmarshaler interface [1] for
both.  This difference can be hidden by hiding the concrete types that
separately implement json.Unmarshaler behind a Container interface
providing access to the values parsed from the JSON.

[1] https://pkg.go.dev/encoding/json#Unmarshaler

containers#1490
@debarshiray
debarshiray force-pushed the wip/rishi/cmd-pkg-podman-turn-container-interface branch from 3f0270c to 12e5ca9 Compare May 14, 2024 17:26
@softwarefactory-delete-me

Copy link
Copy Markdown

debarshiray added a commit to debarshiray/toolbox that referenced this pull request May 15, 2024
Unmarshal the JSON from 'podman inspect --format json --type container'
directly inside podman.InspectContainer() to confine the details within
the podman package.

The JSON samples for the unit tests were taken using the default Toolbx
container on versions of Fedora that shipped a specific Podman and
Toolbx version.  This accounts for differences in the JSON output caused
by different major versions of Podman and the way different Toolbx
versions set up the containers over time.

The minimum required Podman version is 1.6.4 [1], and the Go
implementation has been encouraging users to create containers with
Toolbx version 0.0.17 or newer [2].  The versions used to collect the
JSON samples for the unit tests were chosen accordingly.  They don't
exhaustively cover all supported version combinations, but hopefully
cover enough to be useful.

[1] Commit 8e80dd5
    containers@8e80dd5db1e6f40b
    containers#1253

[2] Commit 238f245
    containers@238f2451e7d7d54a
    containers#318

containers#1490
@debarshiray debarshiray changed the title cmd, pkg/podman: Turn Container into an interface cmd, pkg/podman: Turn Container into an interface and make podman.InspectContainer() return a Container May 15, 2024
@softwarefactory-delete-me

Copy link
Copy Markdown

A subsequent commit will switch to unmarshalling the JSON returned from
'podman inspect --format json --type container' directly inside
podman.InspectContainer() to confine the details within the podman
package and make it easier to write unit tests for it.  eg., it requires
tracking changes to the JSON output across different Podman versions.

Unfortunately, the JSON from 'podman inspect --type container' and
'podman ps --all' are considerably different and it will be awkward to
use the same implementation of the json.Unmarshaler interface [1] for
both.  One option is to have two different concrete types separately
implement json.Unmarshaler to handle the differences in the JSON, and
then hiding these concrete types behind a Container interface that
provides access to the values parsed from the JSON.

[1] https://pkg.go.dev/encoding/json#Unmarshaler

containers#1490
debarshiray added a commit to debarshiray/toolbox that referenced this pull request May 16, 2024
Unmarshal the JSON from 'podman inspect --format json --type container'
directly inside podman.InspectContainer() to confine the details within
the podman package.

The JSON samples for the unit tests were taken using the default Toolbx
container on versions of Fedora that shipped a specific Podman and
Toolbx version.  This accounts for differences in the JSON caused by
different major versions of Podman and the way different Toolbx versions
set up the containers.

One exception was Fedora 28, which had Podman 1.1.2 and Toolbx 0.0.9,
which is the last Toolbx version before 'toolbox init-container' became
the entry point for all Toolbx containers [1].  However, the default
Toolbx image is no longer available from registry.fedoraproject.org.
Hence, the image for Fedora 29 was used.

The minimum required Podman version is 1.6.4 [2], and the Go
implementation has been encouraging users to create containers with
Toolbx version 0.0.17 or newer [3].  The versions used to collect the
JSON samples for the unit tests were chosen accordingly.  They don't
exhaustively cover all possible supported and unsupported version
combinations, but hopefully enough to be useful.

[1] Commit 8b84b5e
    containers@8b84b5e4604921fa
    https://github.com/debarshiray/toolbox/pull/160

[2] Commit 8e80dd5
    containers@8e80dd5db1e6f40b
    containers#1253

[3] Commit 238f245
    containers@238f2451e7d7d54a
    containers#318

containers#1490
@debarshiray
debarshiray force-pushed the wip/rishi/cmd-pkg-podman-turn-container-interface branch from 7093f09 to 41dc88c Compare May 16, 2024 08:44
@softwarefactory-delete-me

Copy link
Copy Markdown

debarshiray added a commit to debarshiray/toolbox that referenced this pull request May 16, 2024
Unmarshal the JSON from 'podman inspect --format json --type container'
directly inside podman.InspectContainer() to confine the details within
the podman package.

The JSON samples for the unit tests were taken using the default Toolbx
container on versions of Fedora that shipped a specific Podman and
Toolbx version.  This accounts for differences in the JSON caused by
different major versions of Podman and the way different Toolbx versions
set up the containers.

One exception was Fedora 28, which had Podman 1.1.2 and Toolbx 0.0.9,
which is the last Toolbx version before 'toolbox init-container' became
the entry point for all Toolbx containers [1].  However, the default
Toolbx image is no longer available from registry.fedoraproject.org.
Hence, the image for Fedora 29 was used.

The minimum required Podman version is 1.6.4 [2], and the Go
implementation has been encouraging users to create containers with
Toolbx version 0.0.17 or newer [3].  The versions used to collect the
JSON samples for the unit tests were chosen accordingly.  They don't
exhaustively cover all possible supported and unsupported version
combinations, but hopefully enough to be useful.

[1] Commit 8b84b5e
    containers@8b84b5e4604921fa
    https://github.com/debarshiray/toolbox/pull/160

[2] Commit 8e80dd5
    containers@8e80dd5db1e6f40b
    containers#1253

[3] Commit 238f245
    containers@238f2451e7d7d54a
    containers#318

containers#1490
debarshiray added a commit to debarshiray/toolbox that referenced this pull request May 16, 2024
Unmarshal the JSON from 'podman inspect --format json --type container'
directly inside podman.InspectContainer() to confine the details within
the podman package.

The JSON samples for the unit tests were taken using the default Toolbx
container on versions of Fedora that shipped a specific Podman and
Toolbx version.  This accounts for differences in the JSON caused by
different major versions of Podman and the way different Toolbx versions
set up the containers.

One exception was Fedora 28, which had Podman 1.1.2 and Toolbx 0.0.9,
which is the last Toolbx version before 'toolbox init-container' became
the entry point for all Toolbx containers [1].  However, the default
Toolbx image is no longer available from registry.fedoraproject.org.
Hence, the image for Fedora 29 was used.

The minimum required Podman version is 1.6.4 [2], and the Go
implementation has been encouraging users to create containers with
Toolbx version 0.0.17 or newer [3].  The versions used to collect the
JSON samples for the unit tests were chosen accordingly.  They don't
exhaustively cover all possible supported and unsupported version
combinations, but hopefully enough to be useful.

[1] Commit 8b84b5e
    containers@8b84b5e4604921fa
    https://github.com/debarshiray/toolbox/pull/160

[2] Commit 8e80dd5
    containers@8e80dd5db1e6f40b
    containers#1253

[3] Commit 238f245
    containers@238f2451e7d7d54a
    containers#318

containers#1490
@debarshiray
debarshiray force-pushed the wip/rishi/cmd-pkg-podman-turn-container-interface branch from 41dc88c to 7464c2b Compare May 16, 2024 15:32
@debarshiray

debarshiray commented May 16, 2024 •

Copy link
Copy Markdown
Member Author

Build failed. https://softwarefactory-project.io/zuul/t/local/buildset/a8171a7bb00347b581d0e7336e4373ce

❌ unit-test-migration-path-for-coreos-toolbox FAILURE in 3m 35s

Let's try to silence this:

centos-9-stream | : 				"        \"type\": \"bind\"," +
centos-9-stream | : 				"        \"source\": \"/etc/profile.d/toolbox.sh\"," +
centos-9-stream | : 				"        \"options\": [" +
centos-9-stream | > 				"          \"ro\"," +
centos-9-stream | : 				"          \"rbind\"," +
centos-9-stream | : 				"          \"rprivate\"" +
centos-9-stream | : 				"        ]" +
centos-9-stream | /home/zuul-worker/src/github.com/containers/toolbox/src/pkg/podman/containerInspect_test.go:72: ro ==> to, row, rob, rod, roe, rot

@softwarefactory-delete-me

Copy link
Copy Markdown

Unmarshal the JSON from 'podman inspect --format json --type container'
directly inside podman.InspectContainer() to confine the details within
the podman package.

The JSON samples for the unit tests were taken using the default Toolbx
container on versions of Fedora that shipped a specific Podman and
Toolbx version.  This accounts for differences in the JSON caused by
different major versions of Podman and the way different Toolbx versions
set up the containers.

One exception was Fedora 28, which had Podman 1.1.2 and Toolbx 0.0.9,
which was the last Toolbx version before 'toolbox init-container' became
the entry point for all Toolbx containers [1].  However, the default
Toolbx image is no longer available from registry.fedoraproject.org.
Hence, the image for Fedora 29 was used.

The minimum required Podman version is 1.6.4 [2], and the Go
implementation has been encouraging users to create containers with
Toolbx version 0.0.17 or newer [3].  The versions used to collect the
JSON samples for the unit tests were chosen accordingly.  They don't
exhaustively cover all possible supported and unsupported version
combinations, but hopefully enough to be useful.

[1] Commit 8b84b5e
    containers@8b84b5e4604921fa
    https://github.com/debarshiray/toolbox/pull/160

[2] Commit 8e80dd5
    containers@8e80dd5db1e6f40b
    containers#1253

[3] Commit 238f245
    containers@238f2451e7d7d54a
    containers#318

containers#1490
@debarshiray
debarshiray force-pushed the wip/rishi/cmd-pkg-podman-turn-container-interface branch from 7464c2b to ec7eb59 Compare May 16, 2024 18:07
@softwarefactory-delete-me

Copy link
Copy Markdown

@debarshiray
debarshiray merged commit ec7eb59 into containers:main May 17, 2024
@debarshiray
debarshiray deleted the wip/rishi/cmd-pkg-podman-turn-container-interface branch May 17, 2024 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant