mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Merge pull request #114172 from thockin/statefulset_name_dns_label
Validate StatefulSet names as DNS Label
This commit is contained in:
commit
db53463d4f
@ -39,10 +39,10 @@ import (
|
|||||||
// Prefix indicates this name will be used as part of generation, in which case
|
// Prefix indicates this name will be used as part of generation, in which case
|
||||||
// trailing dashes are allowed.
|
// trailing dashes are allowed.
|
||||||
func ValidateStatefulSetName(name string, prefix bool) []string {
|
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
|
// 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.
|
// 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.
|
// 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{
|
errorCases := []testCase{
|
||||||
{
|
{
|
||||||
name: "zero-length ID",
|
name: "zero-length name",
|
||||||
set: apps.StatefulSet{
|
set: apps.StatefulSet{
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "", Namespace: metav1.NamespaceDefault},
|
ObjectMeta: metav1.ObjectMeta{Name: "", Namespace: metav1.NamespaceDefault},
|
||||||
Spec: apps.StatefulSetSpec{
|
Spec: apps.StatefulSetSpec{
|
||||||
@ -227,6 +227,36 @@ func TestValidateStatefulSet(t *testing.T) {
|
|||||||
field.Required(field.NewPath("metadata", "name"), ""),
|
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",
|
name: "missing-namespace",
|
||||||
set: apps.StatefulSet{
|
set: apps.StatefulSet{
|
||||||
|
Loading…
Reference in New Issue
Block a user