@@ -6,10 +6,9 @@ import (
66 "sync"
77 "time"
88
9- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1 "
9+ "github.com/pluralsh/deployment-operator/internal/utils "
1010
1111 "github.com/cert-manager/cert-manager/pkg/apis/certmanager"
12-
1312 "github.com/pluralsh/deployment-operator/internal/helpers"
1413 "github.com/pluralsh/deployment-operator/pkg/common"
1514 agentcommon "github.com/pluralsh/deployment-operator/pkg/common"
@@ -18,6 +17,7 @@ import (
1817 "github.com/pluralsh/polly/containers"
1918 "github.com/samber/lo"
2019 corev1 "k8s.io/api/core/v1"
20+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2222 "k8s.io/apimachinery/pkg/runtime/schema"
2323 "k8s.io/client-go/discovery"
@@ -132,15 +132,15 @@ func RunAiInsightComponentScraperInBackgroundOrDie(ctx context.Context, k8sClien
132132 }
133133}
134134
135- func setUnhealthyComponents (ctx context.Context , k8sClient ctrclient.Client , gvk schema.GroupVersionKind , opts ... ctrclient. ListOption ) error {
135+ func setUnhealthyComponents (ctx context.Context , k8sClient ctrclient.Client , gvk schema.GroupVersionKind ) error {
136136 pager := listResources (ctx , k8sClient , gvk )
137137 for pager .HasNext () {
138138 items , err := pager .NextPage ()
139139 if err != nil {
140140 return err
141141 }
142142 for _ , item := range items {
143- health , err := common . GetResourceHealth ( & item )
143+ health , err := getResourceHealthStatus ( ctx , k8sClient , & item )
144144 if err != nil {
145145 return err
146146 }
@@ -156,6 +156,36 @@ func setUnhealthyComponents(ctx context.Context, k8sClient ctrclient.Client, gvk
156156 return nil
157157}
158158
159+ func getResourceHealthStatus (ctx context.Context , k8sClient ctrclient.Client , obj * unstructured.Unstructured ) (* common.HealthStatus , error ) {
160+ health , err := common .GetResourceHealth (obj )
161+ if err != nil {
162+ return nil , err
163+ }
164+
165+ progressTime , err := common .GetLastProgressTimestamp (ctx , k8sClient , obj )
166+ if err != nil {
167+ return nil , err
168+ }
169+
170+ // remove entry if no longer progressing
171+ if health .Status != common .HealthStatusProgressing {
172+ // cleanup progress timestamp
173+ annotations := obj .GetAnnotations ()
174+ delete (annotations , common .LastProgressTimeAnnotation )
175+ obj .SetAnnotations (annotations )
176+ return health , utils .TryToUpdate (ctx , k8sClient , obj )
177+ }
178+
179+ // mark as failed if it exceeds a threshold
180+ cutoffTime := metav1 .NewTime (time .Now ().Add (- 30 * time .Minute ))
181+
182+ if progressTime .Before (& cutoffTime ) {
183+ health .Status = common .HealthStatusDegraded
184+ }
185+
186+ return health , nil
187+ }
188+
159189func listResources (ctx context.Context , k8sClient ctrclient.Client , gvk schema.GroupVersionKind ) * algorithms.Pager [unstructured.Unstructured ] {
160190 var opts []ctrclient.ListOption
161191 manageByOperatorLabels := map [string ]string {
0 commit comments