Skip to content

Commit df90ed9

Browse files
committed
set the skip flag boolean based on feature flag
On-behalf-of: @SAP [email protected] Signed-off-by: Karol Szwaj <[email protected]>
1 parent 63e69f4 commit df90ed9

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250223115924-431177b024f3 h1:YwNX7
146146
github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250223115924-431177b024f3/go.mod h1:n0+EV+LGKl1MXXqGbGcn0AaBv7hdKsdazSYuq8nM8Us=
147147
github.com/kcp-dev/client-go v0.0.0-20250223133118-3dea338dc267 h1:Ec2/Mh7mVvboBFol0S8u30arfA7oyk/VtHL9Xojjvfs=
148148
github.com/kcp-dev/client-go v0.0.0-20250223133118-3dea338dc267/go.mod h1:1lEs8b8BYzGrMr7Q8Fs7cNVaDAWogu5lLkz5t6HtRLI=
149+
github.com/kcp-dev/embeddedetcd v1.0.2 h1:9vhU1EgVrnb+mLgvEa1IoJZn00U1ZuQ+OBVIkU11yQ4=
150+
github.com/kcp-dev/embeddedetcd v1.0.2/go.mod h1:3+1niAxAa83FemGgZ/MGrcsKWXa6987GADsnUne3Uck=
149151
github.com/kcp-dev/kubernetes v0.0.0-20250313100806-0011b8c72acd h1:ia871gMMDg+TCWIBxFK7sUC5jFGZ4XAWJfEWZvh2nO8=
150152
github.com/kcp-dev/kubernetes v0.0.0-20250313100806-0011b8c72acd/go.mod h1:XYYDf1DiwQxjQVmfn0VY4xULAogCt/wxQtTzgQjZ4OY=
151153
github.com/kcp-dev/kubernetes/staging/src/k8s.io/api v0.0.0-20250313100806-0011b8c72acd h1:HZ9tCxzLuyjgaZLqLmnecO4lUqGwSBm38Pjl/8ZGyvQ=

pkg/authorization/resolver_test.go

+17-14
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)