Skip to content

Commit 7e584dc

Browse files
committed
Improve health checking
Wait for a deployment to be created before running the liveness check
1 parent c0bc890 commit 7e584dc

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

controllers/gitrepository_controller.go renamed to controllers/gitrepository_watcher.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ import (
3434
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1alpha1"
3535
)
3636

37-
// KustomizationReconciler watches a GitRepository object
37+
// GitRepositoryWatcher watches GitRepository objects for revision changes
38+
// and triggers a sync for all the Kustomizations that reference a changed source
3839
type GitRepositoryWatcher struct {
3940
client.Client
4041
Log logr.Logger
@@ -54,7 +55,7 @@ func (r *GitRepositoryWatcher) Reconcile(req ctrl.Request) (ctrl.Result, error)
5455
}
5556

5657
log := r.Log.WithValues(strings.ToLower(repo.Kind), req.NamespacedName)
57-
log.Info("New artifact detected")
58+
log.Info("new artifact detected")
5859

5960
// get the list of kustomizations that are using this Git repository
6061
var list kustomizev1.KustomizationList

controllers/kustomization_controller.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,17 @@ func (r *KustomizationReconciler) checkHealth(kustomization kustomizev1.Kustomiz
513513
var alerts string
514514

515515
for _, check := range kustomization.Spec.HealthChecks {
516-
cmd := fmt.Sprintf("kubectl -n %s rollout status %s %s --timeout=%s",
517-
check.Namespace, check.Kind, check.Name, kustomization.GetTimeout())
516+
cmd := fmt.Sprintf("until kubectl -n %s get %s %s ; do sleep 2; done",
517+
check.Namespace, check.Kind, check.Name)
518518
command := exec.CommandContext(ctx, "/bin/sh", "-c", cmd)
519+
if _, err := command.CombinedOutput(); err != nil {
520+
return fmt.Errorf("health check timeout for %s '%s/%s': %w",
521+
check.Kind, check.Namespace, check.Name, err)
522+
}
523+
524+
cmd = fmt.Sprintf("kubectl -n %s rollout status %s %s --timeout=%s",
525+
check.Namespace, check.Kind, check.Name, kustomization.GetTimeout())
526+
command = exec.CommandContext(ctx, "/bin/sh", "-c", cmd)
519527
output, err := command.CombinedOutput()
520528
if err != nil {
521529
if errors.Is(err, context.DeadlineExceeded) {

0 commit comments

Comments
 (0)