Commit 80f26fa8 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #44523 from caesarxuchao/remove-client-go-api-scheme

Automatic merge from submit-queue Remove imports of k8s.io/client-go/pkg/api k8s.io/client-go/pkg/api will be eliminated by #44784, so we need to remove all imports of it. This PR is large, but mostly simple changes, like: * using constants defined in the v1 package instead of those in the internal package * using k8s.io/client-go/kubernetes/scheme.Codecs/Schemes instead of those in k8s.io/client-go/pkg/api * using `v1.SchemeGroupVersion` instead of `api.Registry.GroupOrDie(api.GroupName).GroupVersion` in tests * importing `k8s.io/kubernetes/pkg/api` instead of `k8s.io/client-go/pkg/api` if possible With this PR https://github.com/kubernetes/kubernetes/pull/45159, the only remaining imports of `k8s.io/client-go/pkg/api` are from k8s.io/metrics. ``` bash $ git grep "\"k8s.io/client-go/pkg/api\"" | grep -v "staging/src/k8s.io/client-go/pkg/api" staging/src/k8s.io/metrics/pkg/apis/custom_metrics/install/install.go:25: "k8s.io/client-go/pkg/api" Binary file staging/src/k8s.io/metrics/pkg/apis/custom_metrics/types.generated.go matches staging/src/k8s.io/metrics/pkg/apis/custom_metrics/types.go:22: "k8s.io/client-go/pkg/api" staging/src/k8s.io/metrics/pkg/apis/metrics/install/install.go:26: "k8s.io/client-go/pkg/api" staging/src/k8s.io/metrics/pkg/apis/metrics/types.go:21: "k8s.io/client-go/pkg/api" Binary file staging/src/k8s.io/metrics/pkg/apis/metrics/v1alpha1/zz_generated.conversion.go matches Binary file staging/src/k8s.io/metrics/pkg/apis/metrics/zz_generated.deepcopy.go matches staging/src/k8s.io/metrics/pkg/client/clientset_generated/clientset/fake/clientset_generated.go:24: "k8s.io/client-go/pkg/api" staging/src/k8s.io/metrics/pkg/client/custom_metrics/client.go:26: "k8s.io/client-go/pkg/api" staging/src/k8s.io/metrics/pkg/client/custom_metrics/fake/fake_client.go:24: "k8s.io/client-go/pkg/api" ```
parents c320218d d978f22e
...@@ -22,6 +22,21 @@ import ( ...@@ -22,6 +22,21 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
) )
const (
// ImpersonateUserHeader is used to impersonate a particular user during an API server request
ImpersonateUserHeader = "Impersonate-User"
// ImpersonateGroupHeader is used to impersonate a particular group during an API server request.
// It can be repeated multiplied times for multiple groups.
ImpersonateGroupHeader = "Impersonate-Group"
// ImpersonateUserExtraHeaderPrefix is a prefix for any header used to impersonate an entry in the
// extra map[string][]string for user.Info. The key will be every after the prefix.
// It can be repeated multiplied times for multiple map keys and the same key can be repeated multiple
// times to have multiple elements in the slice under a single key
ImpersonateUserExtraHeaderPrefix = "Impersonate-Extra-"
)
// +genclient=true // +genclient=true
// +nonNamespaced=true // +nonNamespaced=true
// +noMethods=true // +noMethods=true
......
...@@ -195,6 +195,7 @@ function mvfolder { ...@@ -195,6 +195,7 @@ function mvfolder {
} }
mvfolder "pkg/client/clientset_generated/${CLIENTSET}" kubernetes mvfolder "pkg/client/clientset_generated/${CLIENTSET}" kubernetes
rm -f "${CLIENT_REPO_TEMP}/kubernetes/import_known_versions.go"
mvfolder "pkg/client/informers/informers_generated/externalversions" informers mvfolder "pkg/client/informers/informers_generated/externalversions" informers
mvfolder "pkg/client/listers" listers mvfolder "pkg/client/listers" listers
if [ "$(find "${CLIENT_REPO_TEMP}"/pkg/client -type f -name "*.go")" ]; then if [ "$(find "${CLIENT_REPO_TEMP}"/pkg/client -type f -name "*.go")" ]; then
......
...@@ -54,7 +54,8 @@ go_library( ...@@ -54,7 +54,8 @@ go_library(
"//vendor/k8s.io/apiserver/pkg/endpoints/handlers/responsewriters:go_default_library", "//vendor/k8s.io/apiserver/pkg/endpoints/handlers/responsewriters:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library", "//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/server/httplog:go_default_library", "//vendor/k8s.io/apiserver/pkg/server/httplog:go_default_library",
"//vendor/k8s.io/client-go/pkg/api:go_default_library", "//vendor/k8s.io/client-go/pkg/api/v1:go_default_library",
"//vendor/k8s.io/client-go/pkg/apis/authentication:go_default_library", "//vendor/k8s.io/client-go/pkg/apis/authentication:go_default_library",
"//vendor/k8s.io/client-go/pkg/apis/authentication/v1:go_default_library",
], ],
) )
...@@ -30,8 +30,8 @@ import ( ...@@ -30,8 +30,8 @@ import (
"k8s.io/apiserver/pkg/endpoints/handlers/responsewriters" "k8s.io/apiserver/pkg/endpoints/handlers/responsewriters"
"k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/server/httplog" "k8s.io/apiserver/pkg/server/httplog"
"k8s.io/client-go/pkg/api" "k8s.io/client-go/pkg/api/v1"
authenticationapi "k8s.io/client-go/pkg/apis/authentication" authenticationv1 "k8s.io/client-go/pkg/apis/authentication/v1"
) )
// WithImpersonation is a filter that will inspect and check requests that attempt to change the user.Info for their requests // WithImpersonation is a filter that will inspect and check requests that attempt to change the user.Info for their requests
...@@ -61,7 +61,7 @@ func WithImpersonation(handler http.Handler, requestContextMapper request.Reques ...@@ -61,7 +61,7 @@ func WithImpersonation(handler http.Handler, requestContextMapper request.Reques
// if groups are not specified, then we need to look them up differently depending on the type of user // if groups are not specified, then we need to look them up differently depending on the type of user
// if they are specified, then they are the authority (including the inclusion of system:authenticated/system:unauthenticated groups) // if they are specified, then they are the authority (including the inclusion of system:authenticated/system:unauthenticated groups)
groupsSpecified := len(req.Header[authenticationapi.ImpersonateGroupHeader]) > 0 groupsSpecified := len(req.Header[authenticationv1.ImpersonateGroupHeader]) > 0
// make sure we're allowed to impersonate each thing we're requesting. While we're iterating through, start building username // make sure we're allowed to impersonate each thing we're requesting. While we're iterating through, start building username
// and group information // and group information
...@@ -79,7 +79,7 @@ func WithImpersonation(handler http.Handler, requestContextMapper request.Reques ...@@ -79,7 +79,7 @@ func WithImpersonation(handler http.Handler, requestContextMapper request.Reques
} }
switch impersonationRequest.GetObjectKind().GroupVersionKind().GroupKind() { switch impersonationRequest.GetObjectKind().GroupVersionKind().GroupKind() {
case api.Kind("ServiceAccount"): case v1.SchemeGroupVersion.WithKind("ServiceAccount").GroupKind():
actingAsAttributes.Resource = "serviceaccounts" actingAsAttributes.Resource = "serviceaccounts"
username = serviceaccount.MakeUsername(impersonationRequest.Namespace, impersonationRequest.Name) username = serviceaccount.MakeUsername(impersonationRequest.Namespace, impersonationRequest.Name)
if !groupsSpecified { if !groupsSpecified {
...@@ -87,15 +87,15 @@ func WithImpersonation(handler http.Handler, requestContextMapper request.Reques ...@@ -87,15 +87,15 @@ func WithImpersonation(handler http.Handler, requestContextMapper request.Reques
groups = serviceaccount.MakeGroupNames(impersonationRequest.Namespace, impersonationRequest.Name) groups = serviceaccount.MakeGroupNames(impersonationRequest.Namespace, impersonationRequest.Name)
} }
case api.Kind("User"): case v1.SchemeGroupVersion.WithKind("User").GroupKind():
actingAsAttributes.Resource = "users" actingAsAttributes.Resource = "users"
username = impersonationRequest.Name username = impersonationRequest.Name
case api.Kind("Group"): case v1.SchemeGroupVersion.WithKind("Group").GroupKind():
actingAsAttributes.Resource = "groups" actingAsAttributes.Resource = "groups"
groups = append(groups, impersonationRequest.Name) groups = append(groups, impersonationRequest.Name)
case authenticationapi.Kind("UserExtra"): case authenticationv1.SchemeGroupVersion.WithKind("UserExtra").GroupKind():
extraKey := impersonationRequest.FieldPath extraKey := impersonationRequest.FieldPath
extraValue := impersonationRequest.Name extraValue := impersonationRequest.Name
actingAsAttributes.Resource = "userextras" actingAsAttributes.Resource = "userextras"
...@@ -143,10 +143,10 @@ func WithImpersonation(handler http.Handler, requestContextMapper request.Reques ...@@ -143,10 +143,10 @@ func WithImpersonation(handler http.Handler, requestContextMapper request.Reques
httplog.LogOf(req, w).Addf("%v is acting as %v", oldUser, newUser) httplog.LogOf(req, w).Addf("%v is acting as %v", oldUser, newUser)
// clear all the impersonation headers from the request // clear all the impersonation headers from the request
req.Header.Del(authenticationapi.ImpersonateUserHeader) req.Header.Del(authenticationv1.ImpersonateUserHeader)
req.Header.Del(authenticationapi.ImpersonateGroupHeader) req.Header.Del(authenticationv1.ImpersonateGroupHeader)
for headerName := range req.Header { for headerName := range req.Header {
if strings.HasPrefix(headerName, authenticationapi.ImpersonateUserExtraHeaderPrefix) { if strings.HasPrefix(headerName, authenticationv1.ImpersonateUserExtraHeaderPrefix) {
req.Header.Del(headerName) req.Header.Del(headerName)
} }
} }
...@@ -158,42 +158,42 @@ func WithImpersonation(handler http.Handler, requestContextMapper request.Reques ...@@ -158,42 +158,42 @@ func WithImpersonation(handler http.Handler, requestContextMapper request.Reques
// buildImpersonationRequests returns a list of objectreferences that represent the different things we're requesting to impersonate. // buildImpersonationRequests returns a list of objectreferences that represent the different things we're requesting to impersonate.
// Also includes a map[string][]string representing user.Info.Extra // Also includes a map[string][]string representing user.Info.Extra
// Each request must be authorized against the current user before switching contexts. // Each request must be authorized against the current user before switching contexts.
func buildImpersonationRequests(headers http.Header) ([]api.ObjectReference, error) { func buildImpersonationRequests(headers http.Header) ([]v1.ObjectReference, error) {
impersonationRequests := []api.ObjectReference{} impersonationRequests := []v1.ObjectReference{}
requestedUser := headers.Get(authenticationapi.ImpersonateUserHeader) requestedUser := headers.Get(authenticationv1.ImpersonateUserHeader)
hasUser := len(requestedUser) > 0 hasUser := len(requestedUser) > 0
if hasUser { if hasUser {
if namespace, name, err := serviceaccount.SplitUsername(requestedUser); err == nil { if namespace, name, err := serviceaccount.SplitUsername(requestedUser); err == nil {
impersonationRequests = append(impersonationRequests, api.ObjectReference{Kind: "ServiceAccount", Namespace: namespace, Name: name}) impersonationRequests = append(impersonationRequests, v1.ObjectReference{Kind: "ServiceAccount", Namespace: namespace, Name: name})
} else { } else {
impersonationRequests = append(impersonationRequests, api.ObjectReference{Kind: "User", Name: requestedUser}) impersonationRequests = append(impersonationRequests, v1.ObjectReference{Kind: "User", Name: requestedUser})
} }
} }
hasGroups := false hasGroups := false
for _, group := range headers[authenticationapi.ImpersonateGroupHeader] { for _, group := range headers[authenticationv1.ImpersonateGroupHeader] {
hasGroups = true hasGroups = true
impersonationRequests = append(impersonationRequests, api.ObjectReference{Kind: "Group", Name: group}) impersonationRequests = append(impersonationRequests, v1.ObjectReference{Kind: "Group", Name: group})
} }
hasUserExtra := false hasUserExtra := false
for headerName, values := range headers { for headerName, values := range headers {
if !strings.HasPrefix(headerName, authenticationapi.ImpersonateUserExtraHeaderPrefix) { if !strings.HasPrefix(headerName, authenticationv1.ImpersonateUserExtraHeaderPrefix) {
continue continue
} }
hasUserExtra = true hasUserExtra = true
extraKey := strings.ToLower(headerName[len(authenticationapi.ImpersonateUserExtraHeaderPrefix):]) extraKey := strings.ToLower(headerName[len(authenticationv1.ImpersonateUserExtraHeaderPrefix):])
// make a separate request for each extra value they're trying to set // make a separate request for each extra value they're trying to set
for _, value := range values { for _, value := range values {
impersonationRequests = append(impersonationRequests, impersonationRequests = append(impersonationRequests,
api.ObjectReference{ v1.ObjectReference{
Kind: "UserExtra", Kind: "UserExtra",
// we only parse out a group above, but the parsing will fail if there isn't SOME version // we only parse out a group above, but the parsing will fail if there isn't SOME version
// using the internal version will help us fail if anyone starts using it // using the internal version will help us fail if anyone starts using it
APIVersion: authenticationapi.SchemeGroupVersion.String(), APIVersion: authenticationv1.SchemeGroupVersion.String(),
Name: value, Name: value,
// ObjectReference doesn't have a subresource field. FieldPath is close and available, so we'll use that // ObjectReference doesn't have a subresource field. FieldPath is close and available, so we'll use that
// TODO fight the good fight for ObjectReference to refer to resources and subresources // TODO fight the good fight for ObjectReference to refer to resources and subresources
......
...@@ -28,7 +28,7 @@ go_test( ...@@ -28,7 +28,7 @@ go_test(
"//vendor/k8s.io/apiserver/pkg/features:go_default_library", "//vendor/k8s.io/apiserver/pkg/features:go_default_library",
"//vendor/k8s.io/apiserver/pkg/util/feature:go_default_library", "//vendor/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//vendor/k8s.io/apiserver/pkg/util/proxy:go_default_library", "//vendor/k8s.io/apiserver/pkg/util/proxy:go_default_library",
"//vendor/k8s.io/client-go/pkg/api:go_default_library", "//vendor/k8s.io/client-go/pkg/api/v1:go_default_library",
], ],
) )
......
...@@ -26,11 +26,11 @@ import ( ...@@ -26,11 +26,11 @@ import (
"testing" "testing"
"k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/client-go/pkg/api" "k8s.io/client-go/pkg/api/v1"
) )
func TestGenericHttpResponseChecker(t *testing.T) { func TestGenericHttpResponseChecker(t *testing.T) {
responseChecker := NewGenericHttpResponseChecker(api.Resource("pods"), "foo") responseChecker := NewGenericHttpResponseChecker(v1.Resource("pods"), "foo")
tests := []struct { tests := []struct {
resp *http.Response resp *http.Response
expectError bool expectError bool
...@@ -79,7 +79,7 @@ func TestGenericHttpResponseChecker(t *testing.T) { ...@@ -79,7 +79,7 @@ func TestGenericHttpResponseChecker(t *testing.T) {
} }
func TestGenericHttpResponseCheckerLimitReader(t *testing.T) { func TestGenericHttpResponseCheckerLimitReader(t *testing.T) {
responseChecker := NewGenericHttpResponseChecker(api.Resource("pods"), "foo") responseChecker := NewGenericHttpResponseChecker(v1.Resource("pods"), "foo")
excessedString := strings.Repeat("a", (maxReadLength + 10000)) excessedString := strings.Repeat("a", (maxReadLength + 10000))
resp := &http.Response{ resp := &http.Response{
Body: ioutil.NopCloser(bytes.NewBufferString(excessedString)), Body: ioutil.NopCloser(bytes.NewBufferString(excessedString)),
......
...@@ -30,7 +30,8 @@ go_test( ...@@ -30,7 +30,8 @@ go_test(
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library", "//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
"//vendor/k8s.io/client-go/pkg/api:go_default_library", "//vendor/k8s.io/client-go/kubernetes/scheme:go_default_library",
"//vendor/k8s.io/client-go/pkg/api/v1:go_default_library",
"//vendor/k8s.io/client-go/tools/cache:go_default_library", "//vendor/k8s.io/client-go/tools/cache:go_default_library",
"//vendor/k8s.io/client-go/util/clock:go_default_library", "//vendor/k8s.io/client-go/util/clock:go_default_library",
], ],
......
...@@ -24,7 +24,8 @@ import ( ...@@ -24,7 +24,8 @@ import (
"k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/pkg/api" "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/pkg/api/v1"
) )
// verifies the cacheWatcher.process goroutine is properly cleaned up even if // verifies the cacheWatcher.process goroutine is properly cleaned up even if
...@@ -39,12 +40,12 @@ func TestCacheWatcherCleanupNotBlockedByResult(t *testing.T) { ...@@ -39,12 +40,12 @@ func TestCacheWatcherCleanupNotBlockedByResult(t *testing.T) {
count++ count++
} }
initEvents := []*watchCacheEvent{ initEvents := []*watchCacheEvent{
{Object: &api.Pod{}}, {Object: &v1.Pod{}},
{Object: &api.Pod{}}, {Object: &v1.Pod{}},
} }
// set the size of the buffer of w.result to 0, so that the writes to // set the size of the buffer of w.result to 0, so that the writes to
// w.result is blocked. // w.result is blocked.
w := newCacheWatcher(api.Scheme, 0, 0, initEvents, filter, forget) w := newCacheWatcher(scheme.Scheme, 0, 0, initEvents, filter, forget)
w.Stop() w.Stop()
if err := wait.PollImmediate(1*time.Second, 5*time.Second, func() (bool, error) { if err := wait.PollImmediate(1*time.Second, 5*time.Second, func() (bool, error) {
lock.RLock() lock.RLock()
......
...@@ -30,13 +30,13 @@ import ( ...@@ -30,13 +30,13 @@ import (
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/watch" "k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/pkg/api" "k8s.io/client-go/pkg/api/v1"
"k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/clock" "k8s.io/client-go/util/clock"
) )
func makeTestPod(name string, resourceVersion uint64) *api.Pod { func makeTestPod(name string, resourceVersion uint64) *v1.Pod {
return &api.Pod{ return &v1.Pod{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Namespace: "ns", Namespace: "ns",
Name: name, Name: name,
...@@ -99,7 +99,7 @@ func TestWatchCacheBasic(t *testing.T) { ...@@ -99,7 +99,7 @@ func TestWatchCacheBasic(t *testing.T) {
{ {
podNames := sets.String{} podNames := sets.String{}
for _, item := range store.List() { for _, item := range store.List() {
podNames.Insert(item.(*storeElement).Object.(*api.Pod).ObjectMeta.Name) podNames.Insert(item.(*storeElement).Object.(*v1.Pod).ObjectMeta.Name)
} }
if !podNames.HasAll("pod1", "pod2", "pod3") { if !podNames.HasAll("pod1", "pod2", "pod3") {
t.Errorf("missing pods, found %v", podNames) t.Errorf("missing pods, found %v", podNames)
...@@ -117,7 +117,7 @@ func TestWatchCacheBasic(t *testing.T) { ...@@ -117,7 +117,7 @@ func TestWatchCacheBasic(t *testing.T) {
{ {
podNames := sets.String{} podNames := sets.String{}
for _, item := range store.List() { for _, item := range store.List() {
podNames.Insert(item.(*storeElement).Object.(*api.Pod).ObjectMeta.Name) podNames.Insert(item.(*storeElement).Object.(*v1.Pod).ObjectMeta.Name)
} }
if !podNames.HasAll("pod4", "pod5") { if !podNames.HasAll("pod4", "pod5") {
t.Errorf("missing pods, found %v", podNames) t.Errorf("missing pods, found %v", podNames)
...@@ -349,10 +349,10 @@ func TestReflectorForWatchCache(t *testing.T) { ...@@ -349,10 +349,10 @@ func TestReflectorForWatchCache(t *testing.T) {
return fw, nil return fw, nil
}, },
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
return &api.PodList{ListMeta: metav1.ListMeta{ResourceVersion: "10"}}, nil return &v1.PodList{ListMeta: metav1.ListMeta{ResourceVersion: "10"}}, nil
}, },
} }
r := cache.NewReflector(lw, &api.Pod{}, store, 0) r := cache.NewReflector(lw, &v1.Pod{}, store, 0)
r.ListAndWatch(wait.NeverStop) r.ListAndWatch(wait.NeverStop)
{ {
......
...@@ -34,8 +34,9 @@ go_test( ...@@ -34,8 +34,9 @@ go_test(
tags = ["automanaged"], tags = ["automanaged"],
deps = [ deps = [
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library", "//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apimachinery/registered:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/client-go/pkg/api:go_default_library", "//vendor/k8s.io/client-go/kubernetes/scheme:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library", "//vendor/k8s.io/client-go/rest:go_default_library",
"//vendor/k8s.io/client-go/tools/clientcmd/api/v1:go_default_library", "//vendor/k8s.io/client-go/tools/clientcmd/api/v1:go_default_library",
], ],
......
...@@ -32,8 +32,9 @@ import ( ...@@ -32,8 +32,9 @@ import (
"time" "time"
apierrors "k8s.io/apimachinery/pkg/api/errors" apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apimachinery/registered"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/pkg/api" "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest" "k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd/api/v1" "k8s.io/client-go/tools/clientcmd/api/v1"
) )
...@@ -73,7 +74,8 @@ var ( ...@@ -73,7 +74,8 @@ var (
func TestDisabledGroupVersion(t *testing.T) { func TestDisabledGroupVersion(t *testing.T) {
gv := schema.GroupVersion{Group: "webhook.util.k8s.io", Version: "v1"} gv := schema.GroupVersion{Group: "webhook.util.k8s.io", Version: "v1"}
gvs := []schema.GroupVersion{gv} gvs := []schema.GroupVersion{gv}
_, err := NewGenericWebhook(api.Registry, api.Codecs, "/some/path", gvs, retryBackoff) registry := registered.NewOrDie(gv.String())
_, err := NewGenericWebhook(registry, scheme.Codecs, "/some/path", gvs, retryBackoff)
if err == nil { if err == nil {
t.Errorf("expected an error") t.Errorf("expected an error")
...@@ -270,7 +272,7 @@ func TestKubeConfigFile(t *testing.T) { ...@@ -270,7 +272,7 @@ func TestKubeConfigFile(t *testing.T) {
if err == nil { if err == nil {
defer os.Remove(kubeConfigFile) defer os.Remove(kubeConfigFile)
_, err = NewGenericWebhook(api.Registry, api.Codecs, kubeConfigFile, groupVersions, retryBackoff) _, err = NewGenericWebhook(registered.NewOrDie(""), scheme.Codecs, kubeConfigFile, groupVersions, retryBackoff)
} }
return err return err
...@@ -293,7 +295,7 @@ func TestKubeConfigFile(t *testing.T) { ...@@ -293,7 +295,7 @@ func TestKubeConfigFile(t *testing.T) {
// TestMissingKubeConfigFile ensures that a kube config path to a missing file is handled properly // TestMissingKubeConfigFile ensures that a kube config path to a missing file is handled properly
func TestMissingKubeConfigFile(t *testing.T) { func TestMissingKubeConfigFile(t *testing.T) {
kubeConfigPath := "/some/missing/path" kubeConfigPath := "/some/missing/path"
_, err := NewGenericWebhook(api.Registry, api.Codecs, kubeConfigPath, groupVersions, retryBackoff) _, err := NewGenericWebhook(registered.NewOrDie(""), scheme.Codecs, kubeConfigPath, groupVersions, retryBackoff)
if err == nil { if err == nil {
t.Errorf("creating the webhook should had failed") t.Errorf("creating the webhook should had failed")
...@@ -405,7 +407,7 @@ func TestTLSConfig(t *testing.T) { ...@@ -405,7 +407,7 @@ func TestTLSConfig(t *testing.T) {
defer os.Remove(configFile) defer os.Remove(configFile)
wh, err := NewGenericWebhook(api.Registry, api.Codecs, configFile, groupVersions, retryBackoff) wh, err := NewGenericWebhook(registered.NewOrDie(""), scheme.Codecs, configFile, groupVersions, retryBackoff)
if err == nil { if err == nil {
err = wh.RestClient.Get().Do().Error() err = wh.RestClient.Get().Do().Error()
...@@ -497,7 +499,7 @@ func TestWithExponentialBackoff(t *testing.T) { ...@@ -497,7 +499,7 @@ func TestWithExponentialBackoff(t *testing.T) {
defer os.Remove(configFile) defer os.Remove(configFile)
wh, err := NewGenericWebhook(api.Registry, api.Codecs, configFile, groupVersions, retryBackoff) wh, err := NewGenericWebhook(registered.NewOrDie(""), scheme.Codecs, configFile, groupVersions, retryBackoff)
if err != nil { if err != nil {
t.Fatalf("failed to create the webhook: %v", err) t.Fatalf("failed to create the webhook: %v", err)
......
...@@ -29,14 +29,14 @@ go_library( ...@@ -29,14 +29,14 @@ go_library(
srcs = ["webhook.go"], srcs = ["webhook.go"],
tags = ["automanaged"], tags = ["automanaged"],
deps = [ deps = [
"//vendor/k8s.io/apimachinery/pkg/apimachinery/registered:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apiserver/pkg/authentication/authenticator:go_default_library", "//vendor/k8s.io/apiserver/pkg/authentication/authenticator:go_default_library",
"//vendor/k8s.io/apiserver/pkg/authentication/user:go_default_library", "//vendor/k8s.io/apiserver/pkg/authentication/user:go_default_library",
"//vendor/k8s.io/apiserver/pkg/util/cache:go_default_library", "//vendor/k8s.io/apiserver/pkg/util/cache:go_default_library",
"//vendor/k8s.io/apiserver/pkg/util/webhook:go_default_library", "//vendor/k8s.io/apiserver/pkg/util/webhook:go_default_library",
"//vendor/k8s.io/client-go/kubernetes/scheme:go_default_library",
"//vendor/k8s.io/client-go/kubernetes/typed/authentication/v1beta1:go_default_library", "//vendor/k8s.io/client-go/kubernetes/typed/authentication/v1beta1:go_default_library",
"//vendor/k8s.io/client-go/pkg/api:go_default_library",
"//vendor/k8s.io/client-go/pkg/apis/authentication/install:go_default_library",
"//vendor/k8s.io/client-go/pkg/apis/authentication/v1beta1:go_default_library", "//vendor/k8s.io/client-go/pkg/apis/authentication/v1beta1:go_default_library",
], ],
) )
...@@ -18,18 +18,18 @@ limitations under the License. ...@@ -18,18 +18,18 @@ limitations under the License.
package webhook package webhook
import ( import (
"fmt"
"time" "time"
"k8s.io/apimachinery/pkg/apimachinery/registered"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apiserver/pkg/authentication/authenticator" "k8s.io/apiserver/pkg/authentication/authenticator"
"k8s.io/apiserver/pkg/authentication/user" "k8s.io/apiserver/pkg/authentication/user"
"k8s.io/apiserver/pkg/util/cache" "k8s.io/apiserver/pkg/util/cache"
"k8s.io/apiserver/pkg/util/webhook" "k8s.io/apiserver/pkg/util/webhook"
"k8s.io/client-go/kubernetes/scheme"
authenticationclient "k8s.io/client-go/kubernetes/typed/authentication/v1beta1" authenticationclient "k8s.io/client-go/kubernetes/typed/authentication/v1beta1"
"k8s.io/client-go/pkg/api"
authentication "k8s.io/client-go/pkg/apis/authentication/v1beta1" authentication "k8s.io/client-go/pkg/apis/authentication/v1beta1"
_ "k8s.io/client-go/pkg/apis/authentication/install"
) )
var ( var (
...@@ -109,11 +109,24 @@ func (w *WebhookTokenAuthenticator) AuthenticateToken(token string) (user.Info, ...@@ -109,11 +109,24 @@ func (w *WebhookTokenAuthenticator) AuthenticateToken(token string) (user.Info,
}, true, nil }, true, nil
} }
// NOTE: client-go doesn't provide a registry. client-go does registers the
// authentication/v1beta1. We construct a registry that acknowledges
// authentication/v1beta1 as an enabled version to pass a check enforced in
// NewGenericWebhook.
var registry = registered.NewOrDie("")
func init() {
registry.RegisterVersions(groupVersions)
if err := registry.EnableVersions(groupVersions...); err != nil {
panic(fmt.Sprintf("failed to enable version %v", groupVersions))
}
}
// tokenReviewInterfaceFromKubeconfig builds a client from the specified kubeconfig file, // tokenReviewInterfaceFromKubeconfig builds a client from the specified kubeconfig file,
// and returns a TokenReviewInterface that uses that client. Note that the client submits TokenReview // and returns a TokenReviewInterface that uses that client. Note that the client submits TokenReview
// requests to the exact path specified in the kubeconfig file, so arbitrary non-API servers can be targeted. // requests to the exact path specified in the kubeconfig file, so arbitrary non-API servers can be targeted.
func tokenReviewInterfaceFromKubeconfig(kubeConfigFile string) (authenticationclient.TokenReviewInterface, error) { func tokenReviewInterfaceFromKubeconfig(kubeConfigFile string) (authenticationclient.TokenReviewInterface, error) {
gw, err := webhook.NewGenericWebhook(api.Registry, api.Codecs, kubeConfigFile, groupVersions, 0) gw, err := webhook.NewGenericWebhook(registry, scheme.Codecs, kubeConfigFile, groupVersions, 0)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -32,12 +32,13 @@ go_library( ...@@ -32,12 +32,13 @@ go_library(
tags = ["automanaged"], tags = ["automanaged"],
deps = [ deps = [
"//vendor/github.com/golang/glog:go_default_library", "//vendor/github.com/golang/glog:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apimachinery/registered:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apiserver/pkg/authorization/authorizer:go_default_library", "//vendor/k8s.io/apiserver/pkg/authorization/authorizer:go_default_library",
"//vendor/k8s.io/apiserver/pkg/util/cache:go_default_library", "//vendor/k8s.io/apiserver/pkg/util/cache:go_default_library",
"//vendor/k8s.io/apiserver/pkg/util/webhook:go_default_library", "//vendor/k8s.io/apiserver/pkg/util/webhook:go_default_library",
"//vendor/k8s.io/client-go/kubernetes/scheme:go_default_library",
"//vendor/k8s.io/client-go/kubernetes/typed/authorization/v1beta1:go_default_library", "//vendor/k8s.io/client-go/kubernetes/typed/authorization/v1beta1:go_default_library",
"//vendor/k8s.io/client-go/pkg/api:go_default_library",
"//vendor/k8s.io/client-go/pkg/apis/authorization/install:go_default_library", "//vendor/k8s.io/client-go/pkg/apis/authorization/install:go_default_library",
"//vendor/k8s.io/client-go/pkg/apis/authorization/v1beta1:go_default_library", "//vendor/k8s.io/client-go/pkg/apis/authorization/v1beta1:go_default_library",
], ],
......
...@@ -19,16 +19,18 @@ package webhook ...@@ -19,16 +19,18 @@ package webhook
import ( import (
"encoding/json" "encoding/json"
"fmt"
"time" "time"
"github.com/golang/glog" "github.com/golang/glog"
"k8s.io/apimachinery/pkg/apimachinery/registered"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apiserver/pkg/authorization/authorizer" "k8s.io/apiserver/pkg/authorization/authorizer"
"k8s.io/apiserver/pkg/util/cache" "k8s.io/apiserver/pkg/util/cache"
"k8s.io/apiserver/pkg/util/webhook" "k8s.io/apiserver/pkg/util/webhook"
"k8s.io/client-go/kubernetes/scheme"
authorizationclient "k8s.io/client-go/kubernetes/typed/authorization/v1beta1" authorizationclient "k8s.io/client-go/kubernetes/typed/authorization/v1beta1"
"k8s.io/client-go/pkg/api"
authorization "k8s.io/client-go/pkg/apis/authorization/v1beta1" authorization "k8s.io/client-go/pkg/apis/authorization/v1beta1"
_ "k8s.io/client-go/pkg/apis/authorization/install" _ "k8s.io/client-go/pkg/apis/authorization/install"
...@@ -207,11 +209,24 @@ func convertToSARExtra(extra map[string][]string) map[string]authorization.Extra ...@@ -207,11 +209,24 @@ func convertToSARExtra(extra map[string][]string) map[string]authorization.Extra
return ret return ret
} }
// NOTE: client-go doesn't provide a registry. client-go does registers the
// authorization/v1beta1. We construct a registry that acknowledges
// authorization/v1beta1 as an enabled version to pass a check enforced in
// NewGenericWebhook.
var registry = registered.NewOrDie("")
func init() {
registry.RegisterVersions(groupVersions)
if err := registry.EnableVersions(groupVersions...); err != nil {
panic(fmt.Sprintf("failed to enable version %v", groupVersions))
}
}
// subjectAccessReviewInterfaceFromKubeconfig builds a client from the specified kubeconfig file, // subjectAccessReviewInterfaceFromKubeconfig builds a client from the specified kubeconfig file,
// and returns a SubjectAccessReviewInterface that uses that client. Note that the client submits SubjectAccessReview // and returns a SubjectAccessReviewInterface that uses that client. Note that the client submits SubjectAccessReview
// requests to the exact path specified in the kubeconfig file, so arbitrary non-API servers can be targeted. // requests to the exact path specified in the kubeconfig file, so arbitrary non-API servers can be targeted.
func subjectAccessReviewInterfaceFromKubeconfig(kubeConfigFile string) (authorizationclient.SubjectAccessReviewInterface, error) { func subjectAccessReviewInterfaceFromKubeconfig(kubeConfigFile string) (authorizationclient.SubjectAccessReviewInterface, error) {
gw, err := webhook.NewGenericWebhook(api.Registry, api.Codecs, kubeConfigFile, groupVersions, 0) gw, err := webhook.NewGenericWebhook(registry, scheme.Codecs, kubeConfigFile, groupVersions, 0)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -12,7 +12,6 @@ go_library( ...@@ -12,7 +12,6 @@ go_library(
srcs = [ srcs = [
"clientset.go", "clientset.go",
"doc.go", "doc.go",
"import_known_versions.go",
], ],
tags = ["automanaged"], tags = ["automanaged"],
deps = [ deps = [
...@@ -36,19 +35,6 @@ go_library( ...@@ -36,19 +35,6 @@ go_library(
"//vendor/k8s.io/client-go/kubernetes/typed/settings/v1alpha1:go_default_library", "//vendor/k8s.io/client-go/kubernetes/typed/settings/v1alpha1:go_default_library",
"//vendor/k8s.io/client-go/kubernetes/typed/storage/v1:go_default_library", "//vendor/k8s.io/client-go/kubernetes/typed/storage/v1:go_default_library",
"//vendor/k8s.io/client-go/kubernetes/typed/storage/v1beta1:go_default_library", "//vendor/k8s.io/client-go/kubernetes/typed/storage/v1beta1:go_default_library",
"//vendor/k8s.io/client-go/pkg/api:go_default_library",
"//vendor/k8s.io/client-go/pkg/api/install:go_default_library",
"//vendor/k8s.io/client-go/pkg/apis/apps/install:go_default_library",
"//vendor/k8s.io/client-go/pkg/apis/authentication/install:go_default_library",
"//vendor/k8s.io/client-go/pkg/apis/authorization/install:go_default_library",
"//vendor/k8s.io/client-go/pkg/apis/autoscaling/install:go_default_library",
"//vendor/k8s.io/client-go/pkg/apis/batch/install:go_default_library",
"//vendor/k8s.io/client-go/pkg/apis/certificates/install:go_default_library",
"//vendor/k8s.io/client-go/pkg/apis/extensions/install:go_default_library",
"//vendor/k8s.io/client-go/pkg/apis/policy/install:go_default_library",
"//vendor/k8s.io/client-go/pkg/apis/rbac/install:go_default_library",
"//vendor/k8s.io/client-go/pkg/apis/settings/install:go_default_library",
"//vendor/k8s.io/client-go/pkg/apis/storage/install:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library", "//vendor/k8s.io/client-go/rest:go_default_library",
"//vendor/k8s.io/client-go/util/flowcontrol:go_default_library", "//vendor/k8s.io/client-go/util/flowcontrol:go_default_library",
], ],
......
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package kubernetes
// These imports are the API groups the client will support.
import (
"fmt"
"k8s.io/client-go/pkg/api"
_ "k8s.io/client-go/pkg/api/install"
_ "k8s.io/client-go/pkg/apis/apps/install"
_ "k8s.io/client-go/pkg/apis/authentication/install"
_ "k8s.io/client-go/pkg/apis/authorization/install"
_ "k8s.io/client-go/pkg/apis/autoscaling/install"
_ "k8s.io/client-go/pkg/apis/batch/install"
_ "k8s.io/client-go/pkg/apis/certificates/install"
_ "k8s.io/client-go/pkg/apis/extensions/install"
_ "k8s.io/client-go/pkg/apis/policy/install"
_ "k8s.io/client-go/pkg/apis/rbac/install"
_ "k8s.io/client-go/pkg/apis/settings/install"
_ "k8s.io/client-go/pkg/apis/storage/install"
)
func init() {
if missingVersions := api.Registry.ValidateEnvRequestedVersions(); len(missingVersions) != 0 {
panic(fmt.Sprintf("KUBE_API_VERSIONS contains versions that are not installed: %q.", missingVersions))
}
}
...@@ -22,6 +22,21 @@ import ( ...@@ -22,6 +22,21 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
) )
const (
// ImpersonateUserHeader is used to impersonate a particular user during an API server request
ImpersonateUserHeader = "Impersonate-User"
// ImpersonateGroupHeader is used to impersonate a particular group during an API server request.
// It can be repeated multiplied times for multiple groups.
ImpersonateGroupHeader = "Impersonate-Group"
// ImpersonateUserExtraHeaderPrefix is a prefix for any header used to impersonate an entry in the
// extra map[string][]string for user.Info. The key will be every after the prefix.
// It can be repeated multiplied times for multiple map keys and the same key can be repeated multiple
// times to have multiple elements in the slice under a single key
ImpersonateUserExtraHeaderPrefix = "Impersonate-Extra-"
)
// +genclient=true // +genclient=true
// +nonNamespaced=true // +nonNamespaced=true
// +noMethods=true // +noMethods=true
......
...@@ -29,15 +29,16 @@ go_test( ...@@ -29,15 +29,16 @@ go_test(
"//vendor/k8s.io/apimachinery/pkg/labels:go_default_library", "//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/serializer/streaming:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime/serializer/streaming:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library", "//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/diff:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/diff:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/httpstream:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/httpstream:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/intstr:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library", "//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
"//vendor/k8s.io/client-go/pkg/api:go_default_library", "//vendor/k8s.io/client-go/kubernetes/scheme:go_default_library",
"//vendor/k8s.io/client-go/pkg/api/install:go_default_library",
"//vendor/k8s.io/client-go/pkg/api/v1:go_default_library", "//vendor/k8s.io/client-go/pkg/api/v1:go_default_library",
"//vendor/k8s.io/client-go/pkg/apis/extensions/v1beta1:go_default_library",
"//vendor/k8s.io/client-go/rest/watch:go_default_library", "//vendor/k8s.io/client-go/rest/watch:go_default_library",
"//vendor/k8s.io/client-go/tools/clientcmd/api:go_default_library", "//vendor/k8s.io/client-go/tools/clientcmd/api:go_default_library",
"//vendor/k8s.io/client-go/util/clock:go_default_library", "//vendor/k8s.io/client-go/util/clock:go_default_library",
......
...@@ -30,14 +30,13 @@ import ( ...@@ -30,14 +30,13 @@ import (
"k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/diff"
"k8s.io/client-go/pkg/api" "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/pkg/api/v1" "k8s.io/client-go/pkg/api/v1"
v1beta1 "k8s.io/client-go/pkg/apis/extensions/v1beta1"
utiltesting "k8s.io/client-go/util/testing" utiltesting "k8s.io/client-go/util/testing"
_ "k8s.io/client-go/pkg/api/install"
) )
type TestParam struct { type TestParam struct {
...@@ -50,12 +49,13 @@ type TestParam struct { ...@@ -50,12 +49,13 @@ type TestParam struct {
testBodyErrorIsNotNil bool testBodyErrorIsNotNil bool
} }
// TestSerializer makes sure that you're always able to decode an unversioned API object // TestSerializer makes sure that you're always able to decode metav1.Status
func TestSerializer(t *testing.T) { func TestSerializer(t *testing.T) {
gv := v1beta1.SchemeGroupVersion
contentConfig := ContentConfig{ contentConfig := ContentConfig{
ContentType: "application/json", ContentType: "application/json",
GroupVersion: &schema.GroupVersion{Group: "other", Version: runtime.APIVersionInternal}, GroupVersion: &gv,
NegotiatedSerializer: api.Codecs, NegotiatedSerializer: serializer.DirectCodecFactory{CodecFactory: scheme.Codecs},
} }
serializer, err := createSerializers(contentConfig) serializer, err := createSerializers(contentConfig)
...@@ -93,7 +93,7 @@ func TestDoRequestFailed(t *testing.T) { ...@@ -93,7 +93,7 @@ func TestDoRequestFailed(t *testing.T) {
Message: " \"\" not found", Message: " \"\" not found",
Details: &metav1.StatusDetails{}, Details: &metav1.StatusDetails{},
} }
expectedBody, _ := runtime.Encode(api.Codecs.LegacyCodec(v1.SchemeGroupVersion), status) expectedBody, _ := runtime.Encode(scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), status)
fakeHandler := utiltesting.FakeHandler{ fakeHandler := utiltesting.FakeHandler{
StatusCode: 404, StatusCode: 404,
ResponseBody: string(expectedBody), ResponseBody: string(expectedBody),
...@@ -132,7 +132,7 @@ func TestDoRawRequestFailed(t *testing.T) { ...@@ -132,7 +132,7 @@ func TestDoRawRequestFailed(t *testing.T) {
}, },
}, },
} }
expectedBody, _ := runtime.Encode(api.Codecs.LegacyCodec(v1.SchemeGroupVersion), status) expectedBody, _ := runtime.Encode(scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), status)
fakeHandler := utiltesting.FakeHandler{ fakeHandler := utiltesting.FakeHandler{
StatusCode: 404, StatusCode: 404,
ResponseBody: string(expectedBody), ResponseBody: string(expectedBody),
...@@ -231,12 +231,13 @@ func validate(testParam TestParam, t *testing.T, body []byte, fakeHandler *utilt ...@@ -231,12 +231,13 @@ func validate(testParam TestParam, t *testing.T, body []byte, fakeHandler *utilt
t.Errorf("Expected object not to be created") t.Errorf("Expected object not to be created")
} }
} }
statusOut, err := runtime.Decode(api.Codecs.LegacyCodec(v1.SchemeGroupVersion), body) statusOut, err := runtime.Decode(scheme.Codecs.UniversalDeserializer(), body)
if testParam.testBody { if testParam.testBody {
if testParam.testBodyErrorIsNotNil { if testParam.testBodyErrorIsNotNil && err == nil {
if err == nil { t.Errorf("Expected Error")
t.Errorf("Expected Error") }
} if !testParam.testBodyErrorIsNotNil && err != nil {
t.Errorf("Unexpected Error: %v", err)
} }
} }
...@@ -245,7 +246,7 @@ func validate(testParam TestParam, t *testing.T, body []byte, fakeHandler *utilt ...@@ -245,7 +246,7 @@ func validate(testParam TestParam, t *testing.T, body []byte, fakeHandler *utilt
t.Errorf("Unexpected mis-match. Expected %#v. Saw %#v", testParam.expStatus, statusOut) t.Errorf("Unexpected mis-match. Expected %#v. Saw %#v", testParam.expStatus, statusOut)
} }
} }
fakeHandler.ValidateRequest(t, "/"+api.Registry.GroupOrDie(api.GroupName).GroupVersion.String()+"/test", "GET", nil) fakeHandler.ValidateRequest(t, "/"+v1.SchemeGroupVersion.String()+"/test", "GET", nil)
} }
...@@ -317,8 +318,8 @@ func TestCreateBackoffManager(t *testing.T) { ...@@ -317,8 +318,8 @@ func TestCreateBackoffManager(t *testing.T) {
} }
func testServerEnv(t *testing.T, statusCode int) (*httptest.Server, *utiltesting.FakeHandler, *metav1.Status) { func testServerEnv(t *testing.T, statusCode int) (*httptest.Server, *utiltesting.FakeHandler, *metav1.Status) {
status := &metav1.Status{Status: fmt.Sprintf("%s", metav1.StatusSuccess)} status := &metav1.Status{TypeMeta: metav1.TypeMeta{APIVersion: "v1", Kind: "Status"}, Status: fmt.Sprintf("%s", metav1.StatusSuccess)}
expectedBody, _ := runtime.Encode(api.Codecs.LegacyCodec(v1.SchemeGroupVersion), status) expectedBody, _ := runtime.Encode(scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), status)
fakeHandler := utiltesting.FakeHandler{ fakeHandler := utiltesting.FakeHandler{
StatusCode: statusCode, StatusCode: statusCode,
ResponseBody: string(expectedBody), ResponseBody: string(expectedBody),
...@@ -332,8 +333,8 @@ func restClient(testServer *httptest.Server) (*RESTClient, error) { ...@@ -332,8 +333,8 @@ func restClient(testServer *httptest.Server) (*RESTClient, error) {
c, err := RESTClientFor(&Config{ c, err := RESTClientFor(&Config{
Host: testServer.URL, Host: testServer.URL,
ContentConfig: ContentConfig{ ContentConfig: ContentConfig{
GroupVersion: &api.Registry.GroupOrDie(api.GroupName).GroupVersion, GroupVersion: &v1.SchemeGroupVersion,
NegotiatedSerializer: api.Codecs, NegotiatedSerializer: serializer.DirectCodecFactory{CodecFactory: scheme.Codecs},
}, },
Username: "user", Username: "user",
Password: "pass", Password: "pass",
......
...@@ -29,12 +29,12 @@ import ( ...@@ -29,12 +29,12 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/diff"
"k8s.io/client-go/pkg/api" "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/pkg/api/v1"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api" clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
"k8s.io/client-go/util/flowcontrol" "k8s.io/client-go/util/flowcontrol"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
_ "k8s.io/client-go/pkg/api/install"
) )
func TestIsConfigTransportTLS(t *testing.T) { func TestIsConfigTransportTLS(t *testing.T) {
...@@ -139,13 +139,13 @@ func TestDefaultKubernetesUserAgent(t *testing.T) { ...@@ -139,13 +139,13 @@ func TestDefaultKubernetesUserAgent(t *testing.T) {
} }
func TestRESTClientRequires(t *testing.T) { func TestRESTClientRequires(t *testing.T) {
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", ContentConfig: ContentConfig{NegotiatedSerializer: api.Codecs}}); err == nil { if _, err := RESTClientFor(&Config{Host: "127.0.0.1", ContentConfig: ContentConfig{NegotiatedSerializer: scheme.Codecs}}); err == nil {
t.Errorf("unexpected non-error") t.Errorf("unexpected non-error")
} }
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", ContentConfig: ContentConfig{GroupVersion: &api.Registry.GroupOrDie(api.GroupName).GroupVersion}}); err == nil { if _, err := RESTClientFor(&Config{Host: "127.0.0.1", ContentConfig: ContentConfig{GroupVersion: &v1.SchemeGroupVersion}}); err == nil {
t.Errorf("unexpected non-error") t.Errorf("unexpected non-error")
} }
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", ContentConfig: ContentConfig{GroupVersion: &api.Registry.GroupOrDie(api.GroupName).GroupVersion, NegotiatedSerializer: api.Codecs}}); err != nil { if _, err := RESTClientFor(&Config{Host: "127.0.0.1", ContentConfig: ContentConfig{GroupVersion: &v1.SchemeGroupVersion, NegotiatedSerializer: scheme.Codecs}}); err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
} }
......
...@@ -34,11 +34,12 @@ go_test( ...@@ -34,11 +34,12 @@ go_test(
"//vendor/k8s.io/apimachinery/pkg/api/equality:go_default_library", "//vendor/k8s.io/apimachinery/pkg/api/equality:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/serializer/json:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/serializer/streaming:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime/serializer/streaming:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library", "//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
"//vendor/k8s.io/client-go/pkg/api:go_default_library", "//vendor/k8s.io/client-go/kubernetes/scheme:go_default_library",
"//vendor/k8s.io/client-go/pkg/api/install:go_default_library",
"//vendor/k8s.io/client-go/pkg/api/v1:go_default_library", "//vendor/k8s.io/client-go/pkg/api/v1:go_default_library",
"//vendor/k8s.io/client-go/rest/watch:go_default_library", "//vendor/k8s.io/client-go/rest/watch:go_default_library",
], ],
......
...@@ -25,28 +25,35 @@ import ( ...@@ -25,28 +25,35 @@ import (
apiequality "k8s.io/apimachinery/pkg/api/equality" apiequality "k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
runtimejson "k8s.io/apimachinery/pkg/runtime/serializer/json"
"k8s.io/apimachinery/pkg/runtime/serializer/streaming" "k8s.io/apimachinery/pkg/runtime/serializer/streaming"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/watch" "k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/pkg/api" "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/pkg/api/v1" "k8s.io/client-go/pkg/api/v1"
restclientwatch "k8s.io/client-go/rest/watch" restclientwatch "k8s.io/client-go/rest/watch"
_ "k8s.io/client-go/pkg/api/install"
) )
// getDecoder mimics how k8s.io/client-go/rest.createSerializers creates a decoder
func getDecoder() runtime.Decoder {
jsonSerializer := runtimejson.NewSerializer(runtimejson.DefaultMetaFactory, scheme.Scheme, scheme.Scheme, false)
directCodecFactory := serializer.DirectCodecFactory{CodecFactory: scheme.Codecs}
return directCodecFactory.DecoderToVersion(jsonSerializer, v1.SchemeGroupVersion)
}
func TestDecoder(t *testing.T) { func TestDecoder(t *testing.T) {
table := []watch.EventType{watch.Added, watch.Deleted, watch.Modified, watch.Error} table := []watch.EventType{watch.Added, watch.Deleted, watch.Modified, watch.Error}
for _, eventType := range table { for _, eventType := range table {
out, in := io.Pipe() out, in := io.Pipe()
codec := api.Codecs.LegacyCodec(v1.SchemeGroupVersion)
decoder := restclientwatch.NewDecoder(streaming.NewDecoder(out, codec), codec)
expect := &api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}} decoder := restclientwatch.NewDecoder(streaming.NewDecoder(out, getDecoder()), getDecoder())
expect := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
encoder := json.NewEncoder(in) encoder := json.NewEncoder(in)
go func() { go func() {
data, err := runtime.Encode(api.Codecs.LegacyCodec(v1.SchemeGroupVersion), expect) data, err := runtime.Encode(scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), expect)
if err != nil { if err != nil {
t.Fatalf("Unexpected error %v", err) t.Fatalf("Unexpected error %v", err)
} }
...@@ -93,8 +100,7 @@ func TestDecoder(t *testing.T) { ...@@ -93,8 +100,7 @@ func TestDecoder(t *testing.T) {
func TestDecoder_SourceClose(t *testing.T) { func TestDecoder_SourceClose(t *testing.T) {
out, in := io.Pipe() out, in := io.Pipe()
codec := api.Codecs.LegacyCodec(v1.SchemeGroupVersion) decoder := restclientwatch.NewDecoder(streaming.NewDecoder(out, getDecoder()), getDecoder())
decoder := restclientwatch.NewDecoder(streaming.NewDecoder(out, codec), codec)
done := make(chan struct{}) done := make(chan struct{})
......
...@@ -24,49 +24,51 @@ import ( ...@@ -24,49 +24,51 @@ import (
apiequality "k8s.io/apimachinery/pkg/api/equality" apiequality "k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
runtimejson "k8s.io/apimachinery/pkg/runtime/serializer/json"
"k8s.io/apimachinery/pkg/runtime/serializer/streaming" "k8s.io/apimachinery/pkg/runtime/serializer/streaming"
"k8s.io/apimachinery/pkg/watch" "k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/pkg/api" "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/pkg/api/v1" "k8s.io/client-go/pkg/api/v1"
restclientwatch "k8s.io/client-go/rest/watch" restclientwatch "k8s.io/client-go/rest/watch"
_ "k8s.io/client-go/pkg/api/install"
) )
// getEncoder mimics how k8s.io/client-go/rest.createSerializers creates a encoder
func getEncoder() runtime.Encoder {
jsonSerializer := runtimejson.NewSerializer(runtimejson.DefaultMetaFactory, scheme.Scheme, scheme.Scheme, false)
directCodecFactory := serializer.DirectCodecFactory{CodecFactory: scheme.Codecs}
return directCodecFactory.EncoderForVersion(jsonSerializer, v1.SchemeGroupVersion)
}
func TestEncodeDecodeRoundTrip(t *testing.T) { func TestEncodeDecodeRoundTrip(t *testing.T) {
testCases := []struct { testCases := []struct {
Type watch.EventType Type watch.EventType
Object runtime.Object Object runtime.Object
Codec runtime.Codec
}{ }{
{ {
watch.Added, watch.Added,
&api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}, &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
api.Codecs.LegacyCodec(v1.SchemeGroupVersion),
}, },
{ {
watch.Modified, watch.Modified,
&api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}, &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
api.Codecs.LegacyCodec(v1.SchemeGroupVersion),
}, },
{ {
watch.Deleted, watch.Deleted,
&api.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}, &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
api.Codecs.LegacyCodec(v1.SchemeGroupVersion),
}, },
} }
for i, testCase := range testCases { for i, testCase := range testCases {
buf := &bytes.Buffer{} buf := &bytes.Buffer{}
codec := testCase.Codec encoder := restclientwatch.NewEncoder(streaming.NewEncoder(buf, getEncoder()), getEncoder())
encoder := restclientwatch.NewEncoder(streaming.NewEncoder(buf, codec), codec)
if err := encoder.Encode(&watch.Event{Type: testCase.Type, Object: testCase.Object}); err != nil { if err := encoder.Encode(&watch.Event{Type: testCase.Type, Object: testCase.Object}); err != nil {
t.Errorf("%d: unexpected error: %v", i, err) t.Errorf("%d: unexpected error: %v", i, err)
continue continue
} }
rc := ioutil.NopCloser(buf) rc := ioutil.NopCloser(buf)
decoder := restclientwatch.NewDecoder(streaming.NewDecoder(rc, codec), codec) decoder := restclientwatch.NewDecoder(streaming.NewDecoder(rc, getDecoder()), getDecoder())
event, obj, err := decoder.Decode() event, obj, err := decoder.Decode()
if err != nil { if err != nil {
t.Errorf("%d: unexpected error: %v", i, err) t.Errorf("%d: unexpected error: %v", i, err)
......
...@@ -22,8 +22,7 @@ go_test( ...@@ -22,8 +22,7 @@ go_test(
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/diff:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/diff:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/strategicpatch:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/strategicpatch:go_default_library",
"//vendor/k8s.io/client-go/pkg/api:go_default_library", "//vendor/k8s.io/client-go/kubernetes/scheme:go_default_library",
"//vendor/k8s.io/client-go/pkg/api/install:go_default_library",
"//vendor/k8s.io/client-go/pkg/api/v1:go_default_library", "//vendor/k8s.io/client-go/pkg/api/v1:go_default_library",
"//vendor/k8s.io/client-go/pkg/api/v1/ref:go_default_library", "//vendor/k8s.io/client-go/pkg/api/v1/ref:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library", "//vendor/k8s.io/client-go/rest:go_default_library",
......
...@@ -29,8 +29,7 @@ import ( ...@@ -29,8 +29,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8sruntime "k8s.io/apimachinery/pkg/runtime" k8sruntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/strategicpatch" "k8s.io/apimachinery/pkg/util/strategicpatch"
"k8s.io/client-go/pkg/api" "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/pkg/api/install" // To register api.Pod used in tests below
"k8s.io/client-go/pkg/api/v1" "k8s.io/client-go/pkg/api/v1"
"k8s.io/client-go/pkg/api/v1/ref" "k8s.io/client-go/pkg/api/v1/ref"
restclient "k8s.io/client-go/rest" restclient "k8s.io/client-go/rest"
...@@ -120,8 +119,8 @@ func TestEventf(t *testing.T) { ...@@ -120,8 +119,8 @@ func TestEventf(t *testing.T) {
UID: "differentUid", UID: "differentUid",
}, },
} }
testRef, err := ref.GetPartialReference(api.Scheme, testPod, "spec.containers[2]") testRef, err := ref.GetPartialReference(scheme.Scheme, testPod, "spec.containers[2]")
testRef2, err := ref.GetPartialReference(api.Scheme, testPod2, "spec.containers[3]") testRef2, err := ref.GetPartialReference(scheme.Scheme, testPod2, "spec.containers[3]")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -376,7 +375,7 @@ func TestEventf(t *testing.T) { ...@@ -376,7 +375,7 @@ func TestEventf(t *testing.T) {
} }
func recorderWithFakeClock(eventSource v1.EventSource, eventBroadcaster EventBroadcaster, clock clock.Clock) EventRecorder { func recorderWithFakeClock(eventSource v1.EventSource, eventBroadcaster EventBroadcaster, clock clock.Clock) EventRecorder {
return &recorderImpl{api.Scheme, eventSource, eventBroadcaster.(*eventBroadcasterImpl).Broadcaster, clock} return &recorderImpl{scheme.Scheme, eventSource, eventBroadcaster.(*eventBroadcasterImpl).Broadcaster, clock}
} }
func TestWriteEventError(t *testing.T) { func TestWriteEventError(t *testing.T) {
...@@ -497,7 +496,7 @@ func TestLotsOfEvents(t *testing.T) { ...@@ -497,7 +496,7 @@ func TestLotsOfEvents(t *testing.T) {
logWatcher := eventBroadcaster.StartLogging(func(formatter string, args ...interface{}) { logWatcher := eventBroadcaster.StartLogging(func(formatter string, args ...interface{}) {
loggerCalled <- struct{}{} loggerCalled <- struct{}{}
}) })
recorder := eventBroadcaster.NewRecorder(api.Scheme, v1.EventSource{Component: "eventTest"}) recorder := eventBroadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "eventTest"})
ref := &v1.ObjectReference{ ref := &v1.ObjectReference{
Kind: "Pod", Kind: "Pod",
Name: "foo", Name: "foo",
...@@ -532,7 +531,7 @@ func TestEventfNoNamespace(t *testing.T) { ...@@ -532,7 +531,7 @@ func TestEventfNoNamespace(t *testing.T) {
UID: "bar", UID: "bar",
}, },
} }
testRef, err := ref.GetPartialReference(api.Scheme, testPod, "spec.containers[2]") testRef, err := ref.GetPartialReference(scheme.Scheme, testPod, "spec.containers[2]")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -638,8 +637,8 @@ func TestMultiSinkCache(t *testing.T) { ...@@ -638,8 +637,8 @@ func TestMultiSinkCache(t *testing.T) {
UID: "differentUid", UID: "differentUid",
}, },
} }
testRef, err := ref.GetPartialReference(api.Scheme, testPod, "spec.containers[2]") testRef, err := ref.GetPartialReference(scheme.Scheme, testPod, "spec.containers[2]")
testRef2, err := ref.GetPartialReference(api.Scheme, testPod2, "spec.containers[3]") testRef2, err := ref.GetPartialReference(scheme.Scheme, testPod2, "spec.containers[3]")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment