Skip to content

Commit bd4bdbb

Browse files
committed
testing latest commit
1 parent abd2214 commit bd4bdbb

File tree

5 files changed

+26
-16
lines changed

5 files changed

+26
-16
lines changed

test/e2e/framework/auth/helpers.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ func WaitForNamedAuthorizationUpdate(ctx context.Context, c v1authorization.Subj
103103

104104
// BindClusterRole binds the cluster role at the cluster scope. If RBAC is not enabled, nil
105105
// is returned with no action.
106-
func BindClusterRole(ctx context.Context, c bindingsGetter, clusterRole, ns string, subjects ...rbacv1.Subject) error {
106+
func BindClusterRole(ctx context.Context, c bindingsGetter, clusterRole, ns string, subjects ...rbacv1.Subject) (*rbacv1.ClusterRoleBinding, error) {
107107
if !IsRBACEnabled(ctx, c) {
108-
return nil
108+
return nil, nil
109109
}
110110

111111
// Since the namespace names are unique, we can leave this lying around so we don't have to race any caches
112-
_, err := c.ClusterRoleBindings().Create(ctx, &rbacv1.ClusterRoleBinding{
112+
clusterRoleBinding, err := c.ClusterRoleBindings().Create(ctx, &rbacv1.ClusterRoleBinding{
113113
ObjectMeta: metav1.ObjectMeta{
114114
Name: ns + "--" + clusterRole,
115115
},
@@ -122,10 +122,10 @@ func BindClusterRole(ctx context.Context, c bindingsGetter, clusterRole, ns stri
122122
}, metav1.CreateOptions{})
123123

124124
if err != nil {
125-
return fmt.Errorf("binding clusterrole/%s for %q for %v: %w", clusterRole, ns, subjects, err)
125+
return nil, fmt.Errorf("binding clusterrole/%s for %q for %v: %w", clusterRole, ns, subjects, err)
126126
}
127127

128-
return nil
128+
return clusterRoleBinding, nil
129129
}
130130

131131
// BindClusterRoleInNamespace binds the cluster role at the namespace scope. If RBAC is not enabled, nil

test/e2e/kubectl/kubectl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ var _ = SIGDescribe("Kubectl client", func() {
573573

574574
ginkgo.By("adding rbac permissions")
575575
// grant the view permission widely to allow inspection of the `invalid` namespace and the default namespace
576-
err := e2eauth.BindClusterRole(ctx, f.ClientSet.RbacV1(), "view", f.Namespace.Name,
576+
_, err := e2eauth.BindClusterRole(ctx, f.ClientSet.RbacV1(), "view", f.Namespace.Name,
577577
rbacv1.Subject{Kind: rbacv1.ServiceAccountKind, Namespace: f.Namespace.Name, Name: "default"})
578578
framework.ExpectNoError(err)
579579

test/e2e/node/kubelet_authz.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
v1 "k8s.io/api/core/v1"
2727
rbacv1 "k8s.io/api/rbac/v1"
2828
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29-
"k8s.io/apimachinery/pkg/util/uuid"
3029
"k8s.io/apiserver/pkg/authentication/serviceaccount"
3130
"k8s.io/kubernetes/pkg/cluster/ports"
3231
"k8s.io/kubernetes/pkg/features"
@@ -60,7 +59,6 @@ var _ = SIGDescribe(framework.WithFeatureGate(features.KubeletFineGrainedAuthz),
6059
func runKubeletAuthzTest(ctx context.Context, f *framework.Framework, endpoint, authzSubresource string) string {
6160
ns := f.Namespace.Name
6261
saName := authzSubresource
63-
crName := authzSubresource + string(uuid.NewUUID())
6462
verb := "get"
6563
resource := "nodes"
6664

@@ -74,11 +72,11 @@ func runKubeletAuthzTest(ctx context.Context, f *framework.Framework, endpoint,
7472
}, metav1.CreateOptions{})
7573
framework.ExpectNoError(err)
7674

77-
ginkgo.By(fmt.Sprintf("Creating ClusterRole %s with for %s/%s", crName, resource, authzSubresource))
75+
ginkgo.By(fmt.Sprintf("Creating ClusterRole with prefix %s with for %s/%s", authzSubresource, resource, authzSubresource))
7876

79-
_, err = f.ClientSet.RbacV1().ClusterRoles().Create(ctx, &rbacv1.ClusterRole{
77+
clusterRole, err := f.ClientSet.RbacV1().ClusterRoles().Create(ctx, &rbacv1.ClusterRole{
8078
ObjectMeta: metav1.ObjectMeta{
81-
Name: crName,
79+
GenerateName: authzSubresource + "-",
8280
},
8381
Rules: []rbacv1.PolicyRule{
8482
{
@@ -89,17 +87,27 @@ func runKubeletAuthzTest(ctx context.Context, f *framework.Framework, endpoint,
8987
},
9088
}, metav1.CreateOptions{})
9189
framework.ExpectNoError(err)
90+
defer func() {
91+
ginkgo.By(fmt.Sprintf("Destroying ClusterRoles %q for this suite.", clusterRole.Name))
92+
framework.ExpectNoError(f.ClientSet.RbacV1().ClusterRoles().Delete(ctx, clusterRole.Name, metav1.DeleteOptions{}))
93+
}()
9294

9395
subject := rbacv1.Subject{
9496
Kind: rbacv1.ServiceAccountKind,
9597
Namespace: ns,
9698
Name: saName,
9799
}
98100

99-
ginkgo.By(fmt.Sprintf("Creating ClusterRoleBinding with ClusterRole %s with subject %s/%s", crName, ns, saName))
101+
ginkgo.By(fmt.Sprintf("Creating ClusterRoleBinding with ClusterRole %s with subject %s/%s", clusterRole.Name, ns, saName))
100102

101-
err = e2eauth.BindClusterRole(ctx, f.ClientSet.RbacV1(), crName, ns, subject)
103+
clusterRoleBinding, err := e2eauth.BindClusterRole(ctx, f.ClientSet.RbacV1(), clusterRole.Name, ns, subject)
102104
framework.ExpectNoError(err)
105+
defer func() {
106+
if clusterRoleBinding != nil {
107+
ginkgo.By(fmt.Sprintf("Destroying ClusterRoleBindings %q for this suite.", clusterRoleBinding.Name))
108+
framework.ExpectNoError(f.ClientSet.RbacV1().ClusterRoleBindings().Delete(ctx, clusterRoleBinding.Name, metav1.DeleteOptions{}))
109+
}
110+
}()
103111

104112
ginkgo.By("Waiting for Authorization Update.")
105113

test/e2e/storage/drivers/in_tree.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,12 @@ func (n *nfsDriver) PrepareTest(ctx context.Context, f *framework.Framework) *st
165165

166166
// TODO(mkimuram): cluster-admin gives too much right but system:persistent-volume-provisioner
167167
// is not enough. We should create new clusterrole for testing.
168-
err := e2eauth.BindClusterRole(ctx, cs.RbacV1(), "cluster-admin", ns.Name,
168+
clusterRoleBinding, err := e2eauth.BindClusterRole(ctx, cs.RbacV1(), "cluster-admin", ns.Name,
169169
rbacv1.Subject{Kind: rbacv1.ServiceAccountKind, Namespace: ns.Name, Name: "default"})
170170
framework.ExpectNoError(err)
171-
ginkgo.DeferCleanup(cs.RbacV1().ClusterRoleBindings().Delete, ns.Name+"--"+"cluster-admin", *metav1.NewDeleteOptions(0))
171+
if clusterRoleBinding != nil {
172+
ginkgo.DeferCleanup(cs.RbacV1().ClusterRoleBindings().Delete, clusterRoleBinding.Name, *metav1.NewDeleteOptions(0))
173+
}
172174

173175
err = e2eauth.WaitForAuthorizationUpdate(ctx, cs.AuthorizationV1(),
174176
serviceaccount.MakeUsername(ns.Name, "default"),

test/e2e/storage/volume_provisioning.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ var _ = utils.SIGDescribe("Dynamic Provisioning", func() {
442442
Name: serviceAccountName,
443443
}
444444

445-
err := e2eauth.BindClusterRole(ctx, c.RbacV1(), "system:persistent-volume-provisioner", ns, subject)
445+
_, err := e2eauth.BindClusterRole(ctx, c.RbacV1(), "system:persistent-volume-provisioner", ns, subject)
446446
framework.ExpectNoError(err)
447447

448448
roleName := "leader-locking-nfs-provisioner"

0 commit comments

Comments
 (0)