fix kubectl create deployment image name
Kubernetes-commit: 5db45e12d545c69176ead8a4e866ab303776ed5e
This commit is contained in:
parent
a37fece401
commit
77be642341
|
@ -26,6 +26,7 @@ import (
|
||||||
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
|
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
utilrand "k8s.io/apimachinery/pkg/util/rand"
|
||||||
"k8s.io/kubectl/pkg/generate"
|
"k8s.io/kubectl/pkg/generate"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -84,11 +85,23 @@ func buildPodSpec(images []string) v1.PodSpec {
|
||||||
if strings.Contains(name, "@") {
|
if strings.Contains(name, "@") {
|
||||||
name = strings.Split(name, "@")[0]
|
name = strings.Split(name, "@")[0]
|
||||||
}
|
}
|
||||||
|
name = sanitizeAndUniquify(name)
|
||||||
podSpec.Containers = append(podSpec.Containers, v1.Container{Name: name, Image: imageString})
|
podSpec.Containers = append(podSpec.Containers, v1.Container{Name: name, Image: imageString})
|
||||||
}
|
}
|
||||||
return podSpec
|
return podSpec
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sanitizeAndUniquify: replaces characters like "." or "_" into "-" to follow DNS1123 rules.
|
||||||
|
// Then add random suffix to make it uniquified.
|
||||||
|
func sanitizeAndUniquify(name string) string {
|
||||||
|
if strings.Contains(name, "_") || strings.Contains(name, ".") {
|
||||||
|
name = strings.Replace(name, "_", "-", -1)
|
||||||
|
name = strings.Replace(name, ".", "-", -1)
|
||||||
|
name = fmt.Sprintf("%s-%s", name, utilrand.String(5))
|
||||||
|
}
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|
||||||
// DeploymentBasicGeneratorV1 supports stable generation of a deployment
|
// DeploymentBasicGeneratorV1 supports stable generation of a deployment
|
||||||
type DeploymentBasicGeneratorV1 struct {
|
type DeploymentBasicGeneratorV1 struct {
|
||||||
BaseDeploymentGenerator
|
BaseDeploymentGenerator
|
||||||
|
|
Loading…
Reference in New Issue