Skip to content

Commit 034ba21

Browse files
scotwellsclaude
andcommitted
refactor(controller): dedupe the terminal-error annotation decoder
decodeTerminalErrorAnnotation duplicated decodeTerminalError (both born in the same commit). Route the one caller to decodeTerminalError and delete the copy; the caller already guards against an empty annotation, so the canonical decoder's empty-string handling is equivalent here. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 56660a4 commit 034ba21

1 file changed

Lines changed: 1 addition & 16 deletions

File tree

internal/controller/instance_controller.go

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ func (r *InstanceReconciler) applyTerminalErrorFromWD(
657657
) (changed, terminal bool) {
658658
// Path 1: annotation (federation-safe).
659659
if termErrRaw := wd.Annotations[computev1alpha.ReferencedDataErrorAnnotation]; termErrRaw != "" {
660-
termReason, termMessage, decodeErr := decodeTerminalErrorAnnotation(termErrRaw)
660+
termReason, termMessage, decodeErr := decodeTerminalError(termErrRaw)
661661
if decodeErr != nil {
662662
log.FromContext(ctx).V(1).Info("malformed referenced-data-error annotation on WD; ignoring",
663663
"workloadDeployment", wd.Name, "error", decodeErr)
@@ -679,21 +679,6 @@ func (r *InstanceReconciler) applyTerminalErrorFromWD(
679679
return false, false
680680
}
681681

682-
// decodeTerminalErrorAnnotation parses the value of ReferencedDataErrorAnnotation
683-
// into (reason, message). Returns an error when the annotation is malformed.
684-
// Both files in the same package share this unexported helper through Go's
685-
// package-level visibility — no cross-file coupling issue.
686-
func decodeTerminalErrorAnnotation(raw string) (reason, message string, err error) {
687-
var payload struct {
688-
Reason string `json:"reason"`
689-
Message string `json:"message"`
690-
}
691-
if err := json.Unmarshal([]byte(raw), &payload); err != nil {
692-
return "", "", fmt.Errorf("decode referenced-data-error annotation %q: %w", raw, err)
693-
}
694-
return payload.Reason, payload.Message, nil
695-
}
696-
697682
// listPresentCompanionsByKindName returns a set keyed by kind-qualified tokens
698683
// ("Kind/name", e.g. "ConfigMap/app-config") for every companion ConfigMap and
699684
// Secret present in the given namespace (matched by ReferencedDataLabel). This

0 commit comments

Comments
 (0)