fix(api): skip guessing env when there is no env in DB (#12238)

pull/12227/head
LP B 2024-09-20 22:56:41 +02:00 committed by GitHub
parent 6f84317e7a
commit 80f53ed6ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 3 deletions

View File

@ -76,12 +76,17 @@ func guessLocalEnvironment(dataStore dataservices.DataStore) (*portainer.Endpoin
endpoints, err := dataStore.Endpoint().Endpoints() endpoints, err := dataStore.Endpoint().Endpoints()
if err != nil { if err != nil {
return nil, "", fmt.Errorf("failed to retrieve endpoints: %w", err) return nil, "", fmt.Errorf("failed to retrieve environments: %w", err)
}
// skip guessing when there is no endpoints registered in DB
if len(endpoints) == 0 {
return nil, "", nil
} }
endpointTypes, ok := platformToEndpointType[platform] endpointTypes, ok := platformToEndpointType[platform]
if !ok { if !ok {
return nil, "", errors.New("failed to determine endpoint type") return nil, "", errors.New("failed to determine environment type")
} }
for _, endpoint := range endpoints { for _, endpoint := range endpoints {
@ -97,7 +102,7 @@ func guessLocalEnvironment(dataStore dataservices.DataStore) (*portainer.Endpoin
} }
} }
return nil, "", errors.New("failed to find local endpoint") return nil, "", errors.New("failed to find local environment")
} }
func checkDockerEnvTypeForUpgrade(environment *portainer.Endpoint) ContainerPlatform { func checkDockerEnvTypeForUpgrade(environment *portainer.Endpoint) ContainerPlatform {