2016-04-15 22:30:15 +00:00
|
|
|
/*
|
2016-06-03 00:25:58 +00:00
|
|
|
Copyright 2016 The Kubernetes Authors.
|
2016-04-15 22:30:15 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package validation
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"k8s.io/kubernetes/pkg/api"
|
|
|
|
"k8s.io/kubernetes/pkg/apis/apps"
|
2016-12-03 19:06:03 +00:00
|
|
|
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
2016-04-15 22:30:15 +00:00
|
|
|
)
|
|
|
|
|
2016-10-26 20:44:07 +00:00
|
|
|
func TestValidateStatefulSet(t *testing.T) {
|
2016-04-15 22:30:15 +00:00
|
|
|
validLabels := map[string]string{"a": "b"}
|
|
|
|
validPodTemplate := api.PodTemplate{
|
|
|
|
Template: api.PodTemplateSpec{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Labels: validLabels,
|
|
|
|
},
|
|
|
|
Spec: api.PodSpec{
|
|
|
|
RestartPolicy: api.RestartPolicyAlways,
|
|
|
|
DNSPolicy: api.DNSClusterFirst,
|
|
|
|
Containers: []api.Container{{Name: "abc", Image: "image", ImagePullPolicy: "IfNotPresent"}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
invalidLabels := map[string]string{"NoUppercaseOrSpecialCharsLike=Equals": "b"}
|
|
|
|
invalidPodTemplate := api.PodTemplate{
|
|
|
|
Template: api.PodTemplateSpec{
|
|
|
|
Spec: api.PodSpec{
|
|
|
|
RestartPolicy: api.RestartPolicyAlways,
|
|
|
|
DNSPolicy: api.DNSClusterFirst,
|
|
|
|
},
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Labels: invalidLabels,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2016-10-26 20:44:07 +00:00
|
|
|
successCases := []apps.StatefulSet{
|
2016-04-15 22:30:15 +00:00
|
|
|
{
|
|
|
|
ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: api.NamespaceDefault},
|
2016-10-26 20:44:07 +00:00
|
|
|
Spec: apps.StatefulSetSpec{
|
2016-12-03 18:57:26 +00:00
|
|
|
Selector: &metav1.LabelSelector{MatchLabels: validLabels},
|
2016-04-15 22:30:15 +00:00
|
|
|
Template: validPodTemplate.Template,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ObjectMeta: api.ObjectMeta{Name: "abc-123", Namespace: api.NamespaceDefault},
|
2016-10-26 20:44:07 +00:00
|
|
|
Spec: apps.StatefulSetSpec{
|
2016-12-03 18:57:26 +00:00
|
|
|
Selector: &metav1.LabelSelector{MatchLabels: validLabels},
|
2016-04-15 22:30:15 +00:00
|
|
|
Template: validPodTemplate.Template,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, successCase := range successCases {
|
2016-10-26 20:44:07 +00:00
|
|
|
if errs := ValidateStatefulSet(&successCase); len(errs) != 0 {
|
2016-04-15 22:30:15 +00:00
|
|
|
t.Errorf("expected success: %v", errs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-26 20:44:07 +00:00
|
|
|
errorCases := map[string]apps.StatefulSet{
|
2016-04-15 22:30:15 +00:00
|
|
|
"zero-length ID": {
|
|
|
|
ObjectMeta: api.ObjectMeta{Name: "", Namespace: api.NamespaceDefault},
|
2016-10-26 20:44:07 +00:00
|
|
|
Spec: apps.StatefulSetSpec{
|
2016-12-03 18:57:26 +00:00
|
|
|
Selector: &metav1.LabelSelector{MatchLabels: validLabels},
|
2016-04-15 22:30:15 +00:00
|
|
|
Template: validPodTemplate.Template,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"missing-namespace": {
|
|
|
|
ObjectMeta: api.ObjectMeta{Name: "abc-123"},
|
2016-10-26 20:44:07 +00:00
|
|
|
Spec: apps.StatefulSetSpec{
|
2016-12-03 18:57:26 +00:00
|
|
|
Selector: &metav1.LabelSelector{MatchLabels: validLabels},
|
2016-04-15 22:30:15 +00:00
|
|
|
Template: validPodTemplate.Template,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"empty selector": {
|
|
|
|
ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: api.NamespaceDefault},
|
2016-10-26 20:44:07 +00:00
|
|
|
Spec: apps.StatefulSetSpec{
|
2016-04-15 22:30:15 +00:00
|
|
|
Template: validPodTemplate.Template,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"selector_doesnt_match": {
|
|
|
|
ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: api.NamespaceDefault},
|
2016-10-26 20:44:07 +00:00
|
|
|
Spec: apps.StatefulSetSpec{
|
2016-12-03 18:57:26 +00:00
|
|
|
Selector: &metav1.LabelSelector{MatchLabels: map[string]string{"foo": "bar"}},
|
2016-04-15 22:30:15 +00:00
|
|
|
Template: validPodTemplate.Template,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"invalid manifest": {
|
|
|
|
ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: api.NamespaceDefault},
|
2016-10-26 20:44:07 +00:00
|
|
|
Spec: apps.StatefulSetSpec{
|
2016-12-03 18:57:26 +00:00
|
|
|
Selector: &metav1.LabelSelector{MatchLabels: validLabels},
|
2016-04-15 22:30:15 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
"negative_replicas": {
|
|
|
|
ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: api.NamespaceDefault},
|
2016-10-26 20:44:07 +00:00
|
|
|
Spec: apps.StatefulSetSpec{
|
2016-04-15 22:30:15 +00:00
|
|
|
Replicas: -1,
|
2016-12-03 18:57:26 +00:00
|
|
|
Selector: &metav1.LabelSelector{MatchLabels: validLabels},
|
2016-04-15 22:30:15 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
"invalid_label": {
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: "abc-123",
|
|
|
|
Namespace: api.NamespaceDefault,
|
|
|
|
Labels: map[string]string{
|
|
|
|
"NoUppercaseOrSpecialCharsLike=Equals": "bar",
|
|
|
|
},
|
|
|
|
},
|
2016-10-26 20:44:07 +00:00
|
|
|
Spec: apps.StatefulSetSpec{
|
2016-12-03 18:57:26 +00:00
|
|
|
Selector: &metav1.LabelSelector{MatchLabels: validLabels},
|
2016-04-15 22:30:15 +00:00
|
|
|
Template: validPodTemplate.Template,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"invalid_label 2": {
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: "abc-123",
|
|
|
|
Namespace: api.NamespaceDefault,
|
|
|
|
Labels: map[string]string{
|
|
|
|
"NoUppercaseOrSpecialCharsLike=Equals": "bar",
|
|
|
|
},
|
|
|
|
},
|
2016-10-26 20:44:07 +00:00
|
|
|
Spec: apps.StatefulSetSpec{
|
2016-04-15 22:30:15 +00:00
|
|
|
Template: invalidPodTemplate.Template,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"invalid_annotation": {
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: "abc-123",
|
|
|
|
Namespace: api.NamespaceDefault,
|
|
|
|
Annotations: map[string]string{
|
|
|
|
"NoUppercaseOrSpecialCharsLike=Equals": "bar",
|
|
|
|
},
|
|
|
|
},
|
2016-10-26 20:44:07 +00:00
|
|
|
Spec: apps.StatefulSetSpec{
|
2016-12-03 18:57:26 +00:00
|
|
|
Selector: &metav1.LabelSelector{MatchLabels: validLabels},
|
2016-04-15 22:30:15 +00:00
|
|
|
Template: validPodTemplate.Template,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"invalid restart policy 1": {
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: "abc-123",
|
|
|
|
Namespace: api.NamespaceDefault,
|
|
|
|
},
|
2016-10-26 20:44:07 +00:00
|
|
|
Spec: apps.StatefulSetSpec{
|
2016-12-03 18:57:26 +00:00
|
|
|
Selector: &metav1.LabelSelector{MatchLabels: validLabels},
|
2016-04-15 22:30:15 +00:00
|
|
|
Template: api.PodTemplateSpec{
|
|
|
|
Spec: api.PodSpec{
|
|
|
|
RestartPolicy: api.RestartPolicyOnFailure,
|
|
|
|
DNSPolicy: api.DNSClusterFirst,
|
|
|
|
Containers: []api.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent"}},
|
|
|
|
},
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Labels: validLabels,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"invalid restart policy 2": {
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: "abc-123",
|
|
|
|
Namespace: api.NamespaceDefault,
|
|
|
|
},
|
2016-10-26 20:44:07 +00:00
|
|
|
Spec: apps.StatefulSetSpec{
|
2016-12-03 18:57:26 +00:00
|
|
|
Selector: &metav1.LabelSelector{MatchLabels: validLabels},
|
2016-04-15 22:30:15 +00:00
|
|
|
Template: api.PodTemplateSpec{
|
|
|
|
Spec: api.PodSpec{
|
|
|
|
RestartPolicy: api.RestartPolicyNever,
|
|
|
|
DNSPolicy: api.DNSClusterFirst,
|
|
|
|
Containers: []api.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent"}},
|
|
|
|
},
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Labels: validLabels,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for k, v := range errorCases {
|
2016-10-26 20:44:07 +00:00
|
|
|
errs := ValidateStatefulSet(&v)
|
2016-04-15 22:30:15 +00:00
|
|
|
if len(errs) == 0 {
|
|
|
|
t.Errorf("expected failure for %s", k)
|
|
|
|
}
|
|
|
|
for i := range errs {
|
|
|
|
field := errs[i].Field
|
|
|
|
if !strings.HasPrefix(field, "spec.template.") &&
|
|
|
|
field != "metadata.name" &&
|
|
|
|
field != "metadata.namespace" &&
|
|
|
|
field != "spec.selector" &&
|
|
|
|
field != "spec.template" &&
|
|
|
|
field != "GCEPersistentDisk.ReadOnly" &&
|
|
|
|
field != "spec.replicas" &&
|
|
|
|
field != "spec.template.labels" &&
|
|
|
|
field != "metadata.annotations" &&
|
|
|
|
field != "metadata.labels" &&
|
|
|
|
field != "status.replicas" {
|
|
|
|
t.Errorf("%s: missing prefix for: %v", k, errs[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-26 20:44:07 +00:00
|
|
|
func TestValidateStatefulSetUpdate(t *testing.T) {
|
2016-04-15 22:30:15 +00:00
|
|
|
validLabels := map[string]string{"a": "b"}
|
|
|
|
validPodTemplate := api.PodTemplate{
|
|
|
|
Template: api.PodTemplateSpec{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Labels: validLabels,
|
|
|
|
},
|
|
|
|
Spec: api.PodSpec{
|
|
|
|
RestartPolicy: api.RestartPolicyAlways,
|
|
|
|
DNSPolicy: api.DNSClusterFirst,
|
|
|
|
Containers: []api.Container{{Name: "abc", Image: "image", ImagePullPolicy: "IfNotPresent"}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
readWriteVolumePodTemplate := api.PodTemplate{
|
|
|
|
Template: api.PodTemplateSpec{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Labels: validLabels,
|
|
|
|
},
|
|
|
|
Spec: api.PodSpec{
|
|
|
|
RestartPolicy: api.RestartPolicyAlways,
|
|
|
|
DNSPolicy: api.DNSClusterFirst,
|
|
|
|
Containers: []api.Container{{Name: "abc", Image: "image", ImagePullPolicy: "IfNotPresent"}},
|
|
|
|
Volumes: []api.Volume{{Name: "gcepd", VolumeSource: api.VolumeSource{GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{PDName: "my-PD", FSType: "ext4", Partition: 1, ReadOnly: false}}}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
invalidLabels := map[string]string{"NoUppercaseOrSpecialCharsLike=Equals": "b"}
|
|
|
|
invalidPodTemplate := api.PodTemplate{
|
|
|
|
Template: api.PodTemplateSpec{
|
|
|
|
Spec: api.PodSpec{
|
|
|
|
RestartPolicy: api.RestartPolicyAlways,
|
|
|
|
DNSPolicy: api.DNSClusterFirst,
|
|
|
|
},
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Labels: invalidLabels,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
type psUpdateTest struct {
|
2016-10-26 20:44:07 +00:00
|
|
|
old apps.StatefulSet
|
|
|
|
update apps.StatefulSet
|
2016-04-15 22:30:15 +00:00
|
|
|
}
|
|
|
|
successCases := []psUpdateTest{
|
|
|
|
{
|
2016-10-26 20:44:07 +00:00
|
|
|
old: apps.StatefulSet{
|
2016-04-15 22:30:15 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: api.NamespaceDefault},
|
2016-10-26 20:44:07 +00:00
|
|
|
Spec: apps.StatefulSetSpec{
|
2016-12-03 18:57:26 +00:00
|
|
|
Selector: &metav1.LabelSelector{MatchLabels: validLabels},
|
2016-04-15 22:30:15 +00:00
|
|
|
Template: validPodTemplate.Template,
|
|
|
|
},
|
|
|
|
},
|
2016-10-26 20:44:07 +00:00
|
|
|
update: apps.StatefulSet{
|
2016-04-15 22:30:15 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: api.NamespaceDefault},
|
2016-10-26 20:44:07 +00:00
|
|
|
Spec: apps.StatefulSetSpec{
|
2016-04-15 22:30:15 +00:00
|
|
|
Replicas: 3,
|
2016-12-03 18:57:26 +00:00
|
|
|
Selector: &metav1.LabelSelector{MatchLabels: validLabels},
|
2016-04-15 22:30:15 +00:00
|
|
|
Template: validPodTemplate.Template,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-04-25 19:24:40 +00:00
|
|
|
}
|
|
|
|
for _, successCase := range successCases {
|
|
|
|
successCase.old.ObjectMeta.ResourceVersion = "1"
|
|
|
|
successCase.update.ObjectMeta.ResourceVersion = "1"
|
2016-10-26 20:44:07 +00:00
|
|
|
if errs := ValidateStatefulSetUpdate(&successCase.update, &successCase.old); len(errs) != 0 {
|
2016-04-25 19:24:40 +00:00
|
|
|
t.Errorf("expected success: %v", errs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
errorCases := map[string]psUpdateTest{
|
|
|
|
"more than one read/write": {
|
2016-10-26 20:44:07 +00:00
|
|
|
old: apps.StatefulSet{
|
2016-04-25 19:24:40 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{Name: "", Namespace: api.NamespaceDefault},
|
2016-10-26 20:44:07 +00:00
|
|
|
Spec: apps.StatefulSetSpec{
|
2016-12-03 18:57:26 +00:00
|
|
|
Selector: &metav1.LabelSelector{MatchLabels: validLabels},
|
2016-04-15 22:30:15 +00:00
|
|
|
Template: validPodTemplate.Template,
|
|
|
|
},
|
|
|
|
},
|
2016-10-26 20:44:07 +00:00
|
|
|
update: apps.StatefulSet{
|
2016-04-15 22:30:15 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: api.NamespaceDefault},
|
2016-10-26 20:44:07 +00:00
|
|
|
Spec: apps.StatefulSetSpec{
|
2016-04-25 19:24:40 +00:00
|
|
|
Replicas: 2,
|
2016-12-03 18:57:26 +00:00
|
|
|
Selector: &metav1.LabelSelector{MatchLabels: validLabels},
|
2016-04-15 22:30:15 +00:00
|
|
|
Template: readWriteVolumePodTemplate.Template,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-04-25 19:24:40 +00:00
|
|
|
"updates to a field other than spec.Replicas": {
|
2016-10-26 20:44:07 +00:00
|
|
|
old: apps.StatefulSet{
|
2016-04-25 19:24:40 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: api.NamespaceDefault},
|
2016-10-26 20:44:07 +00:00
|
|
|
Spec: apps.StatefulSetSpec{
|
2016-12-03 18:57:26 +00:00
|
|
|
Selector: &metav1.LabelSelector{MatchLabels: validLabels},
|
2016-04-15 22:30:15 +00:00
|
|
|
Template: validPodTemplate.Template,
|
|
|
|
},
|
|
|
|
},
|
2016-10-26 20:44:07 +00:00
|
|
|
update: apps.StatefulSet{
|
2016-04-15 22:30:15 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: api.NamespaceDefault},
|
2016-10-26 20:44:07 +00:00
|
|
|
Spec: apps.StatefulSetSpec{
|
2016-04-25 19:24:40 +00:00
|
|
|
Replicas: 1,
|
2016-12-03 18:57:26 +00:00
|
|
|
Selector: &metav1.LabelSelector{MatchLabels: validLabels},
|
2016-04-15 22:30:15 +00:00
|
|
|
Template: readWriteVolumePodTemplate.Template,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"invalid selector": {
|
2016-10-26 20:44:07 +00:00
|
|
|
old: apps.StatefulSet{
|
2016-04-15 22:30:15 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{Name: "", Namespace: api.NamespaceDefault},
|
2016-10-26 20:44:07 +00:00
|
|
|
Spec: apps.StatefulSetSpec{
|
2016-12-03 18:57:26 +00:00
|
|
|
Selector: &metav1.LabelSelector{MatchLabels: validLabels},
|
2016-04-15 22:30:15 +00:00
|
|
|
Template: validPodTemplate.Template,
|
|
|
|
},
|
|
|
|
},
|
2016-10-26 20:44:07 +00:00
|
|
|
update: apps.StatefulSet{
|
2016-04-15 22:30:15 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: api.NamespaceDefault},
|
2016-10-26 20:44:07 +00:00
|
|
|
Spec: apps.StatefulSetSpec{
|
2016-04-15 22:30:15 +00:00
|
|
|
Replicas: 2,
|
2016-12-03 18:57:26 +00:00
|
|
|
Selector: &metav1.LabelSelector{MatchLabels: invalidLabels},
|
2016-04-15 22:30:15 +00:00
|
|
|
Template: validPodTemplate.Template,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"invalid pod": {
|
2016-10-26 20:44:07 +00:00
|
|
|
old: apps.StatefulSet{
|
2016-04-15 22:30:15 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{Name: "", Namespace: api.NamespaceDefault},
|
2016-10-26 20:44:07 +00:00
|
|
|
Spec: apps.StatefulSetSpec{
|
2016-12-03 18:57:26 +00:00
|
|
|
Selector: &metav1.LabelSelector{MatchLabels: validLabels},
|
2016-04-15 22:30:15 +00:00
|
|
|
Template: validPodTemplate.Template,
|
|
|
|
},
|
|
|
|
},
|
2016-10-26 20:44:07 +00:00
|
|
|
update: apps.StatefulSet{
|
2016-04-15 22:30:15 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: api.NamespaceDefault},
|
2016-10-26 20:44:07 +00:00
|
|
|
Spec: apps.StatefulSetSpec{
|
2016-04-15 22:30:15 +00:00
|
|
|
Replicas: 2,
|
2016-12-03 18:57:26 +00:00
|
|
|
Selector: &metav1.LabelSelector{MatchLabels: validLabels},
|
2016-04-15 22:30:15 +00:00
|
|
|
Template: invalidPodTemplate.Template,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"negative replicas": {
|
2016-10-26 20:44:07 +00:00
|
|
|
old: apps.StatefulSet{
|
2016-04-15 22:30:15 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: api.NamespaceDefault},
|
2016-10-26 20:44:07 +00:00
|
|
|
Spec: apps.StatefulSetSpec{
|
2016-12-03 18:57:26 +00:00
|
|
|
Selector: &metav1.LabelSelector{MatchLabels: validLabels},
|
2016-04-15 22:30:15 +00:00
|
|
|
Template: validPodTemplate.Template,
|
|
|
|
},
|
|
|
|
},
|
2016-10-26 20:44:07 +00:00
|
|
|
update: apps.StatefulSet{
|
2016-04-15 22:30:15 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: api.NamespaceDefault},
|
2016-10-26 20:44:07 +00:00
|
|
|
Spec: apps.StatefulSetSpec{
|
2016-04-15 22:30:15 +00:00
|
|
|
Replicas: -1,
|
2016-12-03 18:57:26 +00:00
|
|
|
Selector: &metav1.LabelSelector{MatchLabels: validLabels},
|
2016-04-15 22:30:15 +00:00
|
|
|
Template: validPodTemplate.Template,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for testName, errorCase := range errorCases {
|
2016-10-26 20:44:07 +00:00
|
|
|
if errs := ValidateStatefulSetUpdate(&errorCase.update, &errorCase.old); len(errs) == 0 {
|
2016-04-15 22:30:15 +00:00
|
|
|
t.Errorf("expected failure: %s", testName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|