Skip to content

Commit 6fc8b2e

Browse files
committed
feat: get source retry interval
Signed-off-by: peefy <[email protected]>
1 parent 90ee6e1 commit 6fc8b2e

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

api/v1alpha1/kclrun_types.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,25 @@ func (in KCLRun) GetTimeout() time.Duration {
284284
return duration
285285
}
286286

287+
// GetRetryInterval returns the retry interval
288+
func (in KCLRun) GetRetryInterval() time.Duration {
289+
if in.Spec.RetryInterval != nil {
290+
return in.Spec.RetryInterval.Duration
291+
}
292+
return in.GetRequeueAfter()
293+
}
294+
295+
// GetRequeueAfter returns the duration after which the KCLRun must be
296+
// reconciled again.
297+
func (in KCLRun) GetRequeueAfter() time.Duration {
298+
return in.Spec.Interval.Duration
299+
}
300+
301+
// GetDependsOn returns the list of dependencies across-namespaces.
302+
func (in KCLRun) GetDependsOn() []meta.NamespacedObjectReference {
303+
return in.Spec.DependsOn
304+
}
305+
287306
// UsePersistentClient returns the configured PersistentClient, or the default
288307
// of true.
289308
func (in KCLRun) UsePersistentClient() bool {

internal/controller/kclrun_controller.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ import (
4141
securejoin "github.com/cyphar/filepath-securejoin"
4242
"github.com/fluxcd/cli-utils/pkg/kstatus/polling"
4343
"github.com/fluxcd/cli-utils/pkg/object"
44+
apiacl "github.com/fluxcd/pkg/apis/acl"
4445
eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
4546
"github.com/fluxcd/pkg/apis/meta"
4647
"github.com/fluxcd/pkg/http/fetch"
48+
"github.com/fluxcd/pkg/runtime/acl"
4749
runtimeClient "github.com/fluxcd/pkg/runtime/client"
4850
"github.com/fluxcd/pkg/runtime/conditions"
4951
"github.com/fluxcd/pkg/runtime/patch"
@@ -150,6 +152,20 @@ func (r *KCLRunReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
150152

151153
source, err := r.getSource(ctx, &obj)
152154
if err != nil {
155+
conditions.MarkFalse(&obj, meta.ReadyCondition, meta.ArtifactFailedReason, "%s", err)
156+
if apierrors.IsNotFound(err) {
157+
msg := fmt.Sprintf("Source '%s' not found", obj.Spec.SourceRef.String())
158+
log.Info(msg)
159+
return ctrl.Result{RequeueAfter: obj.GetRetryInterval()}, nil
160+
}
161+
162+
if acl.IsAccessDenied(err) {
163+
conditions.MarkFalse(&obj, meta.ReadyCondition, apiacl.AccessDeniedReason, "%s", err)
164+
log.Error(err, "Access denied to cross-namespace source")
165+
r.event(&obj, "unknown", eventv1.EventSeverityError, err.Error(), nil)
166+
return ctrl.Result{RequeueAfter: obj.GetRetryInterval()}, nil
167+
}
168+
// Retry with backoff on transient errors.
153169
return ctrl.Result{}, err
154170
}
155171
artifact := source.GetArtifact()

0 commit comments

Comments
 (0)