Skip to content

Commit

Permalink
Merge pull request kubernetes#35431 from deads2k/client-16-remove-old
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue

remove the non-generated client

Removes the non-generated client from kube.  The package has a few methods left, but nothing that needs updating when adding new groups.

@ingvagabund
  • Loading branch information
Kubernetes Submit Queue authored Oct 27, 2016
2 parents bb2c36a + 81ae130 commit 5423eaf
Show file tree
Hide file tree
Showing 136 changed files with 187 additions and 14,648 deletions.
2 changes: 1 addition & 1 deletion docs/proposals/api-group.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

1. clients:

Currently we have structured (pkg/client/unversioned#ExperimentalClient, pkg/client/unversioned#Client) and unstructured (pkg/kubectl/resource#Helper) clients. The structured clients are not scalable because each of them implements specific interface, e.g., [here](../../pkg/client/unversioned/client.go#L32). Only the unstructured clients are scalable. We should either auto-generate the code for structured clients or migrate to use the unstructured clients as much as possible.
Currently we have structured (pkg/client/unversioned#ExperimentalClient, pkg/client/unversioned#Client) and unstructured (pkg/kubectl/resource#Helper) clients. The structured clients are not scalable because each of them implements specific interface, e.g., `[here]../../pkg/client/unversioned/client.go#L32`--fixed. Only the unstructured clients are scalable. We should either auto-generate the code for structured clients or migrate to use the unstructured clients as much as possible.

We should also move the unstructured client to pkg/client/.

Expand Down
1 change: 1 addition & 0 deletions hack/.linted_packages
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pkg/auth/authorizer/union
pkg/client/metrics
pkg/client/metrics/prometheus
pkg/client/testing/core
pkg/client/typed/discovery
pkg/client/unversioned
pkg/client/unversioned/adapters/internalclientset
pkg/client/unversioned/auth
Expand Down
19 changes: 19 additions & 0 deletions pkg/client/typed/discovery/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ go_library(
name = "go_default_library",
srcs = [
"discovery_client.go",
"helper.go",
"restmapper.go",
"unstructured.go",
],
Expand All @@ -27,7 +28,9 @@ go_library(
"//pkg/client/restclient:go_default_library",
"//pkg/runtime:go_default_library",
"//pkg/runtime/serializer:go_default_library",
"//pkg/util/sets:go_default_library",
"//pkg/version:go_default_library",
"//plugin/pkg/client/auth:go_default_library",
"//vendor:github.com/emicklei/go-restful/swagger",
],
)
Expand All @@ -48,3 +51,19 @@ go_test(
"//vendor:github.com/emicklei/go-restful/swagger",
],
)

go_test(
name = "go_default_xtest",
srcs = ["helper_blackbox_test.go"],
tags = ["automanaged"],
deps = [
"//pkg/api:go_default_library",
"//pkg/api/testapi:go_default_library",
"//pkg/api/unversioned:go_default_library",
"//pkg/apimachinery/registered:go_default_library",
"//pkg/client/restclient:go_default_library",
"//pkg/client/typed/discovery:go_default_library",
"//pkg/client/unversioned/fake:go_default_library",
"//pkg/runtime:go_default_library",
],
)
135 changes: 135 additions & 0 deletions pkg/client/typed/discovery/helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
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 discovery

import (
"fmt"

"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/client/restclient"
"k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/pkg/version"
// Import solely to initialize client auth plugins.
_ "k8s.io/kubernetes/plugin/pkg/client/auth"
)

// MatchesServerVersion queries the server to compares the build version
// (git hash) of the client with the server's build version. It returns an error
// if it failed to contact the server or if the versions are not an exact match.
func MatchesServerVersion(client DiscoveryInterface, c *restclient.Config) error {
var err error
if client == nil {
client, err = NewDiscoveryClientForConfig(c)
if err != nil {
return err
}
}
cVer := version.Get()
sVer, err := client.ServerVersion()
if err != nil {
return fmt.Errorf("couldn't read version from server: %v\n", err)
}
// GitVersion includes GitCommit and GitTreeState, but best to be safe?
if cVer.GitVersion != sVer.GitVersion || cVer.GitCommit != sVer.GitCommit || cVer.GitTreeState != sVer.GitTreeState {
return fmt.Errorf("server version (%#v) differs from client version (%#v)!\n", sVer, cVer)
}

return nil
}

// NegotiateVersion queries the server's supported api versions to find
// a version that both client and server support.
// - If no version is provided, try registered client versions in order of
// preference.
// - If version is provided, but not default config (explicitly requested via
// commandline flag), and is unsupported by the server, print a warning to
// stderr and try client's registered versions in order of preference.
// - If version is config default, and the server does not support it,
// return an error.
func NegotiateVersion(client DiscoveryInterface, c *restclient.Config, requestedGV *unversioned.GroupVersion, clientRegisteredGVs []unversioned.GroupVersion) (*unversioned.GroupVersion, error) {
var err error
if client == nil {
client, err = NewDiscoveryClientForConfig(c)
if err != nil {
return nil, err
}
}
clientVersions := sets.String{}
for _, gv := range clientRegisteredGVs {
clientVersions.Insert(gv.String())
}
groups, err := client.ServerGroups()
if err != nil {
// This is almost always a connection error, and higher level code should treat this as a generic error,
// not a negotiation specific error.
return nil, err
}
versions := unversioned.ExtractGroupVersions(groups)
serverVersions := sets.String{}
for _, v := range versions {
serverVersions.Insert(v)
}

// If no version requested, use config version (may also be empty).
// make a copy of the original so we don't risk mutating input here or in the returned value
var preferredGV *unversioned.GroupVersion
switch {
case requestedGV != nil:
t := *requestedGV
preferredGV = &t
case c.GroupVersion != nil:
t := *c.GroupVersion
preferredGV = &t
}

// If version explicitly requested verify that both client and server support it.
// If server does not support warn, but try to negotiate a lower version.
if preferredGV != nil {
if !clientVersions.Has(preferredGV.String()) {
return nil, fmt.Errorf("client does not support API version %q; client supported API versions: %v", preferredGV, clientVersions)

}
// If the server supports no versions, then we should just use the preferredGV
// This can happen because discovery fails due to 403 Forbidden errors
if len(serverVersions) == 0 {
return preferredGV, nil
}
if serverVersions.Has(preferredGV.String()) {
return preferredGV, nil
}
// If we are using an explicit config version the server does not support, fail.
if (c.GroupVersion != nil) && (*preferredGV == *c.GroupVersion) {
return nil, fmt.Errorf("server does not support API version %q", preferredGV)
}
}

for _, clientGV := range clientRegisteredGVs {
if serverVersions.Has(clientGV.String()) {
// Version was not explicitly requested in command config (--api-version).
// Ok to fall back to a supported version with a warning.
// TODO: caesarxuchao: enable the warning message when we have
// proper fix. Please refer to issue #14895.
// if len(version) != 0 {
// glog.Warningf("Server does not support API version '%s'. Falling back to '%s'.", version, clientVersion)
// }
t := clientGV
return &t, nil
}
}
return nil, fmt.Errorf("failed to negotiate an api version; server supports: %v, client supports: %v",
serverVersions, clientVersions)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package unversioned_test
package discovery_test

import (
"bytes"
Expand All @@ -31,7 +31,7 @@ import (
uapi "k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apimachinery/registered"
"k8s.io/kubernetes/pkg/client/restclient"
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/typed/discovery"
"k8s.io/kubernetes/pkg/client/unversioned/fake"
"k8s.io/kubernetes/pkg/runtime"
)
Expand Down Expand Up @@ -139,9 +139,9 @@ func TestNegotiateVersion(t *testing.T) {
return &http.Response{StatusCode: test.statusCode, Header: header, Body: objBody(&uapi.APIVersions{Versions: test.serverVersions})}, nil
}),
}
c := unversioned.NewOrDie(test.config)
c.DiscoveryClient.RESTClient().(*restclient.RESTClient).Client = fakeClient.Client
response, err := unversioned.NegotiateVersion(c, test.config, test.version, test.clientVersions)
c := discovery.NewDiscoveryClientForConfigOrDie(test.config)
c.RESTClient().(*restclient.RESTClient).Client = fakeClient.Client
response, err := discovery.NegotiateVersion(c, test.config, test.version, test.clientVersions)
if err == nil && test.expectErr != nil {
t.Errorf("expected error, got nil for [%s].", test.name)
}
Expand Down
138 changes: 1 addition & 137 deletions pkg/client/unversioned/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,115 +13,32 @@ load(
go_library(
name = "go_default_library",
srcs = [
"apps.go",
"authentication.go",
"authorization.go",
"autoscaling.go",
"batch.go",
"certificates.go",
"certificatesigningrequests.go",
"client.go",
"clusterrolebindings.go",
"clusterroles.go",
"componentstatuses.go",
"conditions.go",
"configmap.go",
"containerinfo.go",
"daemon_sets.go",
"deployment.go",
"doc.go",
"endpoints.go",
"events.go",
"extensions.go",
"flags.go",
"helper.go",
"horizontalpodautoscaler.go",
"import_known_versions.go",
"ingress.go",
"jobs.go",
"limit_ranges.go",
"namespaces.go",
"network_policys.go",
"nodes.go",
"persistentvolumeclaim.go",
"persistentvolumes.go",
"pet_sets.go",
"pod_disruption_budgets.go",
"pod_templates.go",
"pods.go",
"podsecuritypolicy.go",
"policy.go",
"rbac.go",
"replica_sets.go",
"replication_controllers.go",
"resource_quotas.go",
"rolebindings.go",
"roles.go",
"scale.go",
"scheduledjobs.go",
"secrets.go",
"service_accounts.go",
"services.go",
"storage.go",
"storageclasses.go",
"subjectaccessreview.go",
"thirdpartyresources.go",
"tokenreviews.go",
],
tags = ["automanaged"],
deps = [
"//pkg/api:go_default_library",
"//pkg/api/errors:go_default_library",
"//pkg/api/install:go_default_library",
"//pkg/api/meta:go_default_library",
"//pkg/api/unversioned:go_default_library",
"//pkg/apimachinery/registered:go_default_library",
"//pkg/apis/apps:go_default_library",
"//pkg/apis/apps/install:go_default_library",
"//pkg/apis/authentication:go_default_library",
"//pkg/apis/authentication/install:go_default_library",
"//pkg/apis/authorization:go_default_library",
"//pkg/apis/authorization/install:go_default_library",
"//pkg/apis/autoscaling:go_default_library",
"//pkg/apis/autoscaling/install:go_default_library",
"//pkg/apis/batch:go_default_library",
"//pkg/apis/batch/install:go_default_library",
"//pkg/apis/certificates:go_default_library",
"//pkg/apis/certificates/install:go_default_library",
"//pkg/apis/componentconfig/install:go_default_library",
"//pkg/apis/extensions:go_default_library",
"//pkg/apis/extensions/install:go_default_library",
"//pkg/apis/policy:go_default_library",
"//pkg/apis/policy/install:go_default_library",
"//pkg/apis/rbac:go_default_library",
"//pkg/apis/rbac/install:go_default_library",
"//pkg/apis/storage:go_default_library",
"//pkg/apis/storage/install:go_default_library",
"//pkg/client/clientset_generated/internalclientset/typed/apps/unversioned:go_default_library",
"//pkg/client/clientset_generated/internalclientset/typed/batch/unversioned:go_default_library",
"//pkg/client/clientset_generated/internalclientset/typed/core/unversioned:go_default_library",
"//pkg/client/clientset_generated/internalclientset/typed/extensions/unversioned:go_default_library",
"//pkg/client/restclient:go_default_library",
"//pkg/client/typed/discovery:go_default_library",
"//pkg/fields:go_default_library",
"//pkg/runtime:go_default_library",
"//pkg/util/net:go_default_library",
"//pkg/util/sets:go_default_library",
"//pkg/util/wait:go_default_library",
"//pkg/version:go_default_library",
"//pkg/watch:go_default_library",
"//plugin/pkg/client/auth:go_default_library",
"//vendor:github.com/google/cadvisor/info/v1",
],
)

go_test(
name = "go_default_test",
srcs = [
"containerinfo_test.go",
"flags_test.go",
"helper_test.go",
],
srcs = ["helper_test.go"],
library = "go_default_library",
tags = ["automanaged"],
deps = [
Expand All @@ -131,58 +48,5 @@ go_test(
"//pkg/apimachinery/registered:go_default_library",
"//pkg/client/restclient:go_default_library",
"//pkg/runtime:go_default_library",
"//pkg/util/sets:go_default_library",
"//vendor:github.com/google/cadvisor/info/v1",
"//vendor:github.com/google/cadvisor/info/v1/test",
],
)

go_test(
name = "go_default_xtest",
srcs = [
"daemon_sets_test.go",
"deployment_test.go",
"endpoints_test.go",
"events_test.go",
"helper_blackbox_test.go",
"horizontalpodautoscaler_test.go",
"ingress_test.go",
"jobs_test.go",
"limit_ranges_test.go",
"namespaces_test.go",
"nodes_test.go",
"persistentvolume_test.go",
"persistentvolumeclaim_test.go",
"pet_sets_test.go",
"pod_templates_test.go",
"pods_test.go",
"podsecuritypolicy_test.go",
"replica_sets_test.go",
"replication_controllers_test.go",
"resource_quotas_test.go",
"scheduledjobs_test.go",
"services_test.go",
"storageclasses_test.go",
"thirdpartyresources_test.go",
],
tags = ["automanaged"],
deps = [
"//pkg/api:go_default_library",
"//pkg/api/resource:go_default_library",
"//pkg/api/testapi:go_default_library",
"//pkg/api/unversioned:go_default_library",
"//pkg/apimachinery/registered:go_default_library",
"//pkg/apis/apps:go_default_library",
"//pkg/apis/autoscaling:go_default_library",
"//pkg/apis/batch:go_default_library",
"//pkg/apis/batch/v2alpha1:go_default_library",
"//pkg/apis/extensions:go_default_library",
"//pkg/apis/storage:go_default_library",
"//pkg/client/restclient:go_default_library",
"//pkg/client/unversioned:go_default_library",
"//pkg/client/unversioned/fake:go_default_library",
"//pkg/client/unversioned/testclient/simple:go_default_library",
"//pkg/labels:go_default_library",
"//pkg/runtime:go_default_library",
],
)
Loading

0 comments on commit 5423eaf

Please sign in to comment.