Skip to content

Commit dd7be70

Browse files
committed
Add rbac.authorization.k8s.io/v1
1 parent 6faaca0 commit dd7be70

File tree

27 files changed

+706
-9
lines changed

27 files changed

+706
-9
lines changed

cmd/kube-apiserver/app/aggregator.go

+1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ var apiVersionPriorities = map[schema.GroupVersion]priority{
186186
{Group: "certificates.k8s.io", Version: "v1beta1"}: {group: 17300, version: 9},
187187
{Group: "networking.k8s.io", Version: "v1"}: {group: 17200, version: 15},
188188
{Group: "policy", Version: "v1beta1"}: {group: 17100, version: 9},
189+
{Group: "rbac.authorization.k8s.io", Version: "v1"}: {group: 17000, version: 15},
189190
{Group: "rbac.authorization.k8s.io", Version: "v1beta1"}: {group: 17000, version: 12},
190191
{Group: "rbac.authorization.k8s.io", Version: "v1alpha1"}: {group: 17000, version: 9},
191192
{Group: "settings.k8s.io", Version: "v1alpha1"}: {group: 16900, version: 9},

federation/pkg/kubefed/init/init_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ func fakeInitHostFactory(apiserverServiceType v1.ServiceType, federationName, na
783783
role := rbacv1beta1.Role{
784784
TypeMeta: metav1.TypeMeta{
785785
Kind: "Role",
786-
APIVersion: testapi.Rbac.GroupVersion().String(),
786+
APIVersion: rbacv1beta1.SchemeGroupVersion.String(),
787787
},
788788
ObjectMeta: metav1.ObjectMeta{
789789
Name: "federation-system:federation-controller-manager",
@@ -805,7 +805,7 @@ func fakeInitHostFactory(apiserverServiceType v1.ServiceType, federationName, na
805805
rolebinding := rbacv1beta1.RoleBinding{
806806
TypeMeta: metav1.TypeMeta{
807807
Kind: "RoleBinding",
808-
APIVersion: testapi.Rbac.GroupVersion().String(),
808+
APIVersion: rbacv1beta1.SchemeGroupVersion.String(),
809809
},
810810
ObjectMeta: metav1.ObjectMeta{
811811
Name: "federation-system:federation-controller-manager",

hack/.golint_failures

+4
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ pkg/apis/policy/v1alpha1
133133
pkg/apis/policy/v1beta1
134134
pkg/apis/policy/validation
135135
pkg/apis/rbac
136+
pkg/apis/rbac/v1
136137
pkg/apis/rbac/v1beta1
137138
pkg/apis/rbac/validation
138139
pkg/apis/scheduling
@@ -523,6 +524,7 @@ staging/src/k8s.io/api/extensions/v1beta1
523524
staging/src/k8s.io/api/imagepolicy/v1alpha1
524525
staging/src/k8s.io/api/networking/v1
525526
staging/src/k8s.io/api/policy/v1beta1
527+
staging/src/k8s.io/api/rbac/v1
526528
staging/src/k8s.io/api/rbac/v1alpha1
527529
staging/src/k8s.io/api/rbac/v1beta1
528530
staging/src/k8s.io/api/scheduling/v1alpha1
@@ -712,6 +714,8 @@ staging/src/k8s.io/client-go/kubernetes/typed/networking/v1
712714
staging/src/k8s.io/client-go/kubernetes/typed/networking/v1/fake
713715
staging/src/k8s.io/client-go/kubernetes/typed/policy/v1beta1
714716
staging/src/k8s.io/client-go/kubernetes/typed/policy/v1beta1/fake
717+
staging/src/k8s.io/client-go/kubernetes/typed/rbac/v1
718+
staging/src/k8s.io/client-go/kubernetes/typed/rbac/v1/fake
715719
staging/src/k8s.io/client-go/kubernetes/typed/rbac/v1alpha1
716720
staging/src/k8s.io/client-go/kubernetes/typed/rbac/v1alpha1/fake
717721
staging/src/k8s.io/client-go/kubernetes/typed/rbac/v1beta1

hack/lib/init.sh

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ extensions/v1beta1 \
6969
imagepolicy.k8s.io/v1alpha1 \
7070
networking.k8s.io/v1 \
7171
policy/v1beta1 \
72+
rbac.authorization.k8s.io/v1 \
7273
rbac.authorization.k8s.io/v1beta1 \
7374
rbac.authorization.k8s.io/v1alpha1 \
7475
scheduling.k8s.io/v1alpha1 \

pkg/api/defaulting_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ func TestDefaulting(t *testing.T) {
128128
{Group: "rbac.authorization.k8s.io", Version: "v1beta1", Kind: "ClusterRoleBindingList"}: {},
129129
{Group: "rbac.authorization.k8s.io", Version: "v1beta1", Kind: "RoleBinding"}: {},
130130
{Group: "rbac.authorization.k8s.io", Version: "v1beta1", Kind: "RoleBindingList"}: {},
131+
{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRoleBinding"}: {},
132+
{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRoleBindingList"}: {},
133+
{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "RoleBinding"}: {},
134+
{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "RoleBindingList"}: {},
131135
{Group: "settings.k8s.io", Version: "v1alpha1", Kind: "PodPreset"}: {},
132136
{Group: "settings.k8s.io", Version: "v1alpha1", Kind: "PodPresetList"}: {},
133137
{Group: "admissionregistration.k8s.io", Version: "v1alpha1", Kind: "InitializerConfiguration"}: {},

pkg/apis/rbac/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ filegroup(
3838
srcs = [
3939
":package-srcs",
4040
"//pkg/apis/rbac/install:all-srcs",
41+
"//pkg/apis/rbac/v1:all-srcs",
4142
"//pkg/apis/rbac/v1alpha1:all-srcs",
4243
"//pkg/apis/rbac/v1beta1:all-srcs",
4344
"//pkg/apis/rbac/validation:all-srcs",

pkg/apis/rbac/install/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ go_library(
1414
deps = [
1515
"//pkg/api:go_default_library",
1616
"//pkg/apis/rbac:go_default_library",
17+
"//pkg/apis/rbac/v1:go_default_library",
1718
"//pkg/apis/rbac/v1alpha1:go_default_library",
1819
"//pkg/apis/rbac/v1beta1:go_default_library",
1920
"//vendor/k8s.io/apimachinery/pkg/apimachinery/announced:go_default_library",

pkg/apis/rbac/install/install.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"k8s.io/apimachinery/pkg/util/sets"
2626
"k8s.io/kubernetes/pkg/api"
2727
"k8s.io/kubernetes/pkg/apis/rbac"
28+
"k8s.io/kubernetes/pkg/apis/rbac/v1"
2829
"k8s.io/kubernetes/pkg/apis/rbac/v1alpha1"
2930
"k8s.io/kubernetes/pkg/apis/rbac/v1beta1"
3031
)
@@ -37,13 +38,24 @@ func init() {
3738
func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *registered.APIRegistrationManager, scheme *runtime.Scheme) {
3839
if err := announced.NewGroupMetaFactory(
3940
&announced.GroupMetaFactoryArgs{
40-
GroupName: rbac.GroupName,
41-
VersionPreferenceOrder: []string{v1beta1.SchemeGroupVersion.Version, v1alpha1.SchemeGroupVersion.Version},
41+
GroupName: rbac.GroupName,
42+
// Rollout plan:
43+
// 1.8:
44+
// * announce deprecation of v1alpha1 (people should use v1beta1 or v1)
45+
// 1.9 (once all version-skewed API servers in an HA cluster are capable of reading/writing v1 to etcd):
46+
// * move v1 to the beginning
47+
// * add RBAC objects to update-storage-objects.sh
48+
// * update TestEtcdStoragePath to expect objects to be stored in v1
49+
// * document that RBAC storage objects should be migrated to ensure storage is a v1-level (via update-storage-objects.sh or otherwise)
50+
// 1.10 (once all stored objects are at v1):
51+
// * remove v1alpha1
52+
VersionPreferenceOrder: []string{v1beta1.SchemeGroupVersion.Version, v1.SchemeGroupVersion.Version, v1alpha1.SchemeGroupVersion.Version},
4253
ImportPrefix: "k8s.io/api/rbac",
4354
RootScopedKinds: sets.NewString("ClusterRole", "ClusterRoleBinding"),
4455
AddInternalObjectsToScheme: rbac.AddToScheme,
4556
},
4657
announced.VersionToSchemeFunc{
58+
v1.SchemeGroupVersion.Version: v1.AddToScheme,
4759
v1beta1.SchemeGroupVersion.Version: v1beta1.AddToScheme,
4860
v1alpha1.SchemeGroupVersion.Version: v1alpha1.AddToScheme,
4961
},

pkg/apis/rbac/v1/BUILD

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
licenses(["notice"])
4+
5+
load(
6+
"@io_bazel_rules_go//go:def.bzl",
7+
"go_library",
8+
)
9+
10+
go_library(
11+
name = "go_default_library",
12+
srcs = [
13+
"defaults.go",
14+
"doc.go",
15+
"helpers.go",
16+
"register.go",
17+
"zz_generated.conversion.go",
18+
"zz_generated.defaults.go",
19+
],
20+
tags = ["automanaged"],
21+
deps = [
22+
"//pkg/apis/rbac:go_default_library",
23+
"//vendor/k8s.io/api/rbac/v1:go_default_library",
24+
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
25+
"//vendor/k8s.io/apimachinery/pkg/conversion:go_default_library",
26+
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
27+
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
28+
],
29+
)
30+
31+
filegroup(
32+
name = "package-srcs",
33+
srcs = glob(["**"]),
34+
tags = ["automanaged"],
35+
visibility = ["//visibility:private"],
36+
)
37+
38+
filegroup(
39+
name = "all-srcs",
40+
srcs = [":package-srcs"],
41+
tags = ["automanaged"],
42+
)

pkg/apis/rbac/v1/defaults.go

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Copyright 2017 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1
18+
19+
import (
20+
rbacv1 "k8s.io/api/rbac/v1"
21+
"k8s.io/apimachinery/pkg/runtime"
22+
)
23+
24+
func addDefaultingFuncs(scheme *runtime.Scheme) error {
25+
return RegisterDefaults(scheme)
26+
}
27+
28+
func SetDefaults_ClusterRoleBinding(obj *rbacv1.ClusterRoleBinding) {
29+
if len(obj.RoleRef.APIGroup) == 0 {
30+
obj.RoleRef.APIGroup = GroupName
31+
}
32+
}
33+
func SetDefaults_RoleBinding(obj *rbacv1.RoleBinding) {
34+
if len(obj.RoleRef.APIGroup) == 0 {
35+
obj.RoleRef.APIGroup = GroupName
36+
}
37+
}
38+
func SetDefaults_Subject(obj *rbacv1.Subject) {
39+
if len(obj.APIGroup) == 0 {
40+
switch obj.Kind {
41+
case rbacv1.ServiceAccountKind:
42+
obj.APIGroup = ""
43+
case rbacv1.UserKind:
44+
obj.APIGroup = GroupName
45+
case rbacv1.GroupKind:
46+
obj.APIGroup = GroupName
47+
}
48+
}
49+
}

pkg/apis/rbac/v1/doc.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Copyright 2017 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// +k8s:conversion-gen=k8s.io/kubernetes/pkg/apis/rbac
18+
// +k8s:conversion-gen-external-types=../../../../vendor/k8s.io/api/rbac/v1
19+
// +k8s:defaulter-gen=TypeMeta
20+
// +k8s:defaulter-gen-input=../../../../vendor/k8s.io/api/rbac/v1
21+
22+
// +groupName=rbac.authorization.k8s.io
23+
package v1 // import "k8s.io/kubernetes/pkg/apis/rbac/v1"

pkg/apis/rbac/v1/helpers.go

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/*
2+
Copyright 2017 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1
18+
19+
import (
20+
"fmt"
21+
22+
rbacv1 "k8s.io/api/rbac/v1"
23+
24+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25+
)
26+
27+
// +k8s:deepcopy-gen=false
28+
// PolicyRuleBuilder let's us attach methods. A no-no for API types.
29+
// We use it to construct rules in code. It's more compact than trying to write them
30+
// out in a literal and allows us to perform some basic checking during construction
31+
type PolicyRuleBuilder struct {
32+
PolicyRule rbacv1.PolicyRule `protobuf:"bytes,1,opt,name=policyRule"`
33+
}
34+
35+
func NewRule(verbs ...string) *PolicyRuleBuilder {
36+
return &PolicyRuleBuilder{
37+
PolicyRule: rbacv1.PolicyRule{Verbs: verbs},
38+
}
39+
}
40+
41+
func (r *PolicyRuleBuilder) Groups(groups ...string) *PolicyRuleBuilder {
42+
r.PolicyRule.APIGroups = append(r.PolicyRule.APIGroups, groups...)
43+
return r
44+
}
45+
46+
func (r *PolicyRuleBuilder) Resources(resources ...string) *PolicyRuleBuilder {
47+
r.PolicyRule.Resources = append(r.PolicyRule.Resources, resources...)
48+
return r
49+
}
50+
51+
func (r *PolicyRuleBuilder) Names(names ...string) *PolicyRuleBuilder {
52+
r.PolicyRule.ResourceNames = append(r.PolicyRule.ResourceNames, names...)
53+
return r
54+
}
55+
56+
func (r *PolicyRuleBuilder) URLs(urls ...string) *PolicyRuleBuilder {
57+
r.PolicyRule.NonResourceURLs = append(r.PolicyRule.NonResourceURLs, urls...)
58+
return r
59+
}
60+
61+
func (r *PolicyRuleBuilder) RuleOrDie() rbacv1.PolicyRule {
62+
ret, err := r.Rule()
63+
if err != nil {
64+
panic(err)
65+
}
66+
return ret
67+
}
68+
69+
func (r *PolicyRuleBuilder) Rule() (rbacv1.PolicyRule, error) {
70+
if len(r.PolicyRule.Verbs) == 0 {
71+
return rbacv1.PolicyRule{}, fmt.Errorf("verbs are required: %#v", r.PolicyRule)
72+
}
73+
74+
switch {
75+
case len(r.PolicyRule.NonResourceURLs) > 0:
76+
if len(r.PolicyRule.APIGroups) != 0 || len(r.PolicyRule.Resources) != 0 || len(r.PolicyRule.ResourceNames) != 0 {
77+
return rbacv1.PolicyRule{}, fmt.Errorf("non-resource rule may not have apiGroups, resources, or resourceNames: %#v", r.PolicyRule)
78+
}
79+
case len(r.PolicyRule.Resources) > 0:
80+
if len(r.PolicyRule.NonResourceURLs) != 0 {
81+
return rbacv1.PolicyRule{}, fmt.Errorf("resource rule may not have nonResourceURLs: %#v", r.PolicyRule)
82+
}
83+
if len(r.PolicyRule.APIGroups) == 0 {
84+
// this a common bug
85+
return rbacv1.PolicyRule{}, fmt.Errorf("resource rule must have apiGroups: %#v", r.PolicyRule)
86+
}
87+
default:
88+
return rbacv1.PolicyRule{}, fmt.Errorf("a rule must have either nonResourceURLs or resources: %#v", r.PolicyRule)
89+
}
90+
91+
return r.PolicyRule, nil
92+
}
93+
94+
// +k8s:deepcopy-gen=false
95+
// ClusterRoleBindingBuilder let's us attach methods. A no-no for API types.
96+
// We use it to construct bindings in code. It's more compact than trying to write them
97+
// out in a literal.
98+
type ClusterRoleBindingBuilder struct {
99+
ClusterRoleBinding rbacv1.ClusterRoleBinding `protobuf:"bytes,1,opt,name=clusterRoleBinding"`
100+
}
101+
102+
func NewClusterBinding(clusterRoleName string) *ClusterRoleBindingBuilder {
103+
return &ClusterRoleBindingBuilder{
104+
ClusterRoleBinding: rbacv1.ClusterRoleBinding{
105+
ObjectMeta: metav1.ObjectMeta{Name: clusterRoleName},
106+
RoleRef: rbacv1.RoleRef{
107+
APIGroup: GroupName,
108+
Kind: "ClusterRole",
109+
Name: clusterRoleName,
110+
},
111+
},
112+
}
113+
}
114+
115+
func (r *ClusterRoleBindingBuilder) Groups(groups ...string) *ClusterRoleBindingBuilder {
116+
for _, group := range groups {
117+
r.ClusterRoleBinding.Subjects = append(r.ClusterRoleBinding.Subjects, rbacv1.Subject{Kind: rbacv1.GroupKind, Name: group})
118+
}
119+
return r
120+
}
121+
122+
func (r *ClusterRoleBindingBuilder) Users(users ...string) *ClusterRoleBindingBuilder {
123+
for _, user := range users {
124+
r.ClusterRoleBinding.Subjects = append(r.ClusterRoleBinding.Subjects, rbacv1.Subject{Kind: rbacv1.UserKind, Name: user})
125+
}
126+
return r
127+
}
128+
129+
func (r *ClusterRoleBindingBuilder) SAs(namespace string, serviceAccountNames ...string) *ClusterRoleBindingBuilder {
130+
for _, saName := range serviceAccountNames {
131+
r.ClusterRoleBinding.Subjects = append(r.ClusterRoleBinding.Subjects, rbacv1.Subject{Kind: rbacv1.ServiceAccountKind, Namespace: namespace, Name: saName})
132+
}
133+
return r
134+
}
135+
136+
func (r *ClusterRoleBindingBuilder) BindingOrDie() rbacv1.ClusterRoleBinding {
137+
ret, err := r.Binding()
138+
if err != nil {
139+
panic(err)
140+
}
141+
return ret
142+
}
143+
144+
func (r *ClusterRoleBindingBuilder) Binding() (rbacv1.ClusterRoleBinding, error) {
145+
if len(r.ClusterRoleBinding.Subjects) == 0 {
146+
return rbacv1.ClusterRoleBinding{}, fmt.Errorf("subjects are required: %#v", r.ClusterRoleBinding)
147+
}
148+
149+
return r.ClusterRoleBinding, nil
150+
}

0 commit comments

Comments
 (0)