Skip to content

Commit 78bfc0c

Browse files
author
Jim Minter
committed
allow secrets with "." characters to be used in builds
1 parent 4d8d2c3 commit 78bfc0c

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

pkg/build/controller/strategy/util.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"path/filepath"
66
"strconv"
7+
"strings"
78

89
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
910
kvalidation "k8s.io/apimachinery/pkg/util/validation"
@@ -93,7 +94,11 @@ func setupDockerSocket(pod *v1.Pod) {
9394
// mountSecretVolume is a helper method responsible for actual mounting secret
9495
// volumes into a pod.
9596
func mountSecretVolume(pod *v1.Pod, container *v1.Container, secretName, mountPath, volumeSuffix string) {
96-
volumeName := namer.GetName(secretName, volumeSuffix, kvalidation.DNS1123SubdomainMaxLength)
97+
volumeName := namer.GetName(secretName, volumeSuffix, kvalidation.DNS1123LabelMaxLength)
98+
99+
// coerce from RFC1123 subdomain to RFC1123 label.
100+
volumeName = strings.Replace(volumeName, ".", "-", -1)
101+
97102
volumeExists := false
98103
for _, v := range pod.Spec.Volumes {
99104
if v.Name == volumeName {

pkg/build/controller/strategy/util_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func TestSetupDockerSecrets(t *testing.T) {
8181
}
8282

8383
pushSecret := &kapi.LocalObjectReference{
84-
Name: "pushSecret",
84+
Name: "my.pushSecret.with.full.stops.and.longer.than.sixty.three.characters",
8585
}
8686
pullSecret := &kapi.LocalObjectReference{
8787
Name: "pullSecret",
@@ -106,6 +106,13 @@ func TestSetupDockerSecrets(t *testing.T) {
106106
seenName[v.Name] = true
107107
}
108108

109+
if !seenName["my-pushSecret-with-full-stops-and-longer-than-six-c6eb4d75-push"] {
110+
t.Errorf("volume my-pushSecret-with-full-stops-and-longer-than-six-c6eb4d75-push was not seen")
111+
}
112+
if !seenName["pullSecret-pull"] {
113+
t.Errorf("volume pullSecret-pull was not seen")
114+
}
115+
109116
seenMount := map[string]bool{}
110117
seenMountPath := map[string]bool{}
111118
for _, m := range pod.Spec.Containers[0].VolumeMounts {
@@ -119,6 +126,13 @@ func TestSetupDockerSecrets(t *testing.T) {
119126
}
120127
seenMountPath[m.Name] = true
121128
}
129+
130+
if !seenMount["my-pushSecret-with-full-stops-and-longer-than-six-c6eb4d75-push"] {
131+
t.Errorf("volumemount my-pushSecret-with-full-stops-and-longer-than-six-c6eb4d75-push was not seen")
132+
}
133+
if !seenMount["pullSecret-pull"] {
134+
t.Errorf("volumemount pullSecret-pull was not seen")
135+
}
122136
}
123137

124138
func TestCopyEnvVarSlice(t *testing.T) {

0 commit comments

Comments
 (0)