Skip to content

Commit 9e50d1d

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 46b88df commit 9e50d1d

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
@@ -653,7 +653,7 @@ func (r *InstanceReconciler) applyTerminalErrorFromWD(
653653
) (changed, terminal bool) {
654654
// Path 1: annotation (federation-safe).
655655
if termErrRaw := wd.Annotations[computev1alpha.ReferencedDataErrorAnnotation]; termErrRaw != "" {
656-
termReason, termMessage, decodeErr := decodeTerminalErrorAnnotation(termErrRaw)
656+
termReason, termMessage, decodeErr := decodeTerminalError(termErrRaw)
657657
if decodeErr != nil {
658658
log.FromContext(ctx).V(1).Info("malformed referenced-data-error annotation on WD; ignoring",
659659
"workloadDeployment", wd.Name, "error", decodeErr)
@@ -675,21 +675,6 @@ func (r *InstanceReconciler) applyTerminalErrorFromWD(
675675
return false, false
676676
}
677677

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

0 commit comments

Comments
 (0)