Skip to content

Commit cbcb2af

Browse files
committed
reduce unnecessary container runtime availability checks
Signed-off-by: tianya <[email protected]>
1 parent 33e17ee commit cbcb2af

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

pkg/standalone/standalone.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func Init(runtimeVersion, dashboardVersion string, dockerNetwork string, slimMod
162162
setAirGapInit(fromDir)
163163
if !slimMode {
164164
// If --slim installation is not requested, check if docker or podman or containerd is installed.
165-
if !utils.ContainerRuntimeAvailable() {
165+
if !utils.ContainerRuntimeAvailable(containerRuntime) {
166166
return fmt.Errorf("could not connect to container. %v may not be installed or running", containerRuntime)
167167
}
168168

pkg/standalone/uninstall.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func Uninstall(uninstallAll bool, dockerNetwork string, containerRuntime string,
9090
print.WarningStatusEvent(os.Stdout, "WARNING: could not delete dapr bin dir: %s", daprBinDir)
9191
}
9292

93-
if utils.ContainerRuntimeAvailable() {
93+
if utils.ContainerRuntimeAvailable(containerRuntime) {
9494
containerRuntime = strings.TrimSpace(containerRuntime)
9595
runtimeCmd := utils.GetContainerRuntimeCmd(containerRuntime)
9696
containerErrs = removeContainers(uninstallPlacementContainer, uninstallAll, dockerNetwork, runtimeCmd)

utils/utils.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,16 @@ func IsContainerdInstalled() bool {
214214
return true
215215
}
216216

217-
func ContainerRuntimeAvailable() bool {
218-
return IsDockerInstalled() || IsPodmanInstalled() || IsContainerdInstalled()
217+
func ContainerRuntimeAvailable(containerRuntime string) bool {
218+
containerRuntime = strings.TrimSpace(containerRuntime)
219+
switch ContainerRuntime(containerRuntime) {
220+
case PODMAN:
221+
return IsPodmanInstalled()
222+
case CONTAINERD:
223+
return IsContainerdInstalled()
224+
default:
225+
return IsDockerInstalled()
226+
}
219227
}
220228

221229
// IsDaprListeningOnPort checks if Dapr is litening to a given port.

0 commit comments

Comments
 (0)