@@ -30,6 +30,8 @@ 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"
3335 rbacregistryvalidation "k8s.io/kubernetes/pkg/registry/rbac/validation"
3436 "k8s.io/kubernetes/plugin/pkg/auth/authorizer/rbac"
3537)
@@ -64,11 +66,10 @@ func TestResolverWithWarrants(t *testing.T) {
6466 Verbs : []string {"get" },
6567 NonResourceURLs : []string {"/readyz" },
6668 }
67- // TODO(cnvergence): restore the commented lines once we drop the global service account feature flag
68- /* getMetrics := &authorizer.DefaultNonResourceRuleInfo{
69+ getMetrics := & authorizer.DefaultNonResourceRuleInfo {
6970 Verbs : []string {"get" },
7071 NonResourceURLs : []string {"/metrics" },
71- } */
72+ }
7273 getRoot := & authorizer.DefaultNonResourceRuleInfo {
7374 Verbs : []string {"get" },
7475 NonResourceURLs : []string {"/" },
@@ -80,6 +81,7 @@ func TestResolverWithWarrants(t *testing.T) {
8081 wantResourceRules []authorizer.ResourceRuleInfo
8182 wantNonResourceRules []authorizer.NonResourceRuleInfo
8283 wantError bool
84+ skip bool
8385 }{
8486 {
8587 name : "base without warrants" ,
@@ -129,19 +131,19 @@ func TestResolverWithWarrants(t *testing.T) {
129131 wantResourceRules : []authorizer.ResourceRuleInfo {getServices },
130132 wantNonResourceRules : nil , // global service accounts do no work without a cluster.
131133 },
132- // TODO(cnvergence): restore the commented lines once we drop the global service account feature flag
134+ // TODO(cnvergence): restore the skip field once we drop the global service account feature flag
133135 {
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 ,
136+ name : "service account with this cluster" ,
137+ user : & user.DefaultInfo {Name : "system:serviceaccount:default:sa" , Groups : []string {"system:serviceaccounts" , user .AllAuthenticated }, Extra : map [string ][]string {authserviceaccount .ClusterNameKey : {"this" }}},
138+ wantResourceRules : []authorizer.ResourceRuleInfo {getServices },
139+ wantNonResourceRules : []authorizer.NonResourceRuleInfo {getReadyz },
140+ skip : ! utilfeature . DefaultFeatureGate . Enabled ( features . GlobalServiceAccount ) ,
139141 },
140142 {
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 ,
143+ name : "service account with other cluster" ,
144+ user : & user.DefaultInfo {Name : "system:serviceaccount:default:sa" , Groups : []string {"system:serviceaccounts" , user .AllAuthenticated }, Extra : map [string ][]string {authserviceaccount .ClusterNameKey : {"other" }}},
145+ wantNonResourceRules : []authorizer.NonResourceRuleInfo {getMetrics },
146+ skip : ! utilfeature . DefaultFeatureGate . Enabled ( features . GlobalServiceAccount ) ,
145147 },
146148 {
147149 name : "base with service account warrant without cluster, ignored" ,
@@ -281,7 +283,7 @@ func TestResolverWithWarrants(t *testing.T) {
281283 sort .Sort (sortedResourceRules (resourceRules ))
282284 sort .Sort (sortedNonResourceRules (nonResourceRules ))
283285
284- if ! tt .wantError {
286+ if ! tt .wantError && ! tt . skip {
285287 if diff := cmp .Diff (resourceRules , tt .wantResourceRules ); diff != "" {
286288 t .Errorf ("resourceRules differs: +want -got:\n %s" , diff )
287289 }
0 commit comments