Skip to content

Commit 5954f34

Browse files
committed
migrate authenticator and authorizer to Create
1 parent 119f220 commit 5954f34

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

staging/src/k8s.io/apiserver/plugin/pkg/authenticator/token/webhook/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ go_library(
3636
deps = [
3737
"//staging/src/k8s.io/api/authentication/v1:go_default_library",
3838
"//staging/src/k8s.io/api/authentication/v1beta1:go_default_library",
39+
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
3940
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
4041
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
4142
"//staging/src/k8s.io/apiserver/pkg/authentication/authenticator:go_default_library",

staging/src/k8s.io/apiserver/plugin/pkg/authenticator/token/webhook/webhook.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
authenticationv1 "k8s.io/api/authentication/v1"
2727
authenticationv1beta1 "k8s.io/api/authentication/v1beta1"
28+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2829
"k8s.io/apimachinery/pkg/runtime"
2930
"k8s.io/apimachinery/pkg/runtime/schema"
3031
"k8s.io/apiserver/pkg/authentication/authenticator"
@@ -41,7 +42,7 @@ const retryBackoff = 500 * time.Millisecond
4142
var _ authenticator.Token = (*WebhookTokenAuthenticator)(nil)
4243

4344
type tokenReviewer interface {
44-
CreateContext(ctx context.Context, review *authenticationv1.TokenReview) (*authenticationv1.TokenReview, error)
45+
Create(ctx context.Context, review *authenticationv1.TokenReview, _ metav1.CreateOptions) (*authenticationv1.TokenReview, error)
4546
}
4647

4748
type WebhookTokenAuthenticator struct {
@@ -101,7 +102,7 @@ func (w *WebhookTokenAuthenticator) AuthenticateToken(ctx context.Context, token
101102
auds authenticator.Audiences
102103
)
103104
webhook.WithExponentialBackoff(ctx, w.initialBackoff, func() error {
104-
result, err = w.tokenReview.CreateContext(ctx, r)
105+
result, err = w.tokenReview.Create(ctx, r, metav1.CreateOptions{})
105106
return err
106107
}, webhook.DefaultShouldRetry)
107108
if err != nil {
@@ -196,7 +197,7 @@ type tokenReviewV1Client struct {
196197
w *webhook.GenericWebhook
197198
}
198199

199-
func (t *tokenReviewV1Client) CreateContext(ctx context.Context, review *authenticationv1.TokenReview) (*authenticationv1.TokenReview, error) {
200+
func (t *tokenReviewV1Client) Create(ctx context.Context, review *authenticationv1.TokenReview, _ metav1.CreateOptions) (*authenticationv1.TokenReview, error) {
200201
result := &authenticationv1.TokenReview{}
201202
err := t.w.RestClient.Post().Body(review).Do(ctx).Into(result)
202203
return result, err
@@ -206,7 +207,7 @@ type tokenReviewV1beta1Client struct {
206207
w *webhook.GenericWebhook
207208
}
208209

209-
func (t *tokenReviewV1beta1Client) CreateContext(ctx context.Context, review *authenticationv1.TokenReview) (*authenticationv1.TokenReview, error) {
210+
func (t *tokenReviewV1beta1Client) Create(ctx context.Context, review *authenticationv1.TokenReview, _ metav1.CreateOptions) (*authenticationv1.TokenReview, error) {
210211
v1beta1Review := &authenticationv1beta1.TokenReview{Spec: v1SpecToV1beta1Spec(&review.Spec)}
211212
v1beta1Result := &authenticationv1beta1.TokenReview{}
212213
err := t.w.RestClient.Post().Body(v1beta1Review).Do(ctx).Into(v1beta1Result)

staging/src/k8s.io/apiserver/plugin/pkg/authorizer/webhook/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ go_library(
3535
deps = [
3636
"//staging/src/k8s.io/api/authorization/v1:go_default_library",
3737
"//staging/src/k8s.io/api/authorization/v1beta1:go_default_library",
38+
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
3839
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
3940
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
4041
"//staging/src/k8s.io/apimachinery/pkg/util/cache:go_default_library",

staging/src/k8s.io/apiserver/plugin/pkg/authorizer/webhook/webhook.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727

2828
authorizationv1 "k8s.io/api/authorization/v1"
2929
authorizationv1beta1 "k8s.io/api/authorization/v1beta1"
30+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3031
"k8s.io/apimachinery/pkg/runtime"
3132
"k8s.io/apimachinery/pkg/runtime/schema"
3233
"k8s.io/apimachinery/pkg/util/cache"
@@ -47,7 +48,7 @@ const (
4748
var _ authorizer.Authorizer = (*WebhookAuthorizer)(nil)
4849

4950
type subjectAccessReviewer interface {
50-
CreateContext(context.Context, *authorizationv1.SubjectAccessReview) (*authorizationv1.SubjectAccessReview, error)
51+
Create(context.Context, *authorizationv1.SubjectAccessReview, metav1.CreateOptions) (*authorizationv1.SubjectAccessReview, error)
5152
}
5253

5354
type WebhookAuthorizer struct {
@@ -189,7 +190,7 @@ func (w *WebhookAuthorizer) Authorize(ctx context.Context, attr authorizer.Attri
189190
err error
190191
)
191192
webhook.WithExponentialBackoff(ctx, w.initialBackoff, func() error {
192-
result, err = w.subjectAccessReview.CreateContext(ctx, r)
193+
result, err = w.subjectAccessReview.Create(ctx, r, metav1.CreateOptions{})
193194
return err
194195
}, webhook.DefaultShouldRetry)
195196
if err != nil {
@@ -287,7 +288,7 @@ type subjectAccessReviewV1Client struct {
287288
w *webhook.GenericWebhook
288289
}
289290

290-
func (t *subjectAccessReviewV1Client) CreateContext(ctx context.Context, subjectAccessReview *authorizationv1.SubjectAccessReview) (*authorizationv1.SubjectAccessReview, error) {
291+
func (t *subjectAccessReviewV1Client) Create(ctx context.Context, subjectAccessReview *authorizationv1.SubjectAccessReview, _ metav1.CreateOptions) (*authorizationv1.SubjectAccessReview, error) {
291292
result := &authorizationv1.SubjectAccessReview{}
292293
err := t.w.RestClient.Post().Body(subjectAccessReview).Do(ctx).Into(result)
293294
return result, err
@@ -297,7 +298,7 @@ type subjectAccessReviewV1beta1Client struct {
297298
w *webhook.GenericWebhook
298299
}
299300

300-
func (t *subjectAccessReviewV1beta1Client) CreateContext(ctx context.Context, subjectAccessReview *authorizationv1.SubjectAccessReview) (*authorizationv1.SubjectAccessReview, error) {
301+
func (t *subjectAccessReviewV1beta1Client) Create(ctx context.Context, subjectAccessReview *authorizationv1.SubjectAccessReview, _ metav1.CreateOptions) (*authorizationv1.SubjectAccessReview, error) {
301302
v1beta1Review := &authorizationv1beta1.SubjectAccessReview{Spec: v1SpecToV1beta1Spec(&subjectAccessReview.Spec)}
302303
v1beta1Result := &authorizationv1beta1.SubjectAccessReview{}
303304
err := t.w.RestClient.Post().Body(v1beta1Review).Do(ctx).Into(v1beta1Result)

0 commit comments

Comments
 (0)