Skip to content

Commit

Permalink
Merge pull request #557 from mattmoor/escape-rfc-1123
Browse files Browse the repository at this point in the history
Pod names must be RFC1123 compliant
  • Loading branch information
mattmoor authored Jul 19, 2023
2 parents 567cc0f + 9936b7c commit 25706d7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/container/kubernetes_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"io"
"os"
"strings"
"time"

apko_build "chainguard.dev/apko/pkg/build"
Expand Down Expand Up @@ -475,10 +476,17 @@ func NewKubernetesConfig(opt ...KubernetesRunnerConfigOptions) *KubernetesRunner
return cfg
}

// escapeRFC1123 escapes a string to be RFC1123 compliant. We don't worry about
// being collision free because these are generally fed to generateName which
// appends a randomized suffix.
func escapeRFC1123(name string) string {
return strings.ReplaceAll(strings.ReplaceAll(name, ".", "-"), "_", "-")
}

func (c KubernetesRunnerConfig) defaultBuilderPod(cfg *Config) *corev1.Pod {
pod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
GenerateName: fmt.Sprintf("melange-builder-%s-%s-", cfg.PackageName, cfg.Arch.String()),
GenerateName: fmt.Sprintf("melange-builder-%s-%s-", escapeRFC1123(cfg.PackageName), cfg.Arch.String()),
Namespace: c.Namespace,
Labels: map[string]string{
"kubernetes.io/arch": cfg.Arch.String(),
Expand Down

0 comments on commit 25706d7

Please sign in to comment.