Identify cluster scope by a boolean field rather than a special namespace

This commit is contained in:
Mike Spreitzer
2019-11-13 10:32:50 -05:00
parent 3b77bc8054
commit a912bd8488
4 changed files with 46 additions and 65 deletions

View File

@@ -407,11 +407,11 @@ func TestFlowSchemaValidation(t *testing.T) {
},
},
expectedErrors: field.ErrorList{
field.Required(field.NewPath("spec").Child("rules").Index(0).Child("resourceRules").Index(0).Child("namespaces"), "resource rules must supply at least one namespace"),
field.Required(field.NewPath("spec").Child("rules").Index(0).Child("resourceRules").Index(0).Child("namespaces"), "resource rules that are not cluster scoped must supply at least one namespace"),
},
},
{
name: "NamespaceClusterScope is allowed",
name: "ClusterScope is allowed, with no Namespaces",
flowSchema: &flowcontrol.FlowSchema{
ObjectMeta: metav1.ObjectMeta{
Name: "system-foo",
@@ -434,7 +434,7 @@ func TestFlowSchemaValidation(t *testing.T) {
Verbs: []string{flowcontrol.VerbAll},
APIGroups: []string{flowcontrol.APIGroupAll},
Resources: []string{flowcontrol.ResourceAll},
Namespaces: []string{flowcontrol.NamespaceClusterScope},
ClusterScope: true,
},
},
},
@@ -444,7 +444,7 @@ func TestFlowSchemaValidation(t *testing.T) {
expectedErrors: field.ErrorList{},
},
{
name: "NamespaceClusterScope is allowed with NamespaceEvery",
name: "ClusterScope is allowed with NamespaceEvery",
flowSchema: &flowcontrol.FlowSchema{
ObjectMeta: metav1.ObjectMeta{
Name: "system-foo",
@@ -467,7 +467,8 @@ func TestFlowSchemaValidation(t *testing.T) {
Verbs: []string{flowcontrol.VerbAll},
APIGroups: []string{flowcontrol.APIGroupAll},
Resources: []string{flowcontrol.ResourceAll},
Namespaces: []string{flowcontrol.NamespaceClusterScope, flowcontrol.NamespaceEvery},
ClusterScope: true,
Namespaces: []string{flowcontrol.NamespaceEvery},
},
},
},
@@ -508,7 +509,7 @@ func TestFlowSchemaValidation(t *testing.T) {
},
},
expectedErrors: field.ErrorList{
field.Invalid(field.NewPath("spec").Child("rules").Index(0).Child("resourceRules").Index(0).Child("namespaces"), []string{"foo", flowcontrol.NamespaceEvery}, "'*' may be accompanied only by 'Cluster Scope'"),
field.Invalid(field.NewPath("spec").Child("rules").Index(0).Child("resourceRules").Index(0).Child("namespaces"), []string{"foo", flowcontrol.NamespaceEvery}, "if '*' is present, must not specify other namespaces"),
},
},
{