From abeabeb7a6121c350a8d5741bfdabbe7b9b0a5ef Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Tue, 31 Jan 2017 09:11:53 +0100 Subject: [PATCH] client-go: fix examples --- .../client-go/examples/in-cluster/main.go | 4 +- .../client-go/examples/out-of-cluster/main.go | 4 +- .../examples/third-party-resources/main.go | 38 +++++++++++++------ .../examples/third-party-resources/types.go | 26 ++++++++++--- 4 files changed, 50 insertions(+), 22 deletions(-) diff --git a/staging/src/k8s.io/client-go/examples/in-cluster/main.go b/staging/src/k8s.io/client-go/examples/in-cluster/main.go index 04b0798e40a84..b6ffc34fa63b0 100644 --- a/staging/src/k8s.io/client-go/examples/in-cluster/main.go +++ b/staging/src/k8s.io/client-go/examples/in-cluster/main.go @@ -20,8 +20,8 @@ import ( "fmt" "time" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" - "k8s.io/client-go/pkg/api/v1" "k8s.io/client-go/rest" ) @@ -37,7 +37,7 @@ func main() { panic(err.Error()) } for { - pods, err := clientset.Core().Pods("").List(v1.ListOptions{}) + pods, err := clientset.CoreV1().Pods("").List(metav1.ListOptions{}) if err != nil { panic(err.Error()) } diff --git a/staging/src/k8s.io/client-go/examples/out-of-cluster/main.go b/staging/src/k8s.io/client-go/examples/out-of-cluster/main.go index 7919d9278e197..a8a4fb50a6193 100644 --- a/staging/src/k8s.io/client-go/examples/out-of-cluster/main.go +++ b/staging/src/k8s.io/client-go/examples/out-of-cluster/main.go @@ -21,8 +21,8 @@ import ( "fmt" "time" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" - "k8s.io/client-go/pkg/api/v1" "k8s.io/client-go/tools/clientcmd" ) @@ -43,7 +43,7 @@ func main() { panic(err.Error()) } for { - pods, err := clientset.Core().Pods("").List(v1.ListOptions{}) + pods, err := clientset.CoreV1().Pods("").List(metav1.ListOptions{}) if err != nil { panic(err.Error()) } diff --git a/staging/src/k8s.io/client-go/examples/third-party-resources/main.go b/staging/src/k8s.io/client-go/examples/third-party-resources/main.go index 6222dd68f954c..5218a80a9b97f 100644 --- a/staging/src/k8s.io/client-go/examples/third-party-resources/main.go +++ b/staging/src/k8s.io/client-go/examples/third-party-resources/main.go @@ -1,18 +1,33 @@ +/* +Copyright 2017 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 main import ( "flag" "fmt" + "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/runtime/serializer" "k8s.io/client-go/kubernetes" "k8s.io/client-go/pkg/api" - "k8s.io/client-go/pkg/api/errors" - "k8s.io/client-go/pkg/api/v1" "k8s.io/client-go/pkg/apis/extensions/v1beta1" - metav1 "k8s.io/client-go/pkg/apis/meta/v1" - "k8s.io/client-go/pkg/runtime" - "k8s.io/client-go/pkg/runtime/schema" - "k8s.io/client-go/pkg/runtime/serializer" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" @@ -40,11 +55,11 @@ func main() { } // initialize third party resource if it does not exist - tpr, err := clientset.Extensions().ThirdPartyResources().Get("example.k8s.io", metav1.GetOptions{}) + tpr, err := clientset.ExtensionsV1beta1().ThirdPartyResources().Get("example.k8s.io", metav1.GetOptions{}) if err != nil { if errors.IsNotFound(err) { tpr := &v1beta1.ThirdPartyResource{ - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "example.k8s.io", }, Versions: []v1beta1.APIVersion{ @@ -53,7 +68,7 @@ func main() { Description: "An Example ThirdPartyResource", } - result, err := clientset.Extensions().ThirdPartyResources().Create(tpr) + result, err := clientset.ExtensionsV1beta1().ThirdPartyResources().Create(tpr) if err != nil { panic(err) } @@ -87,7 +102,7 @@ func main() { if errors.IsNotFound(err) { // Create an instance of our TPR example := &Example{ - Metadata: api.ObjectMeta{ + Metadata: metav1.ObjectMeta{ Name: "example1", }, Spec: ExampleSpec{ @@ -147,10 +162,9 @@ func configureClient(config *rest.Config) { groupversion, &Example{}, &ExampleList{}, - &api.ListOptions{}, - &api.DeleteOptions{}, ) return nil }) + metav1.AddToGroupVersion(api.Scheme, groupversion) schemeBuilder.AddToScheme(api.Scheme) } diff --git a/staging/src/k8s.io/client-go/examples/third-party-resources/types.go b/staging/src/k8s.io/client-go/examples/third-party-resources/types.go index f4e75b677ca1d..345d5a3ab29fe 100644 --- a/staging/src/k8s.io/client-go/examples/third-party-resources/types.go +++ b/staging/src/k8s.io/client-go/examples/third-party-resources/types.go @@ -1,12 +1,26 @@ +/* +Copyright 2017 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 main import ( "encoding/json" - "k8s.io/client-go/pkg/api" - "k8s.io/client-go/pkg/api/meta" - metav1 "k8s.io/client-go/pkg/apis/meta/v1" - "k8s.io/client-go/pkg/runtime/schema" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" ) type ExampleSpec struct { @@ -16,7 +30,7 @@ type ExampleSpec struct { type Example struct { metav1.TypeMeta `json:",inline"` - Metadata api.ObjectMeta `json:"metadata"` + Metadata metav1.ObjectMeta `json:"metadata"` Spec ExampleSpec `json:"spec"` } @@ -34,7 +48,7 @@ func (e *Example) GetObjectKind() schema.ObjectKind { } // Required to satisfy ObjectMetaAccessor interface -func (e *Example) GetObjectMeta() meta.Object { +func (e *Example) GetObjectMeta() metav1.Object { return &e.Metadata }