Skip to content

Commit 855ff79

Browse files
committed
Add a 'timeout' to the standalone reconcile
When the reconcile is failing the process loop forever. This is annoying when used into automation like Ansible. This change ensures the process exit 1 when the reconcile in not done after 5 minutes. Change-Id: Iac270ef5c9a0339fe2f70a50db29f27f13dc0dbd
1 parent ca21693 commit 855ff79

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
88

99
- "Debug" toggle for fluent bit sidecars
1010
- A support for running zuul-executor component external to the cluster.
11+
- The standalone deployment mode exits 1 when the reconcile is not possible after 300 seconds
1112

1213
### Changed
1314

cli/cmd/dev/apply.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ func applyStandalone(ns string, sfResource string, kubeContext string) {
4545
"CR", sf,
4646
"CR name", sf.ObjectMeta.Name,
4747
"Namespace", ns)
48-
controllers.Standalone(sf, ns, kubeContext)
48+
err = controllers.Standalone(sf, ns, kubeContext)
49+
if err != nil {
50+
ctrl.Log.Error(err, "Could not reconcile resource")
51+
os.Exit(1)
52+
}
4953
os.Exit(0)
5054
}
5155
}

controllers/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func Main(ns string, metricsAddr string, probeAddr string, enableLeaderElection
146146
}
147147
}
148148

149-
func Standalone(sf sfv1.SoftwareFactory, ns string, kubeContext string) {
149+
func Standalone(sf sfv1.SoftwareFactory, ns string, kubeContext string) error {
150150

151151
config := GetConfigContextOrDie(kubeContext)
152152
cl, err := client.New(config, client.Options{
@@ -165,5 +165,5 @@ func Standalone(sf sfv1.SoftwareFactory, ns string, kubeContext string) {
165165
RESTConfig: config,
166166
CancelFunc: cancelFunc,
167167
}
168-
sfr.StandaloneReconcile(ctx, ns, sf)
168+
return sfr.StandaloneReconcile(ctx, ns, sf)
169169
}

controllers/softwarefactory_controller.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"errors"
1212
"fmt"
1313
"sort"
14+
"strconv"
1415
"time"
1516

1617
certv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
@@ -436,8 +437,9 @@ func (r *SoftwareFactoryReconciler) Reconcile(ctx context.Context, req ctrl.Requ
436437

437438
}
438439

439-
func (r *SoftwareFactoryReconciler) StandaloneReconcile(ctx context.Context, ns string, sf sfv1.SoftwareFactory) {
440+
func (r *SoftwareFactoryReconciler) StandaloneReconcile(ctx context.Context, ns string, sf sfv1.SoftwareFactory) error {
440441
d, _ := time.ParseDuration("5s")
442+
maxAttempt := 60
441443
log := log.FromContext(ctx)
442444

443445
// Create a fake resource that simulate the Resource Owner.
@@ -456,21 +458,26 @@ func (r *SoftwareFactoryReconciler) StandaloneReconcile(ctx context.Context, ns
456458
// Create the fake controller configMap
457459
if err := r.Create(ctx, &controllerCM); err != nil {
458460
log.Error(err, "Unable to create configMap", "name", controllerCMName)
459-
return
461+
return err
460462
}
461463
}
462464

463465
sfCtrl := r.mkSFController(ctx, ns, &controllerCM, sf, true)
466+
attempt := 0
464467

465468
for {
466469
status := sfCtrl.Step()
470+
attempt += 1
471+
if attempt == maxAttempt {
472+
return errors.New("unable to reconcile after max attempts")
473+
}
467474
if status.Ready {
468-
break
475+
log.Info("Standalone reconcile done.")
476+
return nil
469477
}
470-
log.Info("Waiting 5s for the next reconcile call ...")
478+
log.Info("[attempt #" + strconv.Itoa(attempt) + "] Waiting 5s for the next reconcile call ...")
471479
time.Sleep(d)
472480
}
473-
log.Info("Standalone reconcile done.")
474481
}
475482

476483
// SetupWithManager sets up the controller with the Manager.

0 commit comments

Comments
 (0)