@@ -30,6 +30,7 @@ import (
3030 "sigs.k8s.io/controller-runtime/pkg/client"
3131
3232 configv1beta1 "github.com/projectsveltos/addon-controller/api/v1beta1"
33+ "github.com/projectsveltos/addon-controller/lib/clusterops"
3334 "github.com/projectsveltos/addon-controller/pkg/scope"
3435 libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1"
3536 "github.com/projectsveltos/libsveltos/lib/clusterproxy"
@@ -170,24 +171,9 @@ func (r *ClusterSummaryReconciler) proceedDeployingFeature(ctx context.Context,
170171
171172 r .updateFeatureStatus (clusterSummaryScope , f .id , deployerStatus , currentHash , deployerError , logger )
172173 if deployerError != nil {
173- // Check if error is a NonRetriableError type
174- var nonRetriableError * configv1beta1.NonRetriableError
175- if errors .As (deployerError , & nonRetriableError ) {
176- nonRetriableStatus := libsveltosv1beta1 .FeatureStatusFailedNonRetriable
177- r .updateFeatureStatus (clusterSummaryScope , f .id , & nonRetriableStatus , currentHash , deployerError , logger )
178- return nil
179- }
180- var templateError * configv1beta1.TemplateInstantiationError
181- if errors .As (deployerError , & templateError ) {
182- nonRetriableStatus := libsveltosv1beta1 .FeatureStatusFailedNonRetriable
183- r .updateFeatureStatus (clusterSummaryScope , f .id , & nonRetriableStatus , currentHash , deployerError , logger )
184- return nil
185- }
186- if r .maxNumberOfConsecutiveFailureReached (clusterSummaryScope , f , logger ) {
187- nonRetriableStatus := libsveltosv1beta1 .FeatureStatusFailedNonRetriable
188- resultError := errors .New ("the maximum number of consecutive errors has been reached" )
189- r .updateFeatureStatus (clusterSummaryScope , f .id , & nonRetriableStatus , currentHash , resultError , logger )
190- return nil
174+ shouldReturn , err := r .handleDeployerError (deployerError , clusterSummaryScope , f , currentHash , logger )
175+ if shouldReturn {
176+ return err
191177 }
192178 }
193179 if * deployerStatus == libsveltosv1beta1 .FeatureStatusProvisioning {
@@ -224,6 +210,38 @@ func (r *ClusterSummaryReconciler) proceedDeployingFeature(ctx context.Context,
224210 return fmt .Errorf ("request is queued" )
225211}
226212
213+ func (r * ClusterSummaryReconciler ) handleDeployerError (deployerError error , clusterSummaryScope * scope.ClusterSummaryScope ,
214+ f feature , currentHash []byte , logger logr.Logger ) (bool , error ) {
215+
216+ // Check if error is a NonRetriableError type
217+ var nonRetriableError * configv1beta1.NonRetriableError
218+ if errors .As (deployerError , & nonRetriableError ) {
219+ nonRetriableStatus := libsveltosv1beta1 .FeatureStatusFailedNonRetriable
220+ r .updateFeatureStatus (clusterSummaryScope , f .id , & nonRetriableStatus , currentHash , deployerError , logger )
221+ return true , nil
222+ }
223+ var templateError * configv1beta1.TemplateInstantiationError
224+ if errors .As (deployerError , & templateError ) {
225+ nonRetriableStatus := libsveltosv1beta1 .FeatureStatusFailedNonRetriable
226+ r .updateFeatureStatus (clusterSummaryScope , f .id , & nonRetriableStatus , currentHash , deployerError , logger )
227+ return true , nil
228+ }
229+ var healthCheckError * clusterops.HealthCheckError
230+ if errors .As (deployerError , & healthCheckError ) {
231+ retriableStatus := libsveltosv1beta1 .FeatureStatusFailed
232+ r .updateFeatureStatus (clusterSummaryScope , f .id , & retriableStatus , currentHash , deployerError , logger )
233+ return true , healthCheckError
234+ }
235+ if r .maxNumberOfConsecutiveFailureReached (clusterSummaryScope , f , logger ) {
236+ nonRetriableStatus := libsveltosv1beta1 .FeatureStatusFailedNonRetriable
237+ resultError := errors .New ("the maximum number of consecutive errors has been reached" )
238+ r .updateFeatureStatus (clusterSummaryScope , f .id , & nonRetriableStatus , currentHash , resultError , logger )
239+ return true , nil
240+ }
241+
242+ return false , deployerError
243+ }
244+
227245func (r * ClusterSummaryReconciler ) proceedDeployingFeatureInPullMode (ctx context.Context ,
228246 clusterSummaryScope * scope.ClusterSummaryScope , f feature , isConfigSame bool , currentHash []byte ,
229247 logger logr.Logger ) error {
0 commit comments