fix(podman): ensure initial env type matches container runtime [r8s-98] (#12259)

pull/12273/head
Ali 2024-09-30 09:16:24 +13:00 committed by GitHub
parent 32e94d4e4e
commit da010f3d08
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 32 additions and 1 deletions

View File

@ -769,6 +769,7 @@
"GpuUseList": null,
"HealthyContainerCount": 0,
"ImageCount": 9,
"IsPodman": false,
"NodeCount": 0,
"RunningContainerCount": 5,
"ServiceCount": 0,

View File

@ -267,6 +267,17 @@ func snapshotVersion(snapshot *portainer.DockerSnapshot, cli *client.Client) err
}
snapshot.SnapshotRaw.Version = version
snapshot.IsPodman = isPodman(version)
return nil
}
// isPodman checks if the version is for Podman by checking if any of the components contain "podman".
// If it's podman, a component name should be "Podman Engine"
func isPodman(version types.Version) bool {
for _, component := range version.Components {
if strings.Contains(strings.ToLower(component.Name), "podman") {
return true
}
}
return false
}

View File

@ -219,6 +219,10 @@ func (service *Service) snapshotDockerEndpoint(endpoint *portainer.Endpoint) err
return err
}
if err := validateContainerEngineCompatibility(endpoint, dockerSnapshot); err != nil {
return err
}
if dockerSnapshot != nil {
snapshot := &portainer.Snapshot{EndpointID: endpoint.ID, Docker: dockerSnapshot}
@ -228,6 +232,20 @@ func (service *Service) snapshotDockerEndpoint(endpoint *portainer.Endpoint) err
return nil
}
func validateContainerEngineCompatibility(endpoint *portainer.Endpoint, dockerSnapshot *portainer.DockerSnapshot) error {
if endpoint.ContainerEngine == portainer.ContainerEngineDocker && dockerSnapshot.IsPodman {
err := errors.New("the Docker environment option doesn't support Podman environments. Please select the Podman option instead.")
log.Error().Err(err).Str("endpoint", endpoint.Name).Msg(err.Error())
return err
}
if endpoint.ContainerEngine == portainer.ContainerEnginePodman && !dockerSnapshot.IsPodman {
err := errors.New("the Podman environment option doesn't support Docker environments. Please select the Docker option instead.")
log.Error().Err(err).Str("endpoint", endpoint.Name).Msg(err.Error())
return err
}
return nil
}
func (service *Service) startSnapshotLoop() {
ticker := time.NewTicker(time.Duration(service.snapshotIntervalInSeconds) * time.Second)

View File

@ -214,6 +214,7 @@ type (
NodeCount int `json:"NodeCount"`
GpuUseAll bool `json:"GpuUseAll"`
GpuUseList []string `json:"GpuUseList"`
IsPodman bool `json:"IsPodman"`
}
// DockerContainerSnapshot is an extent of Docker's Container struct