Skip to content

Commit 13460c3

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 13460c3

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-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

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

Comments
 (0)