fix(kubernetes): detect metrics API for kubernetes endspoints EE-4865 (#8351)

pull/8387/head
Prabhat Khera 2023-01-24 09:05:15 +13:00 committed by GitHub
parent a74e389521
commit 087848539f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 1 deletions

View File

@ -2,12 +2,42 @@ package migrator
import (
portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/internal/endpointutils"
"github.com/rs/zerolog/log"
)
func (m *Migrator) migrateDBVersionToDB80() error {
return m.updateEdgeStackStatusForDB80()
if err := m.updateEdgeStackStatusForDB80(); err != nil {
return err
}
if err := m.updateExistingEndpointsToNotDetectMetricsAPIForDB80(); err != nil {
return err
}
return nil
}
func (m *Migrator) updateExistingEndpointsToNotDetectMetricsAPIForDB80() error {
log.Info().Msg("updating existing endpoints to not detect metrics API for existing endpoints (k8s)")
endpoints, err := m.endpointService.Endpoints()
if err != nil {
return err
}
for _, endpoint := range endpoints {
if endpointutils.IsKubernetesEndpoint(&endpoint) {
endpoint.Kubernetes.Flags.IsServerMetricsDetected = true
err = m.endpointService.UpdateEndpoint(endpoint.ID, &endpoint)
if err != nil {
return err
}
}
}
return nil
}
func (m *Migrator) updateEdgeStackStatusForDB80() error {

View File

@ -62,6 +62,9 @@
"UseLoadBalancer": false,
"UseServerMetrics": false
},
"Flags": {
"IsServerMetricsDetected": false
},
"Snapshots": []
},
"LastCheckInDate": 0,

View File

@ -7,6 +7,7 @@ import (
"github.com/portainer/libhttp/request"
"github.com/portainer/libhttp/response"
portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/internal/endpointutils"
)
// @id EndpointInspect
@ -51,6 +52,15 @@ func (handler *Handler) endpointInspect(w http.ResponseWriter, r *http.Request)
}
}
isServerMetricsDetected := endpoint.Kubernetes.Flags.IsServerMetricsDetected
if !isServerMetricsDetected && handler.K8sClientFactory != nil {
endpointutils.InitialMetricsDetection(
endpoint,
handler.DataStore.Endpoint(),
handler.K8sClientFactory,
)
}
return response.JSON(w, endpoint)
}

View File

@ -116,6 +116,7 @@ func InitialMetricsDetection(endpoint *portainer.Endpoint, endpointService datas
return
}
endpoint.Kubernetes.Configuration.UseServerMetrics = true
endpoint.Kubernetes.Flags.IsServerMetricsDetected = true
err = endpointService.UpdateEndpoint(
portainer.EndpointID(endpoint.ID),
endpoint,

View File

@ -562,6 +562,11 @@ type (
KubernetesData struct {
Snapshots []KubernetesSnapshot `json:"Snapshots"`
Configuration KubernetesConfiguration `json:"Configuration"`
Flags KubernetesFlags `json:"Flags"`
}
KubernetesFlags struct {
IsServerMetricsDetected bool `json:"IsServerMetricsDetected"`
}
// KubernetesSnapshot represents a snapshot of a specific Kubernetes environment(endpoint) at a specific time