Skip to content

Commit 3d74804

Browse files
Improve error message for unknown error in validateTargetRef (#8299)
* Improve error message for unknown error in * Format Unknown error better * Update vertical-pod-autoscaler/pkg/target/controller_fetcher/controller_fetcher.go Co-authored-by: Stoyan Vitanov <stoyan.a.vitanov@gmail.com> * Address PR review feedback * Remove unnecessary Stringer method * Improve third case err message * Adapt third case err message test --------- Co-authored-by: Stoyan Vitanov <stoyan.a.vitanov@gmail.com>
1 parent 1d5f047 commit 3d74804

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

vertical-pod-autoscaler/pkg/recommender/input/cluster_feeder.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,9 @@ func (feeder *clusterStateFeeder) validateTargetRef(ctx context.Context, vpa *vp
573573
if vpa.Spec.TargetRef == nil {
574574
return false, condition{}
575575
}
576+
577+
target := fmt.Sprintf("%s.%s/%s", vpa.Spec.TargetRef.APIVersion, vpa.Spec.TargetRef.Kind, vpa.Spec.TargetRef.Name)
578+
576579
k := controllerfetcher.ControllerKeyWithAPIVersion{
577580
ControllerKey: controllerfetcher.ControllerKey{
578581
Namespace: vpa.Namespace,
@@ -583,13 +586,13 @@ func (feeder *clusterStateFeeder) validateTargetRef(ctx context.Context, vpa *vp
583586
}
584587
top, err := feeder.controllerFetcher.FindTopMostWellKnownOrScalable(ctx, &k)
585588
if err != nil {
586-
return false, condition{conditionType: vpa_types.ConfigUnsupported, delete: false, message: fmt.Sprintf("Error checking if target is a topmost well-known or scalable controller: %s", err)}
589+
return false, condition{conditionType: vpa_types.ConfigUnsupported, delete: false, message: fmt.Sprintf("Error checking if target %s is a topmost well-known or scalable controller: %s", target, err)}
587590
}
588591
if top == nil {
589-
return false, condition{conditionType: vpa_types.ConfigUnsupported, delete: false, message: fmt.Sprintf("Unknown error during checking if target is a topmost well-known or scalable controller: %s", err)}
592+
return false, condition{conditionType: vpa_types.ConfigUnsupported, delete: false, message: fmt.Sprintf("Unknown error during checking if target %s is a topmost well-known or scalable controller", target)}
590593
}
591594
if *top != k {
592-
return false, condition{conditionType: vpa_types.ConfigUnsupported, delete: false, message: "The targetRef controller has a parent but it should point to a topmost well-known or scalable controller"}
595+
return false, condition{conditionType: vpa_types.ConfigUnsupported, delete: false, message: fmt.Sprintf("The target %s has a parent controller but it should point to a topmost well-known or scalable controller", target)}
593596
}
594597
return true, condition{}
595598
}

vertical-pod-autoscaler/pkg/recommender/input/cluster_feeder_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ var (
6565
unsupportedConditionTextFromFetcher = "Cannot read targetRef. Reason: targetRef not defined"
6666
unsupportedConditionNoExtraText = "Cannot read targetRef"
6767
unsupportedConditionNoTargetRef = "Cannot read targetRef"
68-
unsupportedConditionMudaMudaMuda = "Error checking if target is a topmost well-known or scalable controller: muda muda muda"
69-
unsupportedTargetRefHasParent = "The targetRef controller has a parent but it should point to a topmost well-known or scalable controller"
68+
unsupportedConditionMudaMudaMuda = "Error checking if target taxonomy.doestar/doseph-doestar is a topmost well-known or scalable controller: muda muda muda"
69+
unsupportedTargetRefHasParent = "The target stardust.dodokind/dotaro has a parent controller but it should point to a topmost well-known or scalable controller"
7070
)
7171

7272
const (

0 commit comments

Comments
 (0)