@@ -31,6 +31,7 @@ import (
3131
3232 "github.com/go-logr/logr"
3333 corev1 "k8s.io/api/core/v1"
34+ apierrors "k8s.io/apimachinery/pkg/api/errors"
3435 "k8s.io/apimachinery/pkg/runtime"
3536 "k8s.io/apimachinery/pkg/types"
3637 kuberecorder "k8s.io/client-go/tools/record"
@@ -148,19 +149,33 @@ func (r *KustomizationReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
148149 // resolve source reference
149150 source , err := r .getSource (ctx , kustomization )
150151 if err != nil {
151- return ctrl.Result {}, err
152+ if apierrors .IsNotFound (err ) {
153+ msg := "Source not found"
154+ kustomization = kustomizev1 .KustomizationNotReady (kustomization , "" , kustomizev1 .ArtifactFailedReason , msg )
155+ if err := r .Status ().Update (ctx , & kustomization ); err != nil {
156+ log .Error (err , "unable to update status" )
157+ return ctrl.Result {Requeue : true }, err
158+ }
159+ r .recordReadiness (kustomization , false )
160+ log .Info (msg )
161+ // do not requeue, when the source is created the watcher should trigger a reconciliation
162+ return ctrl.Result {}, nil
163+ } else {
164+ // retry on transient errors
165+ return ctrl.Result {Requeue : true }, err
166+ }
152167 }
153168
154- // check source readiness
155169 if source .GetArtifact () == nil {
156- msg := "Source is not ready"
170+ msg := "Source is not ready, artifact not found "
157171 kustomization = kustomizev1 .KustomizationNotReady (kustomization , "" , kustomizev1 .ArtifactFailedReason , msg )
158172 if err := r .Status ().Update (ctx , & kustomization ); err != nil {
159173 log .Error (err , "unable to update status" )
160174 return ctrl.Result {Requeue : true }, err
161175 }
162176 r .recordReadiness (kustomization , false )
163177 log .Info (msg )
178+ // do not requeue, when the artifact is created the watcher should trigger a reconciliation
164179 return ctrl.Result {}, nil
165180 }
166181
@@ -397,14 +412,20 @@ func (r *KustomizationReconciler) getSource(ctx context.Context, kustomization k
397412 var repository sourcev1.GitRepository
398413 err := r .Client .Get (ctx , namespacedName , & repository )
399414 if err != nil {
400- return source , fmt .Errorf ("source '%s' not found: %w" , namespacedName , err )
415+ if apierrors .IsNotFound (err ) {
416+ return source , err
417+ }
418+ return source , fmt .Errorf ("unable to get source '%s': %w" , namespacedName , err )
401419 }
402420 source = & repository
403421 case sourcev1 .BucketKind :
404422 var bucket sourcev1.Bucket
405423 err := r .Client .Get (ctx , namespacedName , & bucket )
406424 if err != nil {
407- return source , fmt .Errorf ("source '%s' not found: %w" , namespacedName , err )
425+ if apierrors .IsNotFound (err ) {
426+ return source , err
427+ }
428+ return source , fmt .Errorf ("unable to get source '%s': %w" , namespacedName , err )
408429 }
409430 source = & bucket
410431 default :
0 commit comments