mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 12:15:52 +00:00
Validate StatefulSet names as DNS Label
Any StatefuleSet which took advantage of this (by having dots in the name) can't have worked because we set `pod.spec.hostname` from it, which is validated as a DNS label. So while this is strictly a breaking change, it doesn't break anything that was not already broken.
This commit is contained in:
parent
7061704297
commit
f4c1682fb1
@ -39,10 +39,10 @@ import (
|
||||
// Prefix indicates this name will be used as part of generation, in which case
|
||||
// trailing dashes are allowed.
|
||||
func ValidateStatefulSetName(name string, prefix bool) []string {
|
||||
// TODO: Validate that there's name for the suffix inserted by the pods.
|
||||
// TODO: Validate that there's room for the suffix inserted by the pods.
|
||||
// Currently this is just "-index". In the future we may allow a user
|
||||
// specified list of suffixes and we need to validate the longest one.
|
||||
return apimachineryvalidation.NameIsDNSSubdomain(name, prefix)
|
||||
return apimachineryvalidation.NameIsDNSLabel(name, prefix)
|
||||
}
|
||||
|
||||
// ValidatePodTemplateSpecForStatefulSet validates the given template and ensures that it is in accordance with the desired selector.
|
||||
|
@ -213,7 +213,7 @@ func TestValidateStatefulSet(t *testing.T) {
|
||||
|
||||
errorCases := []testCase{
|
||||
{
|
||||
name: "zero-length ID",
|
||||
name: "zero-length name",
|
||||
set: apps.StatefulSet{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "", Namespace: metav1.NamespaceDefault},
|
||||
Spec: apps.StatefulSetSpec{
|
||||
@ -227,6 +227,36 @@ func TestValidateStatefulSet(t *testing.T) {
|
||||
field.Required(field.NewPath("metadata", "name"), ""),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "name-with-dots",
|
||||
set: apps.StatefulSet{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "abc.123", Namespace: metav1.NamespaceDefault},
|
||||
Spec: apps.StatefulSetSpec{
|
||||
PodManagementPolicy: apps.OrderedReadyPodManagement,
|
||||
Selector: &metav1.LabelSelector{MatchLabels: validLabels},
|
||||
Template: validPodTemplate.Template,
|
||||
UpdateStrategy: apps.StatefulSetUpdateStrategy{Type: apps.RollingUpdateStatefulSetStrategyType},
|
||||
},
|
||||
},
|
||||
errs: field.ErrorList{
|
||||
field.Invalid(field.NewPath("metadata", "name"), "abc.123", ""),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "long name",
|
||||
set: apps.StatefulSet{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: strings.Repeat("a", 64), Namespace: metav1.NamespaceDefault},
|
||||
Spec: apps.StatefulSetSpec{
|
||||
PodManagementPolicy: apps.OrderedReadyPodManagement,
|
||||
Selector: &metav1.LabelSelector{MatchLabels: validLabels},
|
||||
Template: validPodTemplate.Template,
|
||||
UpdateStrategy: apps.StatefulSetUpdateStrategy{Type: apps.RollingUpdateStatefulSetStrategyType},
|
||||
},
|
||||
},
|
||||
errs: field.ErrorList{
|
||||
field.Invalid(field.NewPath("metadata", "name"), strings.Repeat("a", 64), ""),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "missing-namespace",
|
||||
set: apps.StatefulSet{
|
||||
|
Loading…
Reference in New Issue
Block a user