Skip to content

Commit

Permalink
Make the timeout configurable via the 'PODMAN_CMD_INIT_TIMEOUT' env var
Browse files Browse the repository at this point in the history
This will allow setting a different value for environments like
in GitHub where the Podman client would take slightly more time to return
(I guess because of we are running a lot of Podman commands in parallel?).
  • Loading branch information
rm3l committed May 10, 2023
1 parent c81610d commit 4cabec2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
1 change: 1 addition & 0 deletions docs/website/docs/overview/configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ Options here are mostly used for debugging and testing `odo` behavior.
|-------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|--------------------------------------------|
| `PODMAN_CMD` | The command executed to run the local podman binary. `podman` by default | v2.4.2 | `podman` |
| `DOCKER_CMD` | The command executed to run the local docker binary. `docker` by default | v2.4.2 | `docker` |
| `PODMAN_CMD_INIT_TIMEOUT` | Timeout for initializing the Podman client. `1s` by default | v3.11.0 | `5s` |
| `ODO_LOG_LEVEL` | Useful for setting a log level to be used by `odo` commands. Takes precedence over the `-v` flag. | v1.0.2 | 3 |
| `ODO_DISABLE_TELEMETRY` | Useful for disabling [telemetry collection](https://github.com/redhat-developer/odo/blob/main/USAGE_DATA.md). **Deprecated in v3.2.0**. Use `ODO_TRACKING_CONSENT` instead. | v2.1.0 | `true` |
| `GLOBALODOCONFIG` | Useful for setting a different location of global preference file `preference.yaml`. | v0.0.19 | `~/.config/odo/preference.yaml` |
Expand Down
30 changes: 16 additions & 14 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@ package config

import (
"context"
"time"

"github.com/sethvargo/go-envconfig"
)

type Configuration struct {
DevfileProxy *string `env:"DEVFILE_PROXY,noinit"`
DockerCmd string `env:"DOCKER_CMD,default=docker"`
Globalodoconfig *string `env:"GLOBALODOCONFIG,noinit"`
OdoDebugTelemetryFile *string `env:"ODO_DEBUG_TELEMETRY_FILE,noinit"`
OdoDisableTelemetry *bool `env:"ODO_DISABLE_TELEMETRY,noinit"`
OdoLogLevel *int `env:"ODO_LOG_LEVEL,noinit"`
OdoTrackingConsent *string `env:"ODO_TRACKING_CONSENT,noinit"`
PodmanCmd string `env:"PODMAN_CMD,default=podman"`
TelemetryCaller string `env:"TELEMETRY_CALLER,default="`
OdoExperimentalMode bool `env:"ODO_EXPERIMENTAL_MODE,default=false"`
PushImages bool `env:"ODO_PUSH_IMAGES,default=true"`
OdoContainerBackendGlobalArgs []string `env:"ODO_CONTAINER_BACKEND_GLOBAL_ARGS,noinit,delimiter=;"`
OdoImageBuildArgs []string `env:"ODO_IMAGE_BUILD_ARGS,noinit,delimiter=;"`
OdoContainerRunArgs []string `env:"ODO_CONTAINER_RUN_ARGS,noinit,delimiter=;"`
DevfileProxy *string `env:"DEVFILE_PROXY,noinit"`
DockerCmd string `env:"DOCKER_CMD,default=docker"`
Globalodoconfig *string `env:"GLOBALODOCONFIG,noinit"`
OdoDebugTelemetryFile *string `env:"ODO_DEBUG_TELEMETRY_FILE,noinit"`
OdoDisableTelemetry *bool `env:"ODO_DISABLE_TELEMETRY,noinit"`
OdoLogLevel *int `env:"ODO_LOG_LEVEL,noinit"`
OdoTrackingConsent *string `env:"ODO_TRACKING_CONSENT,noinit"`
PodmanCmd string `env:"PODMAN_CMD,default=podman"`
PodmanCmdInitTimeout time.Duration `env:"PODMAN_CMD_INIT_TIMEOUT,default=1s"`
TelemetryCaller string `env:"TELEMETRY_CALLER,default="`
OdoExperimentalMode bool `env:"ODO_EXPERIMENTAL_MODE,default=false"`
PushImages bool `env:"ODO_PUSH_IMAGES,default=true"`
OdoContainerBackendGlobalArgs []string `env:"ODO_CONTAINER_BACKEND_GLOBAL_ARGS,noinit,delimiter=;"`
OdoImageBuildArgs []string `env:"ODO_IMAGE_BUILD_ARGS,noinit,delimiter=;"`
OdoContainerRunArgs []string `env:"ODO_CONTAINER_RUN_ARGS,noinit,delimiter=;"`
}

// GetConfiguration initializes a Configuration for odo by using the system environment.
Expand Down
3 changes: 3 additions & 0 deletions pkg/podman/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os/exec"
"strings"
"time"

envcontext "github.com/redhat-developer/odo/pkg/config/context"
"github.com/redhat-developer/odo/pkg/platform"
Expand All @@ -18,6 +19,7 @@ import (

type PodmanCli struct {
podmanCmd string
podmanCmdInitTimeout time.Duration
containerRunGlobalExtraArgs []string
containerRunExtraArgs []string
}
Expand All @@ -30,6 +32,7 @@ func NewPodmanCli(ctx context.Context) (*PodmanCli, error) {
// Check if podman is available in the system
cli := &PodmanCli{
podmanCmd: envcontext.GetEnvConfig(ctx).PodmanCmd,
podmanCmdInitTimeout: envcontext.GetEnvConfig(ctx).PodmanCmdInitTimeout,
containerRunGlobalExtraArgs: envcontext.GetEnvConfig(ctx).OdoContainerBackendGlobalArgs,
containerRunExtraArgs: envcontext.GetEnvConfig(ctx).OdoContainerRunArgs,
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/podman/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ type SystemVersionReport struct {
// Version returns the version of the Podman client.
func (o *PodmanCli) Version(ctx context.Context) (SystemVersionReport, error) {
// Because Version is used at the very beginning of odo, when resolving and injecting dependencies (for commands that might require the Podman client),
// it is expected to return in a timely manny (hence this timeout of 1 second).
// it is expected to return in a timely manner (hence this configurable timeout).
// This is to avoid situations like the one described in https://github.com/redhat-developer/odo/issues/6575
// (where a podman that takes too long to respond affects the "odo dev" command, even if the user did not intend to use the Podman platform).
ctxWithTimeout, cancel := context.WithTimeout(ctx, 1*time.Second)
// (where a podman CLI that takes too long to respond affects the "odo dev" command, even if the user did not intend to use the Podman platform).
ctxWithTimeout, cancel := context.WithTimeout(ctx, o.podmanCmdInitTimeout)
defer cancel()

cmd := exec.CommandContext(ctxWithTimeout, o.podmanCmd, "version", "--format", "json")
Expand Down Expand Up @@ -84,7 +84,7 @@ func (o *PodmanCli) Version(ctx context.Context) (SystemVersionReport, error) {
if ctxErr != nil {
msg := "error"
if errors.Is(ctxErr, context.DeadlineExceeded) {
msg = "timeout"
msg = fmt.Sprintf("timeout (%s)", o.podmanCmdInitTimeout.Round(time.Second).String())
}
wErr = fmt.Errorf("%s while waiting for Podman version: %s: %w", msg, ctxErr, wErr)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cmd_dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ echo "$@"
Expect(err).ShouldNot(HaveOccurred())
defer devSession.Kill()

Expect(string(stderrBytes)).Should(ContainSubstring("timeout while waiting for Podman version"))
Expect(string(stderrBytes)).Should(MatchRegexp("timeout \\([^()]+\\) while waiting for Podman version"))
})

When("using a default namespace", func() {
Expand Down

0 comments on commit 4cabec2

Please sign in to comment.