Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rancher/client-go
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.29.3-rancher1
Choose a base ref
...
head repository: rancher/client-go
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.0.0
Choose a head ref
  • 16 commits
  • 399 files changed
  • 6 contributors

Commits on Dec 14, 2016

  1. published by bot

    (https://github.com/kubernetes/contrib/tree/master/mungegithub)
    
    copied from https://github.com/kubernetes/kubernetes.git, branch master,
    last commit is 66a7a1f961489b81e0357a6307270d50b00c5f50
    k8s-publish-robot authored and Chao Xu committed Dec 14, 2016
    Copy the full SHA
    280a11d View commit details
  2. published by bot

    (https://github.com/kubernetes/contrib/tree/master/mungegithub)
    
    copied from https://github.com/kubernetes/kubernetes.git, branch master,
    last commit is d1d8e428b14907b2cf67ba78cce2dae4c2fdf15b
    k8s-publish-robot authored and Chao Xu committed Dec 14, 2016

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a7e2e09 View commit details
  3. published by bot

    (https://github.com/kubernetes/contrib/tree/master/mungegithub)
    
    copied from https://github.com/kubernetes/kubernetes.git, branch master,
    last commit is 8558768650b1da489aa63050bc03f1d42912c968
    k8s-publish-robot authored and Chao Xu committed Dec 14, 2016

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f672dd6 View commit details
  4. published by bot

    (https://github.com/kubernetes/contrib/tree/master/mungegithub)
    
    copied from https://github.com/kubernetes/kubernetes.git, branch master,
    last commit is 1bc5b822cd566321c115d4ebac5d97cfd347d687
    k8s-publish-robot authored and Chao Xu committed Dec 14, 2016

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    93f59dc View commit details
  5. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4cfa344 View commit details
  6. Add README

    wfarr authored and Chao Xu committed Dec 14, 2016

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2a26fff View commit details
  7. published by bot

    (https://github.com/kubernetes/contrib/tree/master/mungegithub)
    
    copied from https://github.com/kubernetes/kubernetes.git, branch master,
    last commit is 800ef09dc19c04789c49c2e83e963bbd986cda7a
    k8s-publish-robot authored and Chao Xu committed Dec 14, 2016

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    47044f1 View commit details
  8. Make out-of-cluster example buildable

    dtan4 authored and Chao Xu committed Dec 14, 2016

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0d05577 View commit details
  9. Make in-cluster example buildable

    dtan4 authored and Chao Xu committed Dec 14, 2016

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1fa1950 View commit details
  10. Make third-party example buildable

    dtan4 authored and Chao Xu committed Dec 14, 2016

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f53b36f View commit details

Commits on Dec 20, 2016

  1. Merge pull request kubernetes#54 from caesarxuchao/release-2.0

    Cherry-pick fixes to release 2.0
    caesarxuchao authored Dec 20, 2016
    Copy the full SHA
    d81cb85 View commit details

Commits on Feb 1, 2017

  1. published by bot

    (https://github.com/kubernetes/test-infra/tree/master/mungegithub)
    
    copied from https://github.com/kubernetes/kubernetes.git, branch release-1.5,
    last commit is 92a03028433cdef51eb36a484c555e4c8900f727
    k8s-publish-robot committed Feb 1, 2017
    Copy the full SHA
    724650e View commit details

Commits on Feb 11, 2017

  1. add travis

    Chao Xu committed Feb 11, 2017
    Copy the full SHA
    582881b View commit details
  2. Copy the full SHA
    0814629 View commit details

Commits on Feb 13, 2017

  1. manually update release-2.0, tracking k8s.io/kubernetes release 1.5, …

    …last commit is bde8578d9675129b7a2aa08f1b825ec6cc0f3420
    Chao Xu committed Feb 13, 2017
    Copy the full SHA
    3ac7cf0 View commit details
  2. Merge pull request kubernetes#102 from caesarxuchao/fix-release-2.0

    manually update release-2.0
    lavalamp authored Feb 13, 2017
    Copy the full SHA
    e121606 View commit details
Showing 399 changed files with 61,976 additions and 55,055 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: go

go_import_path: k8s.io/client-go

go:
- 1.7.4

script: go build ./...
23 changes: 16 additions & 7 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 42 additions & 16 deletions discovery/discovery_client.go
Original file line number Diff line number Diff line change
@@ -45,6 +45,15 @@ type DiscoveryInterface interface {
SwaggerSchemaInterface
}

// CachedDiscoveryInterface is a DiscoveryInterface with cache invalidation and freshness.
type CachedDiscoveryInterface interface {
DiscoveryInterface
// Fresh returns true if no cached data was used that had been retrieved before the instantiation.
Fresh() bool
// Invalidate enforces that no cached data is used in the future that is older than the current time.
Invalidate()
}

// ServerGroupsInterface has methods for obtaining supported groups on the API server
type ServerGroupsInterface interface {
// ServerGroups returns the supported groups, with information like supported versions and the
@@ -204,35 +213,52 @@ func (d *DiscoveryClient) serverPreferredResources(namespaced bool) ([]unversion
const maxRetries = 2
var failedGroups map[unversioned.GroupVersion]error
var results []unversioned.GroupVersionResource
var resources map[unversioned.GroupResource]string
RetrieveGroups:
for i := 0; i < maxRetries; i++ {
results = []unversioned.GroupVersionResource{}
resources = map[unversioned.GroupResource]string{}
failedGroups = make(map[unversioned.GroupVersion]error)
serverGroupList, err := d.ServerGroups()
if err != nil {
return results, err
}

for _, apiGroup := range serverGroupList.Groups {
preferredVersion := apiGroup.PreferredVersion
groupVersion := unversioned.GroupVersion{Group: apiGroup.Name, Version: preferredVersion.Version}
apiResourceList, err := d.ServerResourcesForGroupVersion(preferredVersion.GroupVersion)
if err != nil {
if i < maxRetries-1 {
continue RetrieveGroups
}
failedGroups[groupVersion] = err
continue
}
for _, apiResource := range apiResourceList.APIResources {
// ignore the root scoped resources if "namespaced" is true.
if namespaced && !apiResource.Namespaced {
versions := apiGroup.Versions
for _, version := range versions {
groupVersion := unversioned.GroupVersion{Group: apiGroup.Name, Version: version.Version}
apiResourceList, err := d.ServerResourcesForGroupVersion(version.GroupVersion)
if err != nil {
if i < maxRetries-1 {
continue RetrieveGroups
}
failedGroups[groupVersion] = err
continue
}
if strings.Contains(apiResource.Name, "/") {
continue
for _, apiResource := range apiResourceList.APIResources {
// ignore the root scoped resources if "namespaced" is true.
if namespaced && !apiResource.Namespaced {
continue
}
if strings.Contains(apiResource.Name, "/") {
continue
}
gvr := groupVersion.WithResource(apiResource.Name)
if _, ok := resources[gvr.GroupResource()]; ok {
if gvr.Version != apiGroup.PreferredVersion.Version {
continue
}
// remove previous entry, because it will be replaced with a preferred one
for i := range results {
if results[i].GroupResource() == gvr.GroupResource() {
results = append(results[:i], results[i+1:]...)
}
}
}
resources[gvr.GroupResource()] = gvr.Version
results = append(results, gvr)
}
results = append(results, groupVersion.WithResource(apiResource.Name))
}
}
if len(failedGroups) == 0 {
185 changes: 172 additions & 13 deletions discovery/discovery_client_test.go
Original file line number Diff line number Diff line change
@@ -321,7 +321,7 @@ func TestGetSwaggerSchemaFail(t *testing.T) {
}
}

func TestGetServerPreferredResources(t *testing.T) {
func TestServerPreferredResources(t *testing.T) {
stable := unversioned.APIResourceList{
GroupVersion: "v1",
APIResources: []unversioned.APIResource{
@@ -330,14 +330,6 @@ func TestGetServerPreferredResources(t *testing.T) {
{Name: "namespaces", Namespaced: false, Kind: "Namespace"},
},
}
/*beta := unversioned.APIResourceList{
GroupVersion: "extensions/v1",
APIResources: []unversioned.APIResource{
{Name: "deployments", Namespaced: true, Kind: "Deployment"},
{Name: "ingresses", Namespaced: true, Kind: "Ingress"},
{Name: "jobs", Namespaced: true, Kind: "Job"},
},
}*/
tests := []struct {
resourcesList *unversioned.APIResourceList
response func(w http.ResponseWriter, req *http.Request)
@@ -427,9 +419,6 @@ func TestGetServerPreferredResources(t *testing.T) {
w.Write(output)
},
},
/*{
resourcesList: &stable,
},*/
}
for _, test := range tests {
server := httptest.NewServer(http.HandlerFunc(test.response))
@@ -455,7 +444,7 @@ func TestGetServerPreferredResources(t *testing.T) {
}
}

func TestGetServerPreferredResourcesRetries(t *testing.T) {
func TestServerPreferredResourcesRetries(t *testing.T) {
stable := unversioned.APIResourceList{
GroupVersion: "v1",
APIResources: []unversioned.APIResource{
@@ -553,3 +542,173 @@ func TestGetServerPreferredResourcesRetries(t *testing.T) {
server.Close()
}
}

func TestServerPreferredNamespacedResources(t *testing.T) {
stable := unversioned.APIResourceList{
GroupVersion: "v1",
APIResources: []unversioned.APIResource{
{Name: "pods", Namespaced: true, Kind: "Pod"},
{Name: "services", Namespaced: true, Kind: "Service"},
{Name: "namespaces", Namespaced: false, Kind: "Namespace"},
},
}
batchv1 := unversioned.APIResourceList{
GroupVersion: "batch/v1",
APIResources: []unversioned.APIResource{
{Name: "jobs", Namespaced: true, Kind: "Job"},
},
}
batchv2alpha1 := unversioned.APIResourceList{
GroupVersion: "batch/v2alpha1",
APIResources: []unversioned.APIResource{
{Name: "jobs", Namespaced: true, Kind: "Job"},
{Name: "cronjobs", Namespaced: true, Kind: "CronJob"},
},
}
batchv3alpha1 := unversioned.APIResourceList{
GroupVersion: "batch/v3alpha1",
APIResources: []unversioned.APIResource{
{Name: "jobs", Namespaced: true, Kind: "Job"},
{Name: "cronjobs", Namespaced: true, Kind: "CronJob"},
},
}
tests := []struct {
response func(w http.ResponseWriter, req *http.Request)
expected []unversioned.GroupVersionResource
}{
{
response: func(w http.ResponseWriter, req *http.Request) {
var list interface{}
switch req.URL.Path {
case "/api/v1":
list = &stable
case "/api":
list = &unversioned.APIVersions{
Versions: []string{
"v1",
},
}
default:
t.Logf("unexpected request: %s", req.URL.Path)
w.WriteHeader(http.StatusNotFound)
return
}
output, err := json.Marshal(list)
if err != nil {
t.Errorf("unexpected encoding error: %v", err)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(output)
},
expected: []unversioned.GroupVersionResource{
{Group: "", Version: "v1", Resource: "pods"},
{Group: "", Version: "v1", Resource: "services"},
},
},
{
response: func(w http.ResponseWriter, req *http.Request) {
var list interface{}
switch req.URL.Path {
case "/apis":
list = &unversioned.APIGroupList{
Groups: []unversioned.APIGroup{
{
Name: "batch",
Versions: []unversioned.GroupVersionForDiscovery{
{GroupVersion: "batch/v1", Version: "v1"},
{GroupVersion: "batch/v2alpha1", Version: "v2alpha1"},
{GroupVersion: "batch/v3alpha1", Version: "v3alpha1"},
},
PreferredVersion: unversioned.GroupVersionForDiscovery{GroupVersion: "batch/v1", Version: "v1"},
},
},
}
case "/apis/batch/v1":
list = &batchv1
case "/apis/batch/v2alpha1":
list = &batchv2alpha1
case "/apis/batch/v3alpha1":
list = &batchv3alpha1
default:
t.Logf("unexpected request: %s", req.URL.Path)
w.WriteHeader(http.StatusNotFound)
return
}
output, err := json.Marshal(list)
if err != nil {
t.Errorf("unexpected encoding error: %v", err)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(output)
},
expected: []unversioned.GroupVersionResource{
{Group: "batch", Version: "v1", Resource: "jobs"},
{Group: "batch", Version: "v2alpha1", Resource: "cronjobs"},
},
},
{
response: func(w http.ResponseWriter, req *http.Request) {
var list interface{}
switch req.URL.Path {
case "/apis":
list = &unversioned.APIGroupList{
Groups: []unversioned.APIGroup{
{
Name: "batch",
Versions: []unversioned.GroupVersionForDiscovery{
{GroupVersion: "batch/v1", Version: "v1"},
{GroupVersion: "batch/v2alpha1", Version: "v2alpha1"},
{GroupVersion: "batch/v3alpha1", Version: "v3alpha1"},
},
PreferredVersion: unversioned.GroupVersionForDiscovery{GroupVersion: "batch/v2alpha", Version: "v2alpha1"},
},
},
}
case "/apis/batch/v1":
list = &batchv1
case "/apis/batch/v2alpha1":
list = &batchv2alpha1
case "/apis/batch/v3alpha1":
list = &batchv3alpha1
default:
t.Logf("unexpected request: %s", req.URL.Path)
w.WriteHeader(http.StatusNotFound)
return
}
output, err := json.Marshal(list)
if err != nil {
t.Errorf("unexpected encoding error: %v", err)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(output)
},
expected: []unversioned.GroupVersionResource{
{Group: "batch", Version: "v2alpha1", Resource: "jobs"},
{Group: "batch", Version: "v2alpha1", Resource: "cronjobs"},
},
},
}
for _, test := range tests {
server := httptest.NewServer(http.HandlerFunc(test.response))
defer server.Close()

client := NewDiscoveryClientForConfigOrDie(&rest.Config{Host: server.URL})
got, err := client.ServerPreferredNamespacedResources()
if err != nil {
t.Errorf("unexpected error: %v", err)
continue
}
// we need deterministic order and since during processing in ServerPreferredNamespacedResources
// a map comes into play the result needs sorting
if !reflect.DeepEqual(got, test.expected) {
t.Errorf("expected:\n%v\ngot:\n%v\n", test.expected, got)
}
server.Close()
}
}
Loading