Skip to content

Commit acfcf27

Browse files
committed
refactor(agent): name the shared error-context keys
Signed-off-by: Alex Yuskauskas <ayuskauskas@nvidia.com>
1 parent bc3ab21 commit acfcf27

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

pkg/k8s/agent/names.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,26 @@ func nameWithRunID(prefix, runID string) string {
9393
// pkg/snapshotter defaults and whitespace-checks RunID before building an
9494
// agent Config, but that guard does not cover callers who construct a
9595
// pkg/k8s/agent Config directly, which is the public SDK surface.
96+
// Error-context keys shared by the name-validation failures below, so a
97+
// caller parsing a structured error keys off one spelling.
98+
const (
99+
ctxKeyField = "field"
100+
ctxKeyValue = "value"
101+
ctxKeyResolvedName = "resolvedName"
102+
)
103+
96104
func (d *Deployer) validateRunID() error {
97105
runID := d.config.RunID
98106
if runID == "" {
99107
return errors.NewWithContext(errors.ErrCodeInvalidRequest,
100108
"Config.RunID is required: every object this Deployer creates is named \"<prefix>-<RunID>\"; generate one with runid.Generate()",
101-
map[string]any{"field": "Config.RunID", "value": runID})
109+
map[string]any{ctxKeyField: "Config.RunID", ctxKeyValue: runID})
102110
}
103111
if problems := validation.IsDNS1123Label(runID); len(problems) > 0 {
104112
return errors.NewWithContext(errors.ErrCodeInvalidRequest,
105113
fmt.Sprintf("Config.RunID %q is not a valid Kubernetes name segment: %s",
106114
runID, strings.Join(problems, "; ")),
107-
map[string]any{"field": "Config.RunID", "value": runID})
115+
map[string]any{ctxKeyField: "Config.RunID", ctxKeyValue: runID})
108116
}
109117
return nil
110118
}
@@ -172,7 +180,7 @@ func (d *Deployer) validateResolvedNames() error {
172180
return errors.NewWithContext(errors.ErrCodeInvalidRequest,
173181
fmt.Sprintf("%s %q yields the %s name %q, which is not a valid Kubernetes object name: %s",
174182
n.field, n.prefix, n.objects, n.value, strings.Join(problems, "; ")),
175-
map[string]any{"field": n.field, "value": n.prefix, "resolvedName": n.value})
183+
map[string]any{ctxKeyField: n.field, ctxKeyValue: n.prefix, ctxKeyResolvedName: n.value})
176184
}
177185
return nil
178186
}

0 commit comments

Comments
 (0)