From dcce8c6074b95a5747fed8cab1daf20772c8605c Mon Sep 17 00:00:00 2001 From: Xiangjing Li <55890329+xiangjingli@users.noreply.github.com> Date: Fri, 27 Oct 2023 00:52:23 -0400 Subject: [PATCH] stop synchronizing resources list if any kustomization folder fails (#375) Signed-off-by: Xiangjing Li --- pkg/subscriber/git/git_subscriber_item.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/subscriber/git/git_subscriber_item.go b/pkg/subscriber/git/git_subscriber_item.go index 2f4022b0..02316eff 100644 --- a/pkg/subscriber/git/git_subscriber_item.go +++ b/pkg/subscriber/git/git_subscriber_item.go @@ -360,6 +360,12 @@ func (ghsi *SubscriberItem) doSubscription() error { ghsi.successful = false errMsg += err.Error() + + metrics.LocalDeploymentFailedPullTime. + WithLabelValues(ghsi.SubscriberItem.Subscription.Namespace, ghsi.SubscriberItem.Subscription.Name). + Observe(0) + + return errors.New("kustomization failed, stop synchronizing. err: " + errMsg) } klog.Info("Applying helm charts..") @@ -437,7 +443,13 @@ func (ghsi *SubscriberItem) subscribeKustomizations() error { out, err := utils.RunKustomizeBuild(kustomizeDir) if err != nil { - klog.Error("Failed to apply kustomization, error: ", err.Error()) + klog.Error("Failed to apply kustomization, clean up all resources that will deploy. error: ", err.Error()) + + // If applying one kustomize folder fails after some other kustomize folder success, clean up the memory git resource list for stopping synchronizer. + // Or only successfully kustomized resources are deployed, + // that will trigger synchronizer to delete those resources that haven't been kustomized but deployed previously + ghsi.resources = []kubesynchronizer.ResourceUnit{} + return err }