Skip to content

Commit

Permalink
Merge pull request #598 from octo/fix-conditions-usage
Browse files Browse the repository at this point in the history
Fix incorrect use of format strings with the `conditions` package.
  • Loading branch information
stefanprodan authored Jul 12, 2024
2 parents af9405d + 4386177 commit 8e2b0af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions internal/controller/imagepolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func (r *ImagePolicyReconciler) reconcile(ctx context.Context, sp *patch.SerialP
// watched by this reconciler, like the namespace that ImageRepository
// allows access from.
e := fmt.Errorf("failed to get the referred ImageRepository: %w", err)
conditions.MarkFalse(obj, meta.ReadyCondition, reason, e.Error())
conditions.MarkFalse(obj, meta.ReadyCondition, reason, "%s", e)
result, retErr = ctrl.Result{}, e
return
}
Expand All @@ -296,19 +296,19 @@ func (r *ImagePolicyReconciler) reconcile(ctx context.Context, sp *patch.SerialP
if err != nil {
// Stall if it's an invalid policy.
if _, ok := err.(errInvalidPolicy); ok {
conditions.MarkStalled(obj, "InvalidPolicy", err.Error())
conditions.MarkStalled(obj, "InvalidPolicy", "%s", err)
result, retErr = ctrl.Result{}, nil
return
}

// If there's no tag in the database, mark not ready and retry.
if err == errNoTagsInDatabase {
conditions.MarkFalse(obj, meta.ReadyCondition, imagev1.DependencyNotReadyReason, err.Error())
conditions.MarkFalse(obj, meta.ReadyCondition, imagev1.DependencyNotReadyReason, "%s", err)
result, retErr = ctrl.Result{}, err
return
}

conditions.MarkFalse(obj, meta.ReadyCondition, metav1.StatusFailure, err.Error())
conditions.MarkFalse(obj, meta.ReadyCondition, metav1.StatusFailure, "%s", err)
result, retErr = ctrl.Result{}, err
return
}
Expand All @@ -330,7 +330,7 @@ func (r *ImagePolicyReconciler) reconcile(ctx context.Context, sp *patch.SerialP
prevRef, err := name.NewTag(obj.Status.ObservedPreviousImage)
if err != nil {
e := fmt.Errorf("failed to parse previous image '%s': %w", obj.Status.ObservedPreviousImage, err)
conditions.MarkFalse(obj, meta.ReadyCondition, meta.FailedReason, e.Error())
conditions.MarkFalse(obj, meta.ReadyCondition, meta.FailedReason, "%s", e)
result, retErr = ctrl.Result{}, e
}
previousTag = prevRef.TagStr()
Expand Down
8 changes: 4 additions & 4 deletions internal/controller/imagerepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (r *ImageRepositoryReconciler) reconcile(ctx context.Context, sp *patch.Ser
// Parse image reference.
ref, err := parseImageReference(obj.Spec.Image, obj.Spec.Insecure)
if err != nil {
conditions.MarkStalled(obj, imagev1.ImageURLInvalidReason, err.Error())
conditions.MarkStalled(obj, imagev1.ImageURLInvalidReason, "%s", err)
result, retErr = ctrl.Result{}, nil
return
}
Expand All @@ -260,7 +260,7 @@ func (r *ImageRepositoryReconciler) reconcile(ctx context.Context, sp *patch.Ser
opts, err := r.setAuthOptions(ctx, obj, ref)
if err != nil {
e := fmt.Errorf("failed to configure authentication options: %w", err)
conditions.MarkFalse(obj, meta.ReadyCondition, imagev1.AuthenticationFailedReason, e.Error())
conditions.MarkFalse(obj, meta.ReadyCondition, imagev1.AuthenticationFailedReason, "%s", e)
result, retErr = ctrl.Result{}, e
return
}
Expand All @@ -269,7 +269,7 @@ func (r *ImageRepositoryReconciler) reconcile(ctx context.Context, sp *patch.Ser
ok, when, reasonMsg, err := r.shouldScan(*obj, startTime)
if err != nil {
e := fmt.Errorf("failed to determine if it's scan time: %w", err)
conditions.MarkFalse(obj, meta.ReadyCondition, metav1.StatusFailure, e.Error())
conditions.MarkFalse(obj, meta.ReadyCondition, metav1.StatusFailure, "%s", e)
result, retErr = ctrl.Result{}, e
return
}
Expand All @@ -286,7 +286,7 @@ func (r *ImageRepositoryReconciler) reconcile(ctx context.Context, sp *patch.Ser
tags, err := r.scan(ctx, obj, ref, opts)
if err != nil {
e := fmt.Errorf("scan failed: %w", err)
conditions.MarkFalse(obj, meta.ReadyCondition, imagev1.ReadOperationFailedReason, e.Error())
conditions.MarkFalse(obj, meta.ReadyCondition, imagev1.ReadOperationFailedReason, "%s", e)
result, retErr = ctrl.Result{}, e
return
}
Expand Down

0 comments on commit 8e2b0af

Please sign in to comment.