fix(kube): improve error handling EE-7199 (#11974)

pull/11980/head
andres-portainer 5 months ago committed by GitHub
parent d2b0eacbf5
commit 1170004097
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -79,21 +79,26 @@ func InitialIngressClassDetection(endpoint *portainer.Endpoint, endpointService
if endpoint.Kubernetes.Flags.IsServerIngressClassDetected { if endpoint.Kubernetes.Flags.IsServerIngressClassDetected {
return return
} }
defer func() { defer func() {
endpoint.Kubernetes.Flags.IsServerIngressClassDetected = true endpoint.Kubernetes.Flags.IsServerIngressClassDetected = true
endpointService.UpdateEndpoint(
endpoint.ID, if err := endpointService.UpdateEndpoint(endpoint.ID, endpoint); err != nil {
endpoint, log.Debug().Err(err).Msg("unable to store found IngressClasses inside the database")
) }
}() }()
cli, err := factory.GetKubeClient(endpoint) cli, err := factory.GetKubeClient(endpoint)
if err != nil { if err != nil {
log.Debug().Err(err).Msg("unable to create kubernetes client for ingress class detection") log.Debug().Err(err).Msg("unable to create kubernetes client for ingress class detection")
return return
} }
controllers, err := cli.GetIngressControllers() controllers, err := cli.GetIngressControllers()
if err != nil { if err != nil {
log.Debug().Err(err).Msg("failed to fetch ingressclasses") log.Debug().Err(err).Msg("failed to fetch ingressclasses")
return return
} }
@ -106,42 +111,34 @@ func InitialIngressClassDetection(endpoint *portainer.Endpoint, endpointService
} }
endpoint.Kubernetes.Configuration.IngressClasses = updatedClasses endpoint.Kubernetes.Configuration.IngressClasses = updatedClasses
err = endpointService.UpdateEndpoint(
endpoint.ID,
endpoint,
)
if err != nil {
log.Debug().Err(err).Msg("unable to store found IngressClasses inside the database")
return
}
} }
func InitialMetricsDetection(endpoint *portainer.Endpoint, endpointService dataservices.EndpointService, factory *cli.ClientFactory) { func InitialMetricsDetection(endpoint *portainer.Endpoint, endpointService dataservices.EndpointService, factory *cli.ClientFactory) {
if endpoint.Kubernetes.Flags.IsServerMetricsDetected { if endpoint.Kubernetes.Flags.IsServerMetricsDetected {
return return
} }
defer func() { defer func() {
endpoint.Kubernetes.Flags.IsServerMetricsDetected = true endpoint.Kubernetes.Flags.IsServerMetricsDetected = true
endpointService.UpdateEndpoint( if err := endpointService.UpdateEndpoint(endpoint.ID, endpoint); err != nil {
endpoint.ID, log.Debug().Err(err).Msg("unable to enable UseServerMetrics inside the database")
endpoint, }
)
}() }()
cli, err := factory.GetKubeClient(endpoint) cli, err := factory.GetKubeClient(endpoint)
if err != nil { if err != nil {
log.Debug().Err(err).Msg("unable to create kubernetes client for initial metrics detection") log.Debug().Err(err).Msg("unable to create kubernetes client for initial metrics detection")
return return
} }
_, err = cli.GetMetrics()
if err != nil { if _, err := cli.GetMetrics(); err != nil {
log.Debug().Err(err).Msg("unable to fetch metrics: leaving metrics collection disabled.") log.Debug().Err(err).Msg("unable to fetch metrics: leaving metrics collection disabled.")
return return
} }
endpoint.Kubernetes.Configuration.UseServerMetrics = true endpoint.Kubernetes.Configuration.UseServerMetrics = true
if err != nil {
log.Debug().Err(err).Msg("unable to enable UseServerMetrics inside the database")
return
}
} }
func storageDetect(endpoint *portainer.Endpoint, endpointService dataservices.EndpointService, factory *cli.ClientFactory) error { func storageDetect(endpoint *portainer.Endpoint, endpointService dataservices.EndpointService, factory *cli.ClientFactory) error {

Loading…
Cancel
Save