Skip to content

Commit 3cc6b31

Browse files
wesleyjellisclaude
andcommitted
Emit account_id and job metadata as Kubernetes pod labels
Rather than weaving the account_id job variable into the pod name (which risks the 63-char limit and OpsLevel-side naming conventions), stamp descriptive labels on the job pod for observability: app.kubernetes.io/name: opslevel-job opslevel.com/account-id: <account_id> (when the job sets it) opslevel.com/job-id: <job id> opslevel.com/mode: <faktory|api> These enable native DataDog filtering via podLabelsAsTags with no pod name parsing. Labels are added after building the PDB label selector so they stay out of the selector, which the instance label already makes unique. Adds a getRunnerJobVariable helper (named explicitly since a similar helper is anticipated for egress proxies). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent a46e524 commit 3cc6b31

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/pkg/k8s.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,16 @@ func (s *JobRunner) Run(ctx context.Context, job opslevel.RunnerJob, stdout, std
388388
Outcome: opslevel.RunnerJobOutcomeEnumFailed,
389389
}
390390
}
391+
// Descriptive labels for observability (e.g. DataDog podLabelsAsTags), so
392+
// running pods can be filtered by account/job/mode without parsing the pod
393+
// name. Added after building the selector so they stay out of the PDB
394+
// selector, which the instance label already makes unique.
395+
labels["app.kubernetes.io/name"] = "opslevel-job"
396+
labels["opslevel.com/job-id"] = id
397+
labels["opslevel.com/mode"] = viper.GetString("mode")
398+
if accountId := getRunnerJobVariable(job.Variables, "account_id"); accountId != "" {
399+
labels["opslevel.com/account-id"] = accountId
400+
}
391401
// TODO: manage pods based on image for re-use?
392402
cfgMap, err := s.CreateConfigMap(ctx, s.getConfigMapObject(identifier, job))
393403
if err != nil {

0 commit comments

Comments
 (0)