Skip to content

Commit d3d9293

Browse files
Merge pull request #20831 from Luap99/remote-exec-rm
fix podman-remote exec regression with v4.8
2 parents 500da5e + 86296ff commit d3d9293

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

pkg/bindings/containers/exec.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,15 @@ func ExecStart(ctx context.Context, sessionID string, options *ExecStartOptions)
114114

115115
// ExecRemove removes a given exec session.
116116
func ExecRemove(ctx context.Context, sessionID string, options *ExecRemoveOptions) error {
117+
v := bindings.ServiceVersion(ctx)
118+
// The exec remove endpoint was added in 4.8.
119+
if v.Major < 4 || (v.Major == 4 && v.Minor < 8) {
120+
// Do no call this endpoint as it will not be supported on the server and throw an "NOT FOUND" error.
121+
return bindings.NewAPIVersionError("/exec/{id}/remove", v, "4.8.0")
122+
}
117123
if options == nil {
118124
options = new(ExecRemoveOptions)
119125
}
120-
_ = options
121126
conn, err := bindings.GetClient(ctx)
122127
if err != nil {
123128
return err

pkg/bindings/errors.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"io"
88

9+
"github.com/blang/semver/v4"
910
"github.com/containers/podman/v4/pkg/errorhandling"
1011
)
1112

@@ -61,3 +62,26 @@ func CheckResponseCode(inError error) (int, error) {
6162
return -1, errors.New("is not type ErrorModel")
6263
}
6364
}
65+
66+
type APIVersionError struct {
67+
endpoint string
68+
serverVersion *semver.Version
69+
requiredVersion string
70+
}
71+
72+
// NewAPIVersionError create bindings error when the endpoint on the server is not supported
73+
// because the version is to old.
74+
// - endpoint is the name fo the endpoint (e.g. /containers/json)
75+
// - version is the server API version
76+
// - requiredVersion is the server version need to use said endpoint
77+
func NewAPIVersionError(endpoint string, version *semver.Version, requiredVersion string) *APIVersionError {
78+
return &APIVersionError{
79+
endpoint: endpoint,
80+
serverVersion: version,
81+
requiredVersion: requiredVersion,
82+
}
83+
}
84+
85+
func (e *APIVersionError) Error() string {
86+
return fmt.Sprintf("API server version is %s, need at least %s to call %s", e.serverVersion.String(), e.requiredVersion, e.endpoint)
87+
}

pkg/domain/infra/tunnel/containers.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/containers/podman/v4/libpod/define"
1818
"github.com/containers/podman/v4/libpod/events"
1919
"github.com/containers/podman/v4/pkg/api/handlers"
20+
"github.com/containers/podman/v4/pkg/bindings"
2021
"github.com/containers/podman/v4/pkg/bindings/containers"
2122
"github.com/containers/podman/v4/pkg/bindings/images"
2223
"github.com/containers/podman/v4/pkg/domain/entities"
@@ -588,6 +589,11 @@ func (ic *ContainerEngine) ContainerExec(ctx context.Context, nameOrID string, o
588589
}
589590
defer func() {
590591
if err := containers.ExecRemove(ic.ClientCtx, sessionID, nil); err != nil {
592+
apiErr := new(bindings.APIVersionError)
593+
if errors.As(err, &apiErr) {
594+
// if the API is to old do not throw an error
595+
return
596+
}
591597
if retErr == nil {
592598
exitCode = -1
593599
retErr = err

pkg/machine/e2e/basic_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,18 @@ var _ = Describe("run basic podman commands", func() {
6262
Expect(err).ToNot(HaveOccurred())
6363
Expect(session).To(Exit(0))
6464

65+
ctrName := "test"
6566
bm := basicMachine{}
66-
runAlp, err := mb.setCmd(bm.withPodmanCommand([]string{"run", "-dt", "-p", "62544:80", "quay.io/libpod/alpine_nginx"})).run()
67+
runAlp, err := mb.setCmd(bm.withPodmanCommand([]string{"run", "-dt", "--name", ctrName, "-p", "62544:80", "quay.io/libpod/alpine_nginx"})).run()
6768
Expect(err).ToNot(HaveOccurred())
6869
Expect(runAlp).To(Exit(0))
6970
testHTTPServer("62544", false, "podman rulez")
7071

72+
// Test exec in machine scenario: https://github.com/containers/podman/issues/20821
73+
exec, err := mb.setCmd(bm.withPodmanCommand([]string{"exec", ctrName, "true"})).run()
74+
Expect(err).ToNot(HaveOccurred())
75+
Expect(exec).To(Exit(0))
76+
7177
out, err := pgrep("gvproxy")
7278
Expect(err).ToNot(HaveOccurred())
7379
Expect(out).ToNot(BeEmpty())

0 commit comments

Comments
 (0)