update logic to purge the cache, update the message when the environment can't be reached (#10298)

pull/10300/head
Matt Hook 2023-09-12 13:52:09 +12:00 committed by GitHub
parent 4c16594a25
commit 291625959b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 7 deletions

View File

@ -89,6 +89,8 @@ func (handler *Handler) endpointUpdate(w http.ResponseWriter, r *http.Request) *
return httperror.InternalServerError("Unable to find an environment with the specified identifier inside the database", err)
}
updateEndpointProxy := shouldReloadTLSConfiguration(endpoint, &payload)
if payload.Name != nil {
name := *payload.Name
isUnique, err := handler.isNameUnique(name, endpoint.ID)
@ -104,8 +106,9 @@ func (handler *Handler) endpointUpdate(w http.ResponseWriter, r *http.Request) *
}
if payload.URL != nil {
if payload.URL != nil && *payload.URL != endpoint.URL {
endpoint.URL = *payload.URL
updateEndpointProxy = true
}
if payload.PublicURL != nil {
@ -179,6 +182,8 @@ func (handler *Handler) endpointUpdate(w http.ResponseWriter, r *http.Request) *
}
if endpoint.Type == portainer.AzureEnvironment {
updateEndpointProxy = true
credentials := endpoint.AzureCredentials
if payload.AzureApplicationID != nil {
credentials.ApplicationID = *payload.AzureApplicationID
@ -247,10 +252,7 @@ func (handler *Handler) endpointUpdate(w http.ResponseWriter, r *http.Request) *
}
}
if (payload.URL != nil && *payload.URL != endpoint.URL) ||
(payload.TLS != nil && endpoint.TLSConfig.TLS != *payload.TLS) ||
endpoint.Type == portainer.AzureEnvironment ||
shouldReloadTLSConfiguration(endpoint, &payload) {
if updateEndpointProxy {
handler.ProxyManager.DeleteEndpointProxy(endpoint.ID)
_, err = handler.ProxyManager.CreateAndRegisterEndpointProxy(endpoint)
if err != nil {
@ -291,6 +293,12 @@ func (handler *Handler) endpointUpdate(w http.ResponseWriter, r *http.Request) *
}
func shouldReloadTLSConfiguration(endpoint *portainer.Endpoint, payload *endpointUpdatePayload) bool {
// If we change anything in the tls config then we need to reload the proxy
if payload.TLS != nil && endpoint.TLSConfig.TLS != *payload.TLS {
return true
}
// When updating Docker API environment, as long as TLS is true and TLSSkipVerify is false,
// we assume that new TLS files have been uploaded and we need to reload the TLS configuration.
if endpoint.Type != portainer.DockerEnvironment ||

View File

@ -34,7 +34,7 @@ angular.module('portainer.docker', ['portainer.app', reactModule]).config([
endpoint.Status = status;
if (status === EnvironmentStatus.Down) {
throw new Error('Environment is unreachable.');
throw new Error(`The environment named ${endpoint.Name} is unreachable.`);
}
await StateManager.updateEndpointState(endpoint);

View File

@ -53,7 +53,7 @@ angular.module('portainer.kubernetes', ['portainer.app', registriesModule, custo
try {
await getSelfSubjectAccessReview(endpoint.Id, 'default');
} catch (e) {
throw new Error('Environment is unreachable.');
throw new Error(`The environment named ${endpoint.Name} is unreachable.`);
}
} catch (e) {
let params = {};