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:
Jose Diaz-Gonzalez
2026-05-24 02:50:09 -04:00
parent 3c8cba08e5
commit bf2cfe1886
10 changed files with 235 additions and 51 deletions

View File

@@ -3,8 +3,9 @@ package scheduler_k3s
import (
"bytes"
"context"
"crypto/sha256"
"crypto/sha1"
"encoding/base64"
"encoding/hex"
"errors"
"fmt"
"net"
@@ -24,7 +25,6 @@ import (
nginxvhosts "github.com/dokku/dokku/plugins/nginx-vhosts"
resty "github.com/go-resty/resty/v2"
kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1"
"github.com/multiformats/go-base36"
"golang.org/x/sync/errgroup"
"gopkg.in/yaml.v3"
"helm.sh/helm/v3/pkg/strvals"
@@ -2083,12 +2083,14 @@ func kubernetesNodeToNode(node v1.Node) Node {
}
}
// cronIDLabelValue returns a Kubernetes-label-safe hash of a cron ID.
// The raw cron ID can exceed the 63-byte label cap, so we keep it as an
// annotation and use this short hash for selectors.
// cronIDLabelValue returns the sha1 hex digest of the supplied cron ID,
// used as the dokku.com/cron-hash label/annotation value on cron resources.
// The raw cron ID exceeds Kubernetes' 63-byte label cap for non-trivial
// commands, so we hash it to a fixed 40-character string and keep the
// original in the dokku.com/cron-id annotation for display.
func cronIDLabelValue(cronID string) string {
sum := sha256.Sum256([]byte(cronID))
return base36.EncodeToStringLc(sum[:16])
sum := sha1.Sum([]byte(cronID))
return hex.EncodeToString(sum[:])
}
// parseMemoryQuantity parses a string into a valid memory quantity