From 80f53ed6ece5a9478dcbdee78ccafa248c0153a2 Mon Sep 17 00:00:00 2001 From: LP B Date: Fri, 20 Sep 2024 22:56:41 +0200 Subject: [PATCH] fix(api): skip guessing env when there is no env in DB (#12238) --- api/platform/service.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/api/platform/service.go b/api/platform/service.go index c8efade7a..42f751545 100644 --- a/api/platform/service.go +++ b/api/platform/service.go @@ -76,12 +76,17 @@ func guessLocalEnvironment(dataStore dataservices.DataStore) (*portainer.Endpoin endpoints, err := dataStore.Endpoint().Endpoints() 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] if !ok { - return nil, "", errors.New("failed to determine endpoint type") + return nil, "", errors.New("failed to determine environment type") } 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 {