Retry apply on missing Kind
This commit is contained in:
parent
43d5844d1a
commit
0c47dfd549
|
|
@ -239,7 +239,7 @@ func (r *KustomizationReconciler) sync(
|
|||
}
|
||||
|
||||
// apply
|
||||
err = r.apply(kustomization, dirPath)
|
||||
err = r.applyWithRetry(kustomization, dirPath, 5*time.Second)
|
||||
if err != nil {
|
||||
return kustomizev1.KustomizationNotReady(
|
||||
kustomization,
|
||||
|
|
@ -487,6 +487,26 @@ func (r *KustomizationReconciler) apply(kustomization kustomizev1.Kustomization,
|
|||
return nil
|
||||
}
|
||||
|
||||
func (r *KustomizationReconciler) applyWithRetry(kustomization kustomizev1.Kustomization, dirPath string, delay time.Duration) error {
|
||||
err := r.apply(kustomization, dirPath)
|
||||
if err != nil {
|
||||
// retry apply due to CRD/CR race
|
||||
if strings.Contains(err.Error(), "could not find the requested resource") ||
|
||||
strings.Contains(err.Error(), "no matches for kind") {
|
||||
r.Log.Info("retrying apply",
|
||||
"error", err.Error(),
|
||||
"kustomization", fmt.Sprintf("%s/%s", kustomization.GetNamespace(), kustomization.GetName()))
|
||||
time.Sleep(delay)
|
||||
if err := r.apply(kustomization, dirPath); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *KustomizationReconciler) prune(kustomization kustomizev1.Kustomization, snapshot *kustomizev1.Snapshot) error {
|
||||
if kustomization.Status.Snapshot == nil || snapshot == nil {
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Reference in New Issue