{"action":"created","comment":{"url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments/78492620","id":78492620,"diff_hunk":"@@ -42,55 +41,87 @@ const retryBackoff = 500 * time.Millisecond\n var _ authenticator.Token = (*WebhookTokenAuthenticator)(nil)\n \n type WebhookTokenAuthenticator struct {\n-\t*webhook.GenericWebhook\n-\tresponseCache *cache.LRUExpireCache\n-\tttl           time.Duration\n+\ttokenReview    client.TokenReviewInterface\n+\tresponseCache  *cache.LRUExpireCache\n+\tttl            time.Duration\n+\tinitialBackoff time.Duration\n }\n \n-// New creates a new WebhookTokenAuthenticator from the provided kubeconfig file.\n-func New(kubeConfigFile string, ttl time.Duration) (*WebhookTokenAuthenticator, error) {\n-\treturn newWithBackoff(kubeConfigFile, ttl, retryBackoff)\n+// NewFromInterface creates a webhook authenticator using the given tokenReview client\n+func NewFromInterface(tokenReview client.TokenReviewInterface, ttl time.Duration) (*WebhookTokenAuthenticator, error) {\n+\treturn newWithBackoff(tokenReview, ttl, retryBackoff)\n }\n \n-// newWithBackoff allows tests to skip the sleep.\n-func newWithBackoff(kubeConfigFile string, ttl, initialBackoff time.Duration) (*WebhookTokenAuthenticator, error) {\n-\tgw, err := webhook.NewGenericWebhook(kubeConfigFile, groupVersions, initialBackoff)\n+// New creates a new WebhookTokenAuthenticator from the provided kubeconfig file.\n+func New(kubeConfigFile string, ttl time.Duration) (*WebhookTokenAuthenticator, error) {\n+\ttokenReview, err := tokenReviewClientFromKubeconfig(kubeConfigFile)\n \tif err != nil {\n \t\treturn nil, err\n \t}\n-\treturn &WebhookTokenAuthenticator{gw, cache.NewLRUExpireCache(1024), ttl}, nil\n+\treturn newWithBackoff(tokenReview, ttl, retryBackoff)\n+}\n+\n+// newWithBackoff allows tests to skip the sleep.\n+func newWithBackoff(tokenReview client.TokenReviewInterface, ttl, initialBackoff time.Duration) (*WebhookTokenAuthenticator, error) {\n+\treturn &WebhookTokenAuthenticator{tokenReview, cache.NewLRUExpireCache(1024), ttl, initialBackoff}, nil\n }\n \n // AuthenticateToken implements the authenticator.Token interface.\n func (w *WebhookTokenAuthenticator) AuthenticateToken(token string) (user.Info, bool, error) {\n-\tr := &v1beta1.TokenReview{\n-\t\tSpec: v1beta1.TokenReviewSpec{Token: token},\n+\tr := &authentication.TokenReview{\n+\t\tSpec: authentication.TokenReviewSpec{Token: token},\n \t}\n \tif entry, ok := w.responseCache.Get(r.Spec); ok {\n-\t\tr.Status = entry.(v1beta1.TokenReviewStatus)\n+\t\tr.Status = entry.(authentication.TokenReviewStatus)\n \t} else {\n-\t\tresult := w.WithExponentialBackoff(func() restclient.Result {\n-\t\t\treturn w.RestClient.Post().Body(r).Do()\n+\t\tvar (\n+\t\t\tresult *authentication.TokenReview\n+\t\t\terr    error\n+\t\t)\n+\t\twebhook.WithExponentialBackoff(w.initialBackoff, func() error {\n+\t\t\tresult, err = w.tokenReview.Create(r)\n+\t\t\treturn err\n \t\t})\n-\t\tif err := result.Error(); err != nil {\n-\t\t\treturn nil, false, err\n-\t\t}\n-\t\tvar statusCode int\n-\t\tif result.StatusCode(&statusCode); statusCode < 200 || statusCode >= 300 {\n-\t\t\treturn nil, false, fmt.Errorf(\"Error contacting webhook: %d\", statusCode)\n-\t\t}\n-\t\tspec := r.Spec\n-\t\tif err := result.Into(r); err != nil {\n+\t\tif err != nil {\n \t\t\treturn nil, false, err\n \t\t}\n-\t\tw.responseCache.Add(spec, r.Status, w.ttl)\n+\t\tr.Status = result.Status\n+\t\tw.responseCache.Add(r.Spec, result.Status, w.ttl)\n \t}\n \tif !r.Status.Authenticated {\n \t\treturn nil, false, nil\n \t}\n+\n+\tvar extra map[string][]string\n+\tif r.Status.User.Extra != nil {\n+\t\textra = map[string][]string{}\n+\t\tfor k, v := range r.Status.User.Extra {\n+\t\t\textra[k] = ([]string)(v)","path":"plugin/pkg/auth/authenticator/token/webhook/webhook.go","position":106,"original_position":106,"commit_id":"e6b3fe5b684bd8be5efcf78580feb33ecaffaa69","original_commit_id":"dfa66beb6912fd368c23386c0fb1698a3de92a91","user":{"login":"ericchiang","id":2342749,"avatar_url":"https://avatars.githubusercontent.com/u/2342749?v=3","gravatar_id":"","url":"https://api.github.com/users/ericchiang","html_url":"https://github.com/ericchiang","followers_url":"https://api.github.com/users/ericchiang/followers","following_url":"https://api.github.com/users/ericchiang/following{/other_user}","gists_url":"https://api.github.com/users/ericchiang/gists{/gist_id}","starred_url":"https://api.github.com/users/ericchiang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ericchiang/subscriptions","organizations_url":"https://api.github.com/users/ericchiang/orgs","repos_url":"https://api.github.com/users/ericchiang/repos","events_url":"https://api.github.com/users/ericchiang/events{/privacy}","received_events_url":"https://api.github.com/users/ericchiang/received_events","type":"User","site_admin":false},"body":"That form `(T)(var)` is evaluated at compile time, not runtime. It wouldn't even build if `v` wasn't always castable to `[]string`.","created_at":"2016-09-13T03:45:00Z","updated_at":"2016-09-13T03:45:00Z","html_url":"https://github.com/kubernetes/kubernetes/pull/32547#discussion_r78492620","pull_request_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/32547","_links":{"self":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments/78492620"},"html":{"href":"https://github.com/kubernetes/kubernetes/pull/32547#discussion_r78492620"},"pull_request":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/32547"}}},"pull_request":{"url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/32547","id":84975175,"html_url":"https://github.com/kubernetes/kubernetes/pull/32547","diff_url":"https://github.com/kubernetes/kubernetes/pull/32547.diff","patch_url":"https://github.com/kubernetes/kubernetes/pull/32547.patch","issue_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/32547","number":32547,"state":"open","locked":false,"title":"Allow webhook authenticator to use TokenReviewsInterface","user":{"login":"liggitt","id":980082,"avatar_url":"https://avatars.githubusercontent.com/u/980082?v=3","gravatar_id":"","url":"https://api.github.com/users/liggitt","html_url":"https://github.com/liggitt","followers_url":"https://api.github.com/users/liggitt/followers","following_url":"https://api.github.com/users/liggitt/following{/other_user}","gists_url":"https://api.github.com/users/liggitt/gists{/gist_id}","starred_url":"https://api.github.com/users/liggitt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liggitt/subscriptions","organizations_url":"https://api.github.com/users/liggitt/orgs","repos_url":"https://api.github.com/users/liggitt/repos","events_url":"https://api.github.com/users/liggitt/events{/privacy}","received_events_url":"https://api.github.com/users/liggitt/received_events","type":"User","site_admin":false},"body":"Refactors the authentication webhook to be able to be fed a kubeconfig file or a TokenReviewsInterface \r\n\r\nFixes a bug with webhooks not retrying on 429/500 errors\r\n\r\nRelated to https://github.com/kubernetes/kubernetes/pull/32518#discussion_r78450170\r\n\r\n<!-- Reviewable:start -->\r\nThis change is [<img src=\"https://reviewable.kubernetes.io/review_button.svg\" height=\"34\" align=\"absmiddle\" alt=\"Reviewable\"/>](https://reviewable.kubernetes.io/reviews/kubernetes/kubernetes/32547)\r\n<!-- Reviewable:end -->\r\n","created_at":"2016-09-13T02:14:43Z","updated_at":"2016-09-13T03:45:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7285c8c45bd4af85fd828539750879b57ee966a4","assignee":{"login":"ericchiang","id":2342749,"avatar_url":"https://avatars.githubusercontent.com/u/2342749?v=3","gravatar_id":"","url":"https://api.github.com/users/ericchiang","html_url":"https://github.com/ericchiang","followers_url":"https://api.github.com/users/ericchiang/followers","following_url":"https://api.github.com/users/ericchiang/following{/other_user}","gists_url":"https://api.github.com/users/ericchiang/gists{/gist_id}","starred_url":"https://api.github.com/users/ericchiang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ericchiang/subscriptions","organizations_url":"https://api.github.com/users/ericchiang/orgs","repos_url":"https://api.github.com/users/ericchiang/repos","events_url":"https://api.github.com/users/ericchiang/events{/privacy}","received_events_url":"https://api.github.com/users/ericchiang/received_events","type":"User","site_admin":false},"assignees":[{"login":"ericchiang","id":2342749,"avatar_url":"https://avatars.githubusercontent.com/u/2342749?v=3","gravatar_id":"","url":"https://api.github.com/users/ericchiang","html_url":"https://github.com/ericchiang","followers_url":"https://api.github.com/users/ericchiang/followers","following_url":"https://api.github.com/users/ericchiang/following{/other_user}","gists_url":"https://api.github.com/users/ericchiang/gists{/gist_id}","starred_url":"https://api.github.com/users/ericchiang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ericchiang/subscriptions","organizations_url":"https://api.github.com/users/ericchiang/orgs","repos_url":"https://api.github.com/users/ericchiang/repos","events_url":"https://api.github.com/users/ericchiang/events{/privacy}","received_events_url":"https://api.github.com/users/ericchiang/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/32547/commits","review_comments_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/32547/comments","review_comment_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments{/number}","comments_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/32547/comments","statuses_url":"https://api.github.com/repos/kubernetes/kubernetes/statuses/e6b3fe5b684bd8be5efcf78580feb33ecaffaa69","head":{"label":"liggitt:webhook-refactor","ref":"webhook-refactor","sha":"e6b3fe5b684bd8be5efcf78580feb33ecaffaa69","user":{"login":"liggitt","id":980082,"avatar_url":"https://avatars.githubusercontent.com/u/980082?v=3","gravatar_id":"","url":"https://api.github.com/users/liggitt","html_url":"https://github.com/liggitt","followers_url":"https://api.github.com/users/liggitt/followers","following_url":"https://api.github.com/users/liggitt/following{/other_user}","gists_url":"https://api.github.com/users/liggitt/gists{/gist_id}","starred_url":"https://api.github.com/users/liggitt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liggitt/subscriptions","organizations_url":"https://api.github.com/users/liggitt/orgs","repos_url":"https://api.github.com/users/liggitt/repos","events_url":"https://api.github.com/users/liggitt/events{/privacy}","received_events_url":"https://api.github.com/users/liggitt/received_events","type":"User","site_admin":false},"repo":{"id":22823654,"name":"kubernetes","full_name":"liggitt/kubernetes","owner":{"login":"liggitt","id":980082,"avatar_url":"https://avatars.githubusercontent.com/u/980082?v=3","gravatar_id":"","url":"https://api.github.com/users/liggitt","html_url":"https://github.com/liggitt","followers_url":"https://api.github.com/users/liggitt/followers","following_url":"https://api.github.com/users/liggitt/following{/other_user}","gists_url":"https://api.github.com/users/liggitt/gists{/gist_id}","starred_url":"https://api.github.com/users/liggitt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liggitt/subscriptions","organizations_url":"https://api.github.com/users/liggitt/orgs","repos_url":"https://api.github.com/users/liggitt/repos","events_url":"https://api.github.com/users/liggitt/events{/privacy}","received_events_url":"https://api.github.com/users/liggitt/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/liggitt/kubernetes","description":"Container Cluster Manager","fork":true,"url":"https://api.github.com/repos/liggitt/kubernetes","forks_url":"https://api.github.com/repos/liggitt/kubernetes/forks","keys_url":"https://api.github.com/repos/liggitt/kubernetes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/liggitt/kubernetes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/liggitt/kubernetes/teams","hooks_url":"https://api.github.com/repos/liggitt/kubernetes/hooks","issue_events_url":"https://api.github.com/repos/liggitt/kubernetes/issues/events{/number}","events_url":"https://api.github.com/repos/liggitt/kubernetes/events","assignees_url":"https://api.github.com/repos/liggitt/kubernetes/assignees{/user}","branches_url":"https://api.github.com/repos/liggitt/kubernetes/branches{/branch}","tags_url":"https://api.github.com/repos/liggitt/kubernetes/tags","blobs_url":"https://api.github.com/repos/liggitt/kubernetes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/liggitt/kubernetes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/liggitt/kubernetes/git/refs{/sha}","trees_url":"https://api.github.com/repos/liggitt/kubernetes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/liggitt/kubernetes/statuses/{sha}","languages_url":"https://api.github.com/repos/liggitt/kubernetes/languages","stargazers_url":"https://api.github.com/repos/liggitt/kubernetes/stargazers","contributors_url":"https://api.github.com/repos/liggitt/kubernetes/contributors","subscribers_url":"https://api.github.com/repos/liggitt/kubernetes/subscribers","subscription_url":"https://api.github.com/repos/liggitt/kubernetes/subscription","commits_url":"https://api.github.com/repos/liggitt/kubernetes/commits{/sha}","git_commits_url":"https://api.github.com/repos/liggitt/kubernetes/git/commits{/sha}","comments_url":"https://api.github.com/repos/liggitt/kubernetes/comments{/number}","issue_comment_url":"https://api.github.com/repos/liggitt/kubernetes/issues/comments{/number}","contents_url":"https://api.github.com/repos/liggitt/kubernetes/contents/{+path}","compare_url":"https://api.github.com/repos/liggitt/kubernetes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/liggitt/kubernetes/merges","archive_url":"https://api.github.com/repos/liggitt/kubernetes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/liggitt/kubernetes/downloads","issues_url":"https://api.github.com/repos/liggitt/kubernetes/issues{/number}","pulls_url":"https://api.github.com/repos/liggitt/kubernetes/pulls{/number}","milestones_url":"https://api.github.com/repos/liggitt/kubernetes/milestones{/number}","notifications_url":"https://api.github.com/repos/liggitt/kubernetes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/liggitt/kubernetes/labels{/name}","releases_url":"https://api.github.com/repos/liggitt/kubernetes/releases{/id}","deployments_url":"https://api.github.com/repos/liggitt/kubernetes/deployments","created_at":"2014-08-11T01:56:03Z","updated_at":"2016-01-12T15:52:36Z","pushed_at":"2016-09-13T02:39:14Z","git_url":"git://github.com/liggitt/kubernetes.git","ssh_url":"git@github.com:liggitt/kubernetes.git","clone_url":"https://github.com/liggitt/kubernetes.git","svn_url":"https://github.com/liggitt/kubernetes","homepage":null,"size":313347,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"kubernetes:master","ref":"master","sha":"c1f47581fa58fb4bd632a9d08cd0cea743fbebbf","user":{"login":"kubernetes","id":13629408,"avatar_url":"https://avatars.githubusercontent.com/u/13629408?v=3","gravatar_id":"","url":"https://api.github.com/users/kubernetes","html_url":"https://github.com/kubernetes","followers_url":"https://api.github.com/users/kubernetes/followers","following_url":"https://api.github.com/users/kubernetes/following{/other_user}","gists_url":"https://api.github.com/users/kubernetes/gists{/gist_id}","starred_url":"https://api.github.com/users/kubernetes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kubernetes/subscriptions","organizations_url":"https://api.github.com/users/kubernetes/orgs","repos_url":"https://api.github.com/users/kubernetes/repos","events_url":"https://api.github.com/users/kubernetes/events{/privacy}","received_events_url":"https://api.github.com/users/kubernetes/received_events","type":"Organization","site_admin":false},"repo":{"id":20580498,"name":"kubernetes","full_name":"kubernetes/kubernetes","owner":{"login":"kubernetes","id":13629408,"avatar_url":"https://avatars.githubusercontent.com/u/13629408?v=3","gravatar_id":"","url":"https://api.github.com/users/kubernetes","html_url":"https://github.com/kubernetes","followers_url":"https://api.github.com/users/kubernetes/followers","following_url":"https://api.github.com/users/kubernetes/following{/other_user}","gists_url":"https://api.github.com/users/kubernetes/gists{/gist_id}","starred_url":"https://api.github.com/users/kubernetes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kubernetes/subscriptions","organizations_url":"https://api.github.com/users/kubernetes/orgs","repos_url":"https://api.github.com/users/kubernetes/repos","events_url":"https://api.github.com/users/kubernetes/events{/privacy}","received_events_url":"https://api.github.com/users/kubernetes/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/kubernetes/kubernetes","description":"Production-Grade Container Scheduling and Management","fork":false,"url":"https://api.github.com/repos/kubernetes/kubernetes","forks_url":"https://api.github.com/repos/kubernetes/kubernetes/forks","keys_url":"https://api.github.com/repos/kubernetes/kubernetes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kubernetes/kubernetes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kubernetes/kubernetes/teams","hooks_url":"https://api.github.com/repos/kubernetes/kubernetes/hooks","issue_events_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/events{/number}","events_url":"https://api.github.com/repos/kubernetes/kubernetes/events","assignees_url":"https://api.github.com/repos/kubernetes/kubernetes/assignees{/user}","branches_url":"https://api.github.com/repos/kubernetes/kubernetes/branches{/branch}","tags_url":"https://api.github.com/repos/kubernetes/kubernetes/tags","blobs_url":"https://api.github.com/repos/kubernetes/kubernetes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kubernetes/kubernetes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kubernetes/kubernetes/git/refs{/sha}","trees_url":"https://api.github.com/repos/kubernetes/kubernetes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kubernetes/kubernetes/statuses/{sha}","languages_url":"https://api.github.com/repos/kubernetes/kubernetes/languages","stargazers_url":"https://api.github.com/repos/kubernetes/kubernetes/stargazers","contributors_url":"https://api.github.com/repos/kubernetes/kubernetes/contributors","subscribers_url":"https://api.github.com/repos/kubernetes/kubernetes/subscribers","subscription_url":"https://api.github.com/repos/kubernetes/kubernetes/subscription","commits_url":"https://api.github.com/repos/kubernetes/kubernetes/commits{/sha}","git_commits_url":"https://api.github.com/repos/kubernetes/kubernetes/git/commits{/sha}","comments_url":"https://api.github.com/repos/kubernetes/kubernetes/comments{/number}","issue_comment_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/comments{/number}","contents_url":"https://api.github.com/repos/kubernetes/kubernetes/contents/{+path}","compare_url":"https://api.github.com/repos/kubernetes/kubernetes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kubernetes/kubernetes/merges","archive_url":"https://api.github.com/repos/kubernetes/kubernetes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kubernetes/kubernetes/downloads","issues_url":"https://api.github.com/repos/kubernetes/kubernetes/issues{/number}","pulls_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls{/number}","milestones_url":"https://api.github.com/repos/kubernetes/kubernetes/milestones{/number}","notifications_url":"https://api.github.com/repos/kubernetes/kubernetes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kubernetes/kubernetes/labels{/name}","releases_url":"https://api.github.com/repos/kubernetes/kubernetes/releases{/id}","deployments_url":"https://api.github.com/repos/kubernetes/kubernetes/deployments","created_at":"2014-06-06T22:56:04Z","updated_at":"2016-09-13T02:50:03Z","pushed_at":"2016-09-13T03:40:51Z","git_url":"git://github.com/kubernetes/kubernetes.git","ssh_url":"git@github.com:kubernetes/kubernetes.git","clone_url":"https://github.com/kubernetes/kubernetes.git","svn_url":"https://github.com/kubernetes/kubernetes","homepage":"http://kubernetes.io","size":561572,"stargazers_count":16759,"watchers_count":16759,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":5389,"mirror_url":null,"open_issues_count":4379,"forks":5389,"open_issues":4379,"watchers":16759,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/32547"},"html":{"href":"https://github.com/kubernetes/kubernetes/pull/32547"},"issue":{"href":"https://api.github.com/repos/kubernetes/kubernetes/issues/32547"},"comments":{"href":"https://api.github.com/repos/kubernetes/kubernetes/issues/32547/comments"},"review_comments":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/32547/comments"},"review_comment":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/32547/commits"},"statuses":{"href":"https://api.github.com/repos/kubernetes/kubernetes/statuses/e6b3fe5b684bd8be5efcf78580feb33ecaffaa69"}}}}
{"actor":{"display_login":"ericchiang"}}