@@ -26,6 +26,7 @@ import (
26
26
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
27
27
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28
28
"k8s.io/apimachinery/pkg/runtime"
29
+ utilrand "k8s.io/apimachinery/pkg/util/rand"
29
30
"k8s.io/kubectl/pkg/generate"
30
31
)
31
32
@@ -84,11 +85,23 @@ func buildPodSpec(images []string) v1.PodSpec {
84
85
if strings .Contains (name , "@" ) {
85
86
name = strings .Split (name , "@" )[0 ]
86
87
}
88
+ name = sanitizeAndUniquify (name )
87
89
podSpec .Containers = append (podSpec .Containers , v1.Container {Name : name , Image : imageString })
88
90
}
89
91
return podSpec
90
92
}
91
93
94
+ // sanitizeAndUniquify: replaces characters like "." or "_" into "-" to follow DNS1123 rules.
95
+ // Then add random suffix to make it uniquified.
96
+ func sanitizeAndUniquify (name string ) string {
97
+ if strings .Contains (name , "_" ) || strings .Contains (name , "." ) {
98
+ name = strings .Replace (name , "_" , "-" , - 1 )
99
+ name = strings .Replace (name , "." , "-" , - 1 )
100
+ name = fmt .Sprintf ("%s-%s" , name , utilrand .String (5 ))
101
+ }
102
+ return name
103
+ }
104
+
92
105
// DeploymentBasicGeneratorV1 supports stable generation of a deployment
93
106
type DeploymentBasicGeneratorV1 struct {
94
107
BaseDeploymentGenerator
0 commit comments