fix: hash scheduler-k3s cron-id label to fit Kubernetes' 63-byte cap
The `dokku.com/cron-id` label could exceed Kubernetes' 63-byte cap because the cron ID is `base36(appName === command === schedule)`, which expands roughly 1.5x per byte. The label is now keyed `dokku.com/cron-hash` and holds the `sha1` hex digest of the cron-id, a fixed 40-character value that always fits the cap. The same hex digest is mirrored into the `dokku.com/cron-hash` annotation, and the original base36 cron-id stays in the `dokku.com/cron-id` annotation that `cron:list` reads when surfacing user-facing IDs. Per-task lookups stay server-side via label selectors, so `cron:set --maintenance` and the forbid/replace concurrency checks on `dokku run --cron-id` keep working without any in-memory filtering.
This commit is contained in:
10 files changed
+235
-51
No files matched your search
@@ -795,10 +795,8 @@ func TriggerSchedulerDeploy(scheduler string, appName string, imageTag string) e
|
||||
suffix := ""
|
||||
for _, cronJob := range cronJobs {
|
||||
if cronJob.Annotations["dokku.com/cron-id"] == cronTask.ID {
|
||||
var ok bool
|
||||
suffix, ok = cronJob.Annotations["dokku.com/job-suffix"]
|
||||
if !ok {
|
||||
suffix = ""
|
||||
if value, ok := cronJob.Annotations["dokku.com/job-suffix"]; ok {
|
||||
suffix = value
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1355,6 +1353,7 @@ func TriggerSchedulerRun(scheduler string, appName string, envCount int, args []
|
||||
labels := map[string]string{
|
||||
"app.kubernetes.io/part-of": appName,
|
||||
}
|
||||
annotations := map[string]string{}
|
||||
|
||||
if os.Getenv("DOKKU_TRACE") == "1" {
|
||||
extraEnv["TRACE"] = "true"
|
||||
@@ -1373,8 +1372,11 @@ func TriggerSchedulerRun(scheduler string, appName string, envCount int, args []
|
||||
processType := "run"
|
||||
if os.Getenv("DOKKU_CRON_ID") != "" {
|
||||
processType = "cron"
|
||||
cronHash := cronIDLabelValue(os.Getenv("DOKKU_CRON_ID"))
|
||||
cronID := os.Getenv("DOKKU_CRON_ID")
|
||||
cronHash := cronIDLabelValue(cronID)
|
||||
labels["dokku.com/cron-hash"] = cronHash
|
||||
annotations["dokku.com/cron-hash"] = cronHash
|
||||
annotations["dokku.com/cron-id"] = cronID
|
||||
concurrencyPolicy := strings.ToUpper(os.Getenv("DOKKU_CONCURRENCY_POLICY"))
|
||||
switch concurrencyPolicy {
|
||||
case "forbid":
|
||||
@@ -1498,6 +1500,8 @@ func TriggerSchedulerRun(scheduler string, appName string, envCount int, args []
|
||||
|
||||
workingDir := common.GetWorkingDir(appName, image)
|
||||
job, err := templateKubernetesJob(Job{
|
||||
ActiveDeadlineSeconds: activeDeadlineSeconds,
|
||||
Annotations: annotations,
|
||||
AppName: appName,
|
||||
Command: command,
|
||||
DeploymentID: deploymentID,
|
||||
@@ -1513,7 +1517,6 @@ func TriggerSchedulerRun(scheduler string, appName string, envCount int, args []
|
||||
RemoveContainer: rmContainer,
|
||||
SecurityContext: securityContext,
|
||||
WorkingDir: workingDir,
|
||||
ActiveDeadlineSeconds: activeDeadlineSeconds,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error templating job: %w", err)
|
||||
@@ -1754,7 +1757,7 @@ func TriggerSchedulerRunList(scheduler string, appName string, format string) er
|
||||
|
||||
cronID, ok := cronJob.Annotations["dokku.com/cron-id"]
|
||||
if !ok {
|
||||
common.LogWarn(fmt.Sprintf("Cron job %s does not have a cron ID annotation", cronJob.Name))
|
||||
common.LogWarn(fmt.Sprintf("Cron job %s does not have a dokku.com/cron-id annotation", cronJob.Name))
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user