Skip to content

Commit ee58eb2

Browse files
committed
fix: pipeline names easily exceed character limit
1 parent 431d24e commit ee58eb2

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

pkg/pipelines/tekton/resources.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package tekton
22

33
import (
44
"context"
5+
"crypto/sha256"
6+
"encoding/hex"
57
"errors"
68
"fmt"
79

@@ -57,7 +59,22 @@ func getPipelineName(f fn.Function) string {
5759
} else {
5860
source = "git"
5961
}
60-
return fmt.Sprintf("%s-%s-%s-pipeline", f.Name, f.Build.Builder, source)
62+
63+
// Kubernetes resource names must be <= 63 characters (RFC 1123)
64+
// We use a hash-based approach to guarantee uniqueness while staying under the limit
65+
66+
// Create a unique identifier based on function name, builder, and source
67+
fullIdentifier := fmt.Sprintf("%s-%s-%s", f.Name, f.Build.Builder, source)
68+
69+
// Generate hash of the full identifier
70+
hash := sha256.Sum256([]byte(fullIdentifier))
71+
// Use first 8 characters of hex encoding (4 bytes = 8 hex chars)
72+
shortHash := hex.EncodeToString(hash[:4])
73+
74+
// Format: func-{hash}-{builder}-{source}
75+
// This gives us: 4 + 1 + 8 + 1 + 3-4 + 1 + 6-3 = 24-26 chars max
76+
// Well under the 63 char limit with room for future additions
77+
return fmt.Sprintf("func-%s-%s-%s", shortHash, f.Build.Builder, source)
6178
}
6279

6380
func getPipelineRunGenerateName(f fn.Function) string {

0 commit comments

Comments
 (0)