mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #996 from brendandburns/selector
Add a validation that replicaSelector matches PodTemplate.Labels
This commit is contained in:
commit
bd2cbdc312
@ -275,6 +275,11 @@ func ValidateReplicationController(controller *ReplicationController) errs.Error
|
||||
if labels.Set(controller.DesiredState.ReplicaSelector).AsSelector().Empty() {
|
||||
allErrs = append(allErrs, errs.NewInvalid("ReplicationController.ReplicaSelector", controller.DesiredState.ReplicaSelector))
|
||||
}
|
||||
selector := labels.Set(controller.DesiredState.ReplicaSelector).AsSelector()
|
||||
labels := labels.Set(controller.DesiredState.PodTemplate.Labels)
|
||||
if !selector.Matches(labels) {
|
||||
allErrs = append(allErrs, errs.NewInvalid("ReplicaController.DesiredState.PodTemplate.Labels", controller.DesiredState.PodTemplate))
|
||||
}
|
||||
if controller.DesiredState.Replicas < 0 {
|
||||
allErrs = append(allErrs, errs.NewInvalid("ReplicationController.Replicas", controller.DesiredState.Replicas))
|
||||
}
|
||||
|
@ -373,6 +373,7 @@ func TestValidateReplicationController(t *testing.T) {
|
||||
Version: "v1beta1",
|
||||
},
|
||||
},
|
||||
Labels: validSelector,
|
||||
}
|
||||
|
||||
successCases := []ReplicationController{
|
||||
@ -411,6 +412,13 @@ func TestValidateReplicationController(t *testing.T) {
|
||||
PodTemplate: validPodTemplate,
|
||||
},
|
||||
},
|
||||
"selector_doesnt_match": {
|
||||
JSONBase: JSONBase{ID: "abc"},
|
||||
DesiredState: ReplicationControllerState{
|
||||
ReplicaSelector: map[string]string{"foo": "bar"},
|
||||
PodTemplate: validPodTemplate,
|
||||
},
|
||||
},
|
||||
"invalid manifest": {
|
||||
JSONBase: JSONBase{ID: "abc"},
|
||||
DesiredState: ReplicationControllerState{
|
||||
|
@ -205,6 +205,7 @@ var validPodTemplate = api.PodTemplate{
|
||||
},
|
||||
},
|
||||
},
|
||||
Labels: map[string]string{"a": "b"},
|
||||
}
|
||||
|
||||
func TestCreateController(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user