From e5b2955b39174ff3bbfdefc1fd27695ce6fbb4f0 Mon Sep 17 00:00:00 2001 From: Sebastian Florek Date: Fri, 4 Oct 2024 16:53:38 +0200 Subject: [PATCH] feat(upgradeinsights): add support for warning status (#296) * feat(upgradeinsights): add support for warning status * fix lint --- go.mod | 2 +- go.sum | 4 ++-- .../controller/upgradeinsights_cloudprovider.go | 15 +++++++++++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 65e10da5..9a9ff162 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,7 @@ require ( github.com/open-policy-agent/gatekeeper/v3 v3.17.1 github.com/orcaman/concurrent-map/v2 v2.0.1 github.com/pkg/errors v0.9.1 - github.com/pluralsh/console/go/client v1.19.0 + github.com/pluralsh/console/go/client v1.20.0 github.com/pluralsh/controller-reconcile-helper v0.1.0 github.com/pluralsh/gophoenix v0.1.3-0.20231201014135-dff1b4309e34 github.com/pluralsh/polly v0.1.10 diff --git a/go.sum b/go.sum index ccc3b58e..cf0de887 100644 --- a/go.sum +++ b/go.sum @@ -666,8 +666,8 @@ github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5/go.mod h1:iIss55rK github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pluralsh/console/go/client v1.19.0 h1:x5JQWYtxr5S/PVUJS4Jiiir2IYAqMruONXydu9NSliM= -github.com/pluralsh/console/go/client v1.19.0/go.mod h1:lpoWASYsM9keNePS3dpFiEisUHEfObIVlSL3tzpKn8k= +github.com/pluralsh/console/go/client v1.20.0 h1:XZ9GcNAcEXRXtcyHZdA1dpi/GovMdHbC+obJgD+RnzE= +github.com/pluralsh/console/go/client v1.20.0/go.mod h1:lpoWASYsM9keNePS3dpFiEisUHEfObIVlSL3tzpKn8k= github.com/pluralsh/controller-reconcile-helper v0.1.0 h1:BV3dYZFH5rn8ZvZjtpkACSv/GmLEtRftNQj/Y4ddHEo= github.com/pluralsh/controller-reconcile-helper v0.1.0/go.mod h1:RxAbvSB4/jkvx616krCdNQXPbpGJXW3J1L3rASxeFOA= github.com/pluralsh/gophoenix v0.1.3-0.20231201014135-dff1b4309e34 h1:ab2PN+6if/Aq3/sJM0AVdy1SYuMAnq4g20VaKhTm/Bw= diff --git a/internal/controller/upgradeinsights_cloudprovider.go b/internal/controller/upgradeinsights_cloudprovider.go index a89d0fb5..c923f50e 100644 --- a/internal/controller/upgradeinsights_cloudprovider.go +++ b/internal/controller/upgradeinsights_cloudprovider.go @@ -35,7 +35,7 @@ func (in *EKSCloudProvider) UpgradeInsights(ctx context.Context, ui v1alpha1.Upg return nil, err } - insights, err := in.listInsights(ctx, client, ui) + insights, err := in.listInsights(ctx, client) if err != nil { return nil, err } @@ -63,7 +63,7 @@ func (in *EKSCloudProvider) UpgradeInsights(ctx context.Context, ui v1alpha1.Upg }), nil } -func (in *EKSCloudProvider) listInsights(ctx context.Context, client *eks.Client, ui v1alpha1.UpgradeInsights) ([]*types.Insight, error) { +func (in *EKSCloudProvider) listInsights(ctx context.Context, client *eks.Client) ([]*types.Insight, error) { logger := log.FromContext(ctx) var result []types.InsightSummary @@ -116,8 +116,9 @@ func (in *EKSCloudProvider) fromInsightStatus(status *types.InsightStatus) *cons case types.InsightStatusValuePassing: return lo.ToPtr(console.UpgradeInsightStatusPassing) case types.InsightStatusValueError: - case types.InsightStatusValueWarning: return lo.ToPtr(console.UpgradeInsightStatusFailed) + case types.InsightStatusValueWarning: + return lo.ToPtr(console.UpgradeInsightStatusWarning) case types.InsightStatusValueUnknown: return lo.ToPtr(console.UpgradeInsightStatusUnknown) } @@ -126,11 +127,17 @@ func (in *EKSCloudProvider) fromInsightStatus(status *types.InsightStatus) *cons } func (in *EKSCloudProvider) fromClientStats(stats []types.ClientStat) *console.UpgradeInsightStatus { - const failedBeforeDuration = 24.0 // in hours + const failedBeforeDuration = 24.0 // 24 hours + const warningBeforeDuration = 24.0 * 30 // 30 days + for _, stat := range stats { if stat.LastRequestTime != nil && time.Since(*stat.LastRequestTime).Hours() < failedBeforeDuration { return lo.ToPtr(console.UpgradeInsightStatusFailed) } + + if stat.LastRequestTime != nil && time.Since(*stat.LastRequestTime).Hours() < warningBeforeDuration { + return lo.ToPtr(console.UpgradeInsightStatusWarning) + } } return lo.ToPtr(console.UpgradeInsightStatusPassing)