@@ -30,6 +30,9 @@ import (
3030 "k8s.io/apiserver/pkg/authentication/user"
3131 "k8s.io/apiserver/pkg/authorization/authorizer"
3232 "k8s.io/apiserver/pkg/endpoints/request"
33+ utilfeature "k8s.io/apiserver/pkg/util/feature"
34+ "k8s.io/kubernetes/pkg/features"
35+
3336 rbacregistryvalidation "k8s.io/kubernetes/pkg/registry/rbac/validation"
3437 "k8s.io/kubernetes/plugin/pkg/auth/authorizer/rbac"
3538)
@@ -64,11 +67,10 @@ func TestResolverWithWarrants(t *testing.T) {
6467 Verbs : []string {"get" },
6568 NonResourceURLs : []string {"/readyz" },
6669 }
67- // TODO(cnvergence): restore the commented lines once we drop the global service account feature flag
68- /* getMetrics := &authorizer.DefaultNonResourceRuleInfo{
70+ getMetrics := & authorizer.DefaultNonResourceRuleInfo {
6971 Verbs : []string {"get" },
7072 NonResourceURLs : []string {"/metrics" },
71- } */
73+ }
7274 getRoot := & authorizer.DefaultNonResourceRuleInfo {
7375 Verbs : []string {"get" },
7476 NonResourceURLs : []string {"/" },
@@ -80,6 +82,7 @@ func TestResolverWithWarrants(t *testing.T) {
8082 wantResourceRules []authorizer.ResourceRuleInfo
8183 wantNonResourceRules []authorizer.NonResourceRuleInfo
8284 wantError bool
85+ skip bool
8386 }{
8487 {
8588 name : "base without warrants" ,
@@ -129,19 +132,19 @@ func TestResolverWithWarrants(t *testing.T) {
129132 wantResourceRules : []authorizer.ResourceRuleInfo {getServices },
130133 wantNonResourceRules : nil , // global service accounts do no work without a cluster.
131134 },
132- // TODO(cnvergence): restore the commented lines once we drop the global service account feature flag
135+ // TODO(cnvergence): restore the skip field once we drop the global service account feature flag
133136 {
134- name : "service account with this cluster" ,
135- user : & user.DefaultInfo {Name : "system:serviceaccount:default:sa" , Groups : []string {"system:serviceaccounts" , user .AllAuthenticated }, Extra : map [string ][]string {authserviceaccount .ClusterNameKey : {"this" }}},
136- wantResourceRules : []authorizer.ResourceRuleInfo {getServices },
137- // wantNonResourceRules: []authorizer.NonResourceRuleInfo{getReadyz},
138- wantNonResourceRules : nil ,
137+ name : "service account with this cluster" ,
138+ user : & user.DefaultInfo {Name : "system:serviceaccount:default:sa" , Groups : []string {"system:serviceaccounts" , user .AllAuthenticated }, Extra : map [string ][]string {authserviceaccount .ClusterNameKey : {"this" }}},
139+ wantResourceRules : []authorizer.ResourceRuleInfo {getServices },
140+ wantNonResourceRules : []authorizer.NonResourceRuleInfo {getReadyz },
141+ skip : ! utilfeature . DefaultFeatureGate . Enabled ( features . GlobalServiceAccount ) ,
139142 },
140143 {
141- name : "service account with other cluster" ,
142- user : & user.DefaultInfo {Name : "system:serviceaccount:default:sa" , Groups : []string {"system:serviceaccounts" , user .AllAuthenticated }, Extra : map [string ][]string {authserviceaccount .ClusterNameKey : {"other" }}},
143- // wantNonResourceRules: []authorizer.NonResourceRuleInfo{getMetrics},
144- wantNonResourceRules : nil ,
144+ name : "service account with other cluster" ,
145+ user : & user.DefaultInfo {Name : "system:serviceaccount:default:sa" , Groups : []string {"system:serviceaccounts" , user .AllAuthenticated }, Extra : map [string ][]string {authserviceaccount .ClusterNameKey : {"other" }}},
146+ wantNonResourceRules : []authorizer.NonResourceRuleInfo {getMetrics },
147+ skip : ! utilfeature . DefaultFeatureGate . Enabled ( features . GlobalServiceAccount ) ,
145148 },
146149 {
147150 name : "base with service account warrant without cluster, ignored" ,
@@ -281,7 +284,7 @@ func TestResolverWithWarrants(t *testing.T) {
281284 sort .Sort (sortedResourceRules (resourceRules ))
282285 sort .Sort (sortedNonResourceRules (nonResourceRules ))
283286
284- if ! tt .wantError {
287+ if ! tt .wantError && ! tt . skip {
285288 if diff := cmp .Diff (resourceRules , tt .wantResourceRules ); diff != "" {
286289 t .Errorf ("resourceRules differs: +want -got:\n %s" , diff )
287290 }
0 commit comments