Skip to content

Commit

Permalink
client-go: fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sttts committed Feb 2, 2017
1 parent 7aebe7c commit abeabeb
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 22 deletions.
4 changes: 2 additions & 2 deletions staging/src/k8s.io/client-go/examples/in-cluster/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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())
}
Expand Down
4 changes: 2 additions & 2 deletions staging/src/k8s.io/client-go/examples/out-of-cluster/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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())
}
Expand Down
38 changes: 26 additions & 12 deletions staging/src/k8s.io/client-go/examples/third-party-resources/main.go
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -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{
Expand All @@ -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)
}
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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"`
}
Expand All @@ -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
}

Expand Down

0 comments on commit abeabeb

Please sign in to comment.