From e1539af9b938fb752f267d569dad5c6f578ffed9 Mon Sep 17 00:00:00 2001 From: Jinghua ZHU Date: Tue, 12 Dec 2017 18:11:00 +0800 Subject: [PATCH 1/6] Init --- apis/cr/v1/doc.go | 2 + apis/cr/v1/register.go | 49 ++++++ apis/cr/v1/roundtrip_test.go | 66 ++++++++ apis/cr/v1/types.go | 39 +++++ {apis => bk/apis}/test0.io/v1/crd.go | 0 {apis => bk/apis}/test0.io/v1/doc.go | 0 {apis => bk/apis}/test0.io/v1/types.go | 0 .../test0.io/v1/zz_generated.deepcopy.go | 0 .../test0.io/v1/zz_generated.deepcopy.go.bk | 0 bk/client/client.go | 51 ++++++ bk/controller/controller.go | 92 +++++++++++ {controller => bk/controller}/types.go | 0 bk/main.go | 96 +++++++++++ bk/pkg/apis/testio/v1/doc.go | 5 - bk/pkg/apis/testio/v1/types.go | 53 ------ .../apis/testio/v1/zz_generated.deepcopy.go | 151 ------------------ .../client/clientset/versioned/clientset.go | 98 ------------ bk/pkg/client/clientset/versioned/doc.go | 20 --- .../versioned/fake/clientset_generated.go | 71 -------- bk/pkg/client/clientset/versioned/fake/doc.go | 20 --- .../clientset/versioned/fake/register.go | 53 ------ .../client/clientset/versioned/scheme/doc.go | 20 --- .../clientset/versioned/scheme/register.go | 53 ------ .../versioned/typed/testio/v1/doc.go | 20 --- .../versioned/typed/testio/v1/fake/doc.go | 20 --- .../testio/v1/fake/fake_testio_client.go | 21 --- .../typed/testio/v1/generated_expansion.go | 17 -- .../typed/testio/v1/testio_client.go | 21 --- client/client.go | 46 +++--- client/cr.go | 103 ++++++++++++ controller/controller.go | 114 ++++++++----- main.go | 99 +++++++----- 32 files changed, 647 insertions(+), 753 deletions(-) create mode 100644 apis/cr/v1/doc.go create mode 100644 apis/cr/v1/register.go create mode 100644 apis/cr/v1/roundtrip_test.go create mode 100644 apis/cr/v1/types.go rename {apis => bk/apis}/test0.io/v1/crd.go (100%) rename {apis => bk/apis}/test0.io/v1/doc.go (100%) rename {apis => bk/apis}/test0.io/v1/types.go (100%) rename {apis => bk/apis}/test0.io/v1/zz_generated.deepcopy.go (100%) rename {apis => bk/apis}/test0.io/v1/zz_generated.deepcopy.go.bk (100%) create mode 100644 bk/client/client.go create mode 100644 bk/controller/controller.go rename {controller => bk/controller}/types.go (100%) create mode 100644 bk/main.go delete mode 100644 bk/pkg/apis/testio/v1/doc.go delete mode 100644 bk/pkg/apis/testio/v1/types.go delete mode 100644 bk/pkg/apis/testio/v1/zz_generated.deepcopy.go delete mode 100644 bk/pkg/client/clientset/versioned/clientset.go delete mode 100644 bk/pkg/client/clientset/versioned/doc.go delete mode 100644 bk/pkg/client/clientset/versioned/fake/clientset_generated.go delete mode 100644 bk/pkg/client/clientset/versioned/fake/doc.go delete mode 100644 bk/pkg/client/clientset/versioned/fake/register.go delete mode 100644 bk/pkg/client/clientset/versioned/scheme/doc.go delete mode 100644 bk/pkg/client/clientset/versioned/scheme/register.go delete mode 100644 bk/pkg/client/clientset/versioned/typed/testio/v1/doc.go delete mode 100644 bk/pkg/client/clientset/versioned/typed/testio/v1/fake/doc.go delete mode 100644 bk/pkg/client/clientset/versioned/typed/testio/v1/fake/fake_testio_client.go delete mode 100644 bk/pkg/client/clientset/versioned/typed/testio/v1/generated_expansion.go delete mode 100644 bk/pkg/client/clientset/versioned/typed/testio/v1/testio_client.go create mode 100644 client/cr.go diff --git a/apis/cr/v1/doc.go b/apis/cr/v1/doc.go new file mode 100644 index 0000000..6320349 --- /dev/null +++ b/apis/cr/v1/doc.go @@ -0,0 +1,2 @@ +// +k8s:deepcopy-gen=package +package v1 diff --git a/apis/cr/v1/register.go b/apis/cr/v1/register.go new file mode 100644 index 0000000..1ee348e --- /dev/null +++ b/apis/cr/v1/register.go @@ -0,0 +1,49 @@ +/* +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 v1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +var ( + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + AddToScheme = SchemeBuilder.AddToScheme +) + +// GroupName is the group name used in this package. +const GroupName = "cr.client-go.k8s.io" + +// SchemeGroupVersion is the group version used to register these objects. +var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"} + +// Resource takes an unqualified resource and returns a Group-qualified GroupResource. +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +// addKnownTypes adds the set of types defined in this package to the supplied scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &Example{}, + &ExampleList{}, + ) + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/apis/cr/v1/roundtrip_test.go b/apis/cr/v1/roundtrip_test.go new file mode 100644 index 0000000..7373c78 --- /dev/null +++ b/apis/cr/v1/roundtrip_test.go @@ -0,0 +1,66 @@ +/* +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 v1 + +import ( + "math/rand" + "testing" + + "github.com/google/gofuzz" + + "k8s.io/apimachinery/pkg/api/testing/fuzzer" + roundtrip "k8s.io/apimachinery/pkg/api/testing/roundtrip" + metafuzzer "k8s.io/apimachinery/pkg/apis/meta/fuzzer" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/serializer" + runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer" +) + +var _ runtime.Object = &Example{} +var _ metav1.ObjectMetaAccessor = &Example{} + +var _ runtime.Object = &ExampleList{} +var _ metav1.ListMetaAccessor = &ExampleList{} + +func exampleFuzzerFuncs(codecs runtimeserializer.CodecFactory) []interface{} { + return []interface{}{ + func(obj *ExampleList, c fuzz.Continue) { + c.FuzzNoCustom(obj) + obj.Items = make([]Example, c.Intn(10)) + for i := range obj.Items { + c.Fuzz(&obj.Items[i]) + } + }, + } +} + +// TestRoundTrip tests that the third-party kinds can be marshaled and unmarshaled correctly to/from JSON +// without the loss of information. Moreover, deep copy is tested. +func TestRoundTrip(t *testing.T) { + scheme := runtime.NewScheme() + codecs := serializer.NewCodecFactory(scheme) + + AddToScheme(scheme) + + seed := rand.Int63() + fuzzerFuncs := fuzzer.MergeFuzzerFuncs(metafuzzer.Funcs, exampleFuzzerFuncs) + fuzzer := fuzzer.FuzzerFor(fuzzerFuncs, rand.NewSource(seed), codecs) + + roundtrip.RoundTripSpecificKindWithoutProtobuf(t, SchemeGroupVersion.WithKind("Example"), scheme, codecs, fuzzer, nil) + roundtrip.RoundTripSpecificKindWithoutProtobuf(t, SchemeGroupVersion.WithKind("ExampleList"), scheme, codecs, fuzzer, nil) +} diff --git a/apis/cr/v1/types.go b/apis/cr/v1/types.go new file mode 100644 index 0000000..cde811c --- /dev/null +++ b/apis/cr/v1/types.go @@ -0,0 +1,39 @@ +package v1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +const ExampleResourcePlural = "examples" + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +type Example struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata"` + Spec ExampleSpec `json:"spec"` + Status ExampleStatus `json:"status,omitempty"` +} + +type ExampleSpec struct { + Foo string `json:"foo"` + Bar bool `json:"bar"` +} + +type ExampleStatus struct { + State ExampleState `json:"state,omitempty"` + Message string `json:"message,omitempty"` +} + +type ExampleState string + +const ( + ExampleStateCreated ExampleState = "Created" + ExampleStateProcessed ExampleState = "Processed" +) + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +type ExampleList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + Items []Example `json:"items"` +} diff --git a/apis/test0.io/v1/crd.go b/bk/apis/test0.io/v1/crd.go similarity index 100% rename from apis/test0.io/v1/crd.go rename to bk/apis/test0.io/v1/crd.go diff --git a/apis/test0.io/v1/doc.go b/bk/apis/test0.io/v1/doc.go similarity index 100% rename from apis/test0.io/v1/doc.go rename to bk/apis/test0.io/v1/doc.go diff --git a/apis/test0.io/v1/types.go b/bk/apis/test0.io/v1/types.go similarity index 100% rename from apis/test0.io/v1/types.go rename to bk/apis/test0.io/v1/types.go diff --git a/apis/test0.io/v1/zz_generated.deepcopy.go b/bk/apis/test0.io/v1/zz_generated.deepcopy.go similarity index 100% rename from apis/test0.io/v1/zz_generated.deepcopy.go rename to bk/apis/test0.io/v1/zz_generated.deepcopy.go diff --git a/apis/test0.io/v1/zz_generated.deepcopy.go.bk b/bk/apis/test0.io/v1/zz_generated.deepcopy.go.bk similarity index 100% rename from apis/test0.io/v1/zz_generated.deepcopy.go.bk rename to bk/apis/test0.io/v1/zz_generated.deepcopy.go.bk diff --git a/bk/client/client.go b/bk/client/client.go new file mode 100644 index 0000000..d658830 --- /dev/null +++ b/bk/client/client.go @@ -0,0 +1,51 @@ +package client + +import ( + "time" + + "github.com/jinghzhu/GoUtils/logger" + crd "github.com/jinghzhu/k8scrd/apis/test0.io/v1" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/serializer" + "k8s.io/apimachinery/pkg/util/wait" + "k8s.io/client-go/rest" +) + +func NewClient(cfg *rest.Config) (*rest.RESTClient, *runtime.Scheme, error) { + scheme := runtime.NewScheme() + if err := crd.AddToScheme(scheme); err != nil { + return nil, nil, err + } + + config := *cfg + config.GroupVersion = &crd.SchemeGroupVersion + config.APIPath = "/apis" + config.ContentType = runtime.ContentTypeJSON + config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: serializer.NewCodecFactory(scheme)} + + client, err := rest.RESTClientFor(&config) + if err != nil { + logger.Error("Fail to generate REST client: " + err.Error()) + return nil, nil, err + } + + return client, scheme, nil +} + +func WaitForInstanceProcessed(testClient *rest.RESTClient, name string) error { + return wait.Poll(100*time.Millisecond, 10*time.Second, func() (bool, error) { + var instance crd.Test + err := testClient.Get(). + Resource(crd.TestResourcePlural). + Namespace(corev1.NamespaceDefault). + Name(name). + Do().Into(&instance) + + if err == nil && instance.Status.State == crd.StateProcessed { + return true, nil + } + + return false, err + }) +} diff --git a/bk/controller/controller.go b/bk/controller/controller.go new file mode 100644 index 0000000..2e58ffc --- /dev/null +++ b/bk/controller/controller.go @@ -0,0 +1,92 @@ +package controller + +import ( + "context" + "fmt" + + logger "github.com/jinghzhu/GoUtils/logger" + crd "github.com/jinghzhu/k8scrd/apis/test0.io/v1" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/fields" + "k8s.io/client-go/tools/cache" +) + +// Run starts a CRD resource controller. +func (c *TestController) Run(ctx context.Context) error { + logger.Info("Watch CRD objects") + + // Watch CRD objects + _, err := c.watch(ctx) + if err != nil { + fmt.Printf("Failed to register watch for Example resource: %v\n", err) + return err + } + + // <-ctx.Done() + return ctx.Err() +} + +func (c *TestController) watch(ctx context.Context) (cache.Controller, error) { + source := cache.NewListWatchFromClient( + c.TestClient, + crd.TestResourcePlural, + corev1.NamespaceAll, + fields.Everything(), + ) + + _, controller := cache.NewInformer( + source, + &crd.Test{}, + // Every resyncPeriod, all resources in the cache will retrigger events. + // Set to 0 to disable the resync. + 0, + // CRD event handlers. + cache.ResourceEventHandlerFuncs{ + AddFunc: c.onAdd, + UpdateFunc: c.onUpdate, + DeleteFunc: c.onDelete, + }, + ) + + // go controller.Run(ctx.Done() + return controller, nil +} + +func (c *TestController) onAdd(obj interface{}) { + test := obj.(*crd.Test) + logger.Info("[CONTROLLER] OnAdd " + test.ObjectMeta.SelfLink) + + // Use DeepCopy() to make a deep copy of original object and modify this copy + // or create a copy manually for better performance. + testCopy := test.DeepCopy() + testCopy.Status = crd.TestStatus{ + State: crd.StateProcessed, + Message: "Successfully processed by controller", + } + + err := c.TestClient.Put(). + Name(test.ObjectMeta.Name). + Namespace(test.ObjectMeta.Namespace). + Resource(crd.TestResourcePlural). + Body(testCopy). + Do(). + Error() + + if err != nil { + logger.Error("ERROR updating status: " + err.Error()) + } else { + logger.Info("UPDATED status: " + testCopy.SelfLink) + } +} + +func (c *TestController) onUpdate(oldObj, newObj interface{}) { + old := oldObj.(*crd.Test) + new := newObj.(*crd.Test) + logger.Info("[CONTROLLER] OnUpdate old: " + old.ObjectMeta.SelfLink) + logger.Info("[CONTROLLER] OnUpdate new: " + new.ObjectMeta.SelfLink) +} + +func (c *TestController) onDelete(obj interface{}) { + test := obj.(*crd.Test) + logger.Info("[CONTROLLER] OnDelete " + test.ObjectMeta.SelfLink) +} diff --git a/controller/types.go b/bk/controller/types.go similarity index 100% rename from controller/types.go rename to bk/controller/types.go diff --git a/bk/main.go b/bk/main.go new file mode 100644 index 0000000..d711d8f --- /dev/null +++ b/bk/main.go @@ -0,0 +1,96 @@ +package main + +import ( + "context" + "fmt" + "os" + + logger "github.com/jinghzhu/GoUtils/logger" + test0v1 "github.com/jinghzhu/k8scrd/apis/test0.io/v1" + "github.com/jinghzhu/k8scrd/client" + "github.com/jinghzhu/k8scrd/controller" + corev1 "k8s.io/api/core/v1" + apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" + apierrors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/tools/clientcmd" +) + +func main() { + kubeconfig := os.Getenv("KUBECONFIG") + + // Use kubeconfig to create client config. + clientConfig, err := clientcmd.BuildConfigFromFlags("", kubeconfig) + if err != nil { + panic(err) + } + + apiextensionsClientSet, err := apiextensionsclient.NewForConfig(clientConfig) + if err != nil { + panic(err) + } + + // Init a CRD. + _, err = test0v1.CreateCustomResourceDefinition(apiextensionsClientSet) + if err != nil && !apierrors.IsAlreadyExists(err) { + panic(err) + } + + // Make a new config for extension's API group and use the first one as the baseline. + testClient, testScheme, err := client.NewClient(clientConfig) + if err != nil { + panic(err) + } + + // Start CRD controller. + controller := controller.TestController{ + TestClient: testClient, + TestScheme: testScheme, + } + ctx := context.Background() + go controller.Run(ctx) + + // Create an instance of CRD. + instanceName := "test1" + testInstance := test0v1.Test{ + ObjectMeta: metav1.ObjectMeta{ + Name: instanceName, + }, + Spec: test0v1.TestSpec{ + Foo: "hello", + Bar: true, + }, + Status: test0v1.TestStatus{ + State: test0v1.StateCreated, + Message: "Created but not processed yet", + }, + } + var result test0v1.Test + err = testClient.Post(). + Resource(test0v1.TestResourcePlural). + Namespace(corev1.NamespaceDefault). + Body(testInstance). + Do().Into(&result) + if err == nil { + logger.Info(fmt.Sprintf("CREATED: %#v", result)) + } else if apierrors.IsAlreadyExists(err) { + logger.Info(fmt.Sprintf("ALREADY EXISTS: %#v", result)) + } else { + panic(err) + } + + // Wait until the CRD object is handled by controller and its status is changed to Processed. + err = client.WaitForInstanceProcessed(testClient, instanceName) + if err != nil { + panic(err) + } + logger.Info("Porcessed") + + // Get the list of CRs. + testList := test0v1.TestList{} + err = testClient.Get().Resource(test0v1.TestResourcePlural).Do().Into(&testList) + if err != nil { + panic(err) + } + logger.Info(fmt.Sprintf("LIST: %#v", testList)) +} diff --git a/bk/pkg/apis/testio/v1/doc.go b/bk/pkg/apis/testio/v1/doc.go deleted file mode 100644 index 4a890b5..0000000 --- a/bk/pkg/apis/testio/v1/doc.go +++ /dev/null @@ -1,5 +0,0 @@ -// +k8s:deepcopy-gen=package,register - -// Package v1 is the v1 version of the API. -// +groupName=testio -package v1 diff --git a/bk/pkg/apis/testio/v1/types.go b/bk/pkg/apis/testio/v1/types.go deleted file mode 100644 index 1f4523b..0000000 --- a/bk/pkg/apis/testio/v1/types.go +++ /dev/null @@ -1,53 +0,0 @@ -package v1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -const ( - TestResourcePlural string = "tests" - // GroupName is the group name used in this package. - GroupName string = "testio" - TestCRDName string = TestResourcePlural + "." + GroupName - version string = "v1" - StateCreated string = "Created" - StateProcessed string = "Processed" -) - -var ( - // SchemeGroupVersion is the group version used to register these objects. - SchemeGroupVersion = schema.GroupVersion{ - Group: GroupName, - Version: version, - } - SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - AddToScheme = SchemeBuilder.AddToScheme -) - -// Test is the CRD. -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type Test struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata"` - Spec TestSpec `json:"spec"` - Status TestStatus `json:"status,omitempty"` -} - -type TestSpec struct { - Foo string `json:"foo"` - Bar bool `json:"bar"` -} - -type TestStatus struct { - State string `json:"state,omitempty"` - Message string `json:"message,omitempty"` -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type TestList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata"` - Items []Test `json:"items"` -} diff --git a/bk/pkg/apis/testio/v1/zz_generated.deepcopy.go b/bk/pkg/apis/testio/v1/zz_generated.deepcopy.go deleted file mode 100644 index b8dd634..0000000 --- a/bk/pkg/apis/testio/v1/zz_generated.deepcopy.go +++ /dev/null @@ -1,151 +0,0 @@ -// +build !ignore_autogenerated - -/* -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. -*/ - -// This file was autogenerated by deepcopy-gen. Do not edit it manually! - -package v1 - -import ( - conversion "k8s.io/apimachinery/pkg/conversion" - runtime "k8s.io/apimachinery/pkg/runtime" - reflect "reflect" -) - -func init() { - SchemeBuilder.Register(RegisterDeepCopies) -} - -// RegisterDeepCopies adds deep-copy functions to the given scheme. Public -// to allow building arbitrary schemes. -// -// Deprecated: deepcopy registration will go away when static deepcopy is fully implemented. -func RegisterDeepCopies(scheme *runtime.Scheme) error { - return scheme.AddGeneratedDeepCopyFuncs( - conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error { - in.(*Test).DeepCopyInto(out.(*Test)) - return nil - }, InType: reflect.TypeOf(&Test{})}, - conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error { - in.(*TestList).DeepCopyInto(out.(*TestList)) - return nil - }, InType: reflect.TypeOf(&TestList{})}, - conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error { - in.(*TestSpec).DeepCopyInto(out.(*TestSpec)) - return nil - }, InType: reflect.TypeOf(&TestSpec{})}, - conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error { - in.(*TestStatus).DeepCopyInto(out.(*TestStatus)) - return nil - }, InType: reflect.TypeOf(&TestStatus{})}, - ) -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Test) DeepCopyInto(out *Test) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec - out.Status = in.Status - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Test. -func (in *Test) DeepCopy() *Test { - if in == nil { - return nil - } - out := new(Test) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Test) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } else { - return nil - } -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TestList) DeepCopyInto(out *TestList) { - *out = *in - out.TypeMeta = in.TypeMeta - out.ListMeta = in.ListMeta - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Test, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestList. -func (in *TestList) DeepCopy() *TestList { - if in == nil { - return nil - } - out := new(TestList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *TestList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } else { - return nil - } -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TestSpec) DeepCopyInto(out *TestSpec) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestSpec. -func (in *TestSpec) DeepCopy() *TestSpec { - if in == nil { - return nil - } - out := new(TestSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TestStatus) DeepCopyInto(out *TestStatus) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestStatus. -func (in *TestStatus) DeepCopy() *TestStatus { - if in == nil { - return nil - } - out := new(TestStatus) - in.DeepCopyInto(out) - return out -} diff --git a/bk/pkg/client/clientset/versioned/clientset.go b/bk/pkg/client/clientset/versioned/clientset.go deleted file mode 100644 index ce922aa..0000000 --- a/bk/pkg/client/clientset/versioned/clientset.go +++ /dev/null @@ -1,98 +0,0 @@ -/* -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 versioned - -import ( - glog "github.com/golang/glog" - testiov1 "github.com/jinghzhu/k8scrd/pkg/client/clientset/versioned/typed/testio/v1" - discovery "k8s.io/client-go/discovery" - rest "k8s.io/client-go/rest" - flowcontrol "k8s.io/client-go/util/flowcontrol" -) - -type Interface interface { - Discovery() discovery.DiscoveryInterface - TestioV1() testiov1.TestioV1Interface - // Deprecated: please explicitly pick a version if possible. - Testio() testiov1.TestioV1Interface -} - -// Clientset contains the clients for groups. Each group has exactly one -// version included in a Clientset. -type Clientset struct { - *discovery.DiscoveryClient - testioV1 *testiov1.TestioV1Client -} - -// TestioV1 retrieves the TestioV1Client -func (c *Clientset) TestioV1() testiov1.TestioV1Interface { - return c.testioV1 -} - -// Deprecated: Testio retrieves the default version of TestioClient. -// Please explicitly pick a version. -func (c *Clientset) Testio() testiov1.TestioV1Interface { - return c.testioV1 -} - -// Discovery retrieves the DiscoveryClient -func (c *Clientset) Discovery() discovery.DiscoveryInterface { - if c == nil { - return nil - } - return c.DiscoveryClient -} - -// NewForConfig creates a new Clientset for the given config. -func NewForConfig(c *rest.Config) (*Clientset, error) { - configShallowCopy := *c - if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { - configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) - } - var cs Clientset - var err error - cs.testioV1, err = testiov1.NewForConfig(&configShallowCopy) - if err != nil { - return nil, err - } - - cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(&configShallowCopy) - if err != nil { - glog.Errorf("failed to create the DiscoveryClient: %v", err) - return nil, err - } - return &cs, nil -} - -// NewForConfigOrDie creates a new Clientset for the given config and -// panics if there is an error in the config. -func NewForConfigOrDie(c *rest.Config) *Clientset { - var cs Clientset - cs.testioV1 = testiov1.NewForConfigOrDie(c) - - cs.DiscoveryClient = discovery.NewDiscoveryClientForConfigOrDie(c) - return &cs -} - -// New creates a new Clientset for the given RESTClient. -func New(c rest.Interface) *Clientset { - var cs Clientset - cs.testioV1 = testiov1.New(c) - - cs.DiscoveryClient = discovery.NewDiscoveryClient(c) - return &cs -} diff --git a/bk/pkg/client/clientset/versioned/doc.go b/bk/pkg/client/clientset/versioned/doc.go deleted file mode 100644 index 8fd89c6..0000000 --- a/bk/pkg/client/clientset/versioned/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -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. -*/ - -// This package is generated by client-gen with custom arguments. - -// This package has the automatically generated clientset. -package versioned diff --git a/bk/pkg/client/clientset/versioned/fake/clientset_generated.go b/bk/pkg/client/clientset/versioned/fake/clientset_generated.go deleted file mode 100644 index 1c87714..0000000 --- a/bk/pkg/client/clientset/versioned/fake/clientset_generated.go +++ /dev/null @@ -1,71 +0,0 @@ -/* -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 fake - -import ( - clientset "github.com/jinghzhu/k8scrd/pkg/client/clientset/versioned" - testiov1 "github.com/jinghzhu/k8scrd/pkg/client/clientset/versioned/typed/testio/v1" - faketestiov1 "github.com/jinghzhu/k8scrd/pkg/client/clientset/versioned/typed/testio/v1/fake" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/discovery" - fakediscovery "k8s.io/client-go/discovery/fake" - "k8s.io/client-go/testing" -) - -// NewSimpleClientset returns a clientset that will respond with the provided objects. -// It's backed by a very simple object tracker that processes creates, updates and deletions as-is, -// without applying any validations and/or defaults. It shouldn't be considered a replacement -// for a real clientset and is mostly useful in simple unit tests. -func NewSimpleClientset(objects ...runtime.Object) *Clientset { - o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) - for _, obj := range objects { - if err := o.Add(obj); err != nil { - panic(err) - } - } - - fakePtr := testing.Fake{} - fakePtr.AddReactor("*", "*", testing.ObjectReaction(o)) - fakePtr.AddWatchReactor("*", testing.DefaultWatchReactor(watch.NewFake(), nil)) - - return &Clientset{fakePtr, &fakediscovery.FakeDiscovery{Fake: &fakePtr}} -} - -// Clientset implements clientset.Interface. Meant to be embedded into a -// struct to get a default implementation. This makes faking out just the method -// you want to test easier. -type Clientset struct { - testing.Fake - discovery *fakediscovery.FakeDiscovery -} - -func (c *Clientset) Discovery() discovery.DiscoveryInterface { - return c.discovery -} - -var _ clientset.Interface = &Clientset{} - -// TestioV1 retrieves the TestioV1Client -func (c *Clientset) TestioV1() testiov1.TestioV1Interface { - return &faketestiov1.FakeTestioV1{Fake: &c.Fake} -} - -// Testio retrieves the TestioV1Client -func (c *Clientset) Testio() testiov1.TestioV1Interface { - return &faketestiov1.FakeTestioV1{Fake: &c.Fake} -} diff --git a/bk/pkg/client/clientset/versioned/fake/doc.go b/bk/pkg/client/clientset/versioned/fake/doc.go deleted file mode 100644 index 5f565b3..0000000 --- a/bk/pkg/client/clientset/versioned/fake/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -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. -*/ - -// This package is generated by client-gen with custom arguments. - -// This package has the automatically generated fake clientset. -package fake diff --git a/bk/pkg/client/clientset/versioned/fake/register.go b/bk/pkg/client/clientset/versioned/fake/register.go deleted file mode 100644 index 2a02dc2..0000000 --- a/bk/pkg/client/clientset/versioned/fake/register.go +++ /dev/null @@ -1,53 +0,0 @@ -/* -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 fake - -import ( - testiov1 "github.com/jinghzhu/k8scrd/pkg/apis/testio/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - schema "k8s.io/apimachinery/pkg/runtime/schema" - serializer "k8s.io/apimachinery/pkg/runtime/serializer" -) - -var scheme = runtime.NewScheme() -var codecs = serializer.NewCodecFactory(scheme) -var parameterCodec = runtime.NewParameterCodec(scheme) - -func init() { - v1.AddToGroupVersion(scheme, schema.GroupVersion{Version: "v1"}) - AddToScheme(scheme) -} - -// AddToScheme adds all types of this clientset into the given scheme. This allows composition -// of clientsets, like in: -// -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kuberentes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) -// -// kclientset, _ := kubernetes.NewForConfig(c) -// aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) -// -// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types -// correctly. -func AddToScheme(scheme *runtime.Scheme) { - testiov1.AddToScheme(scheme) - -} diff --git a/bk/pkg/client/clientset/versioned/scheme/doc.go b/bk/pkg/client/clientset/versioned/scheme/doc.go deleted file mode 100644 index 5d8ec82..0000000 --- a/bk/pkg/client/clientset/versioned/scheme/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -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. -*/ - -// This package is generated by client-gen with custom arguments. - -// This package contains the scheme of the automatically generated clientset. -package scheme diff --git a/bk/pkg/client/clientset/versioned/scheme/register.go b/bk/pkg/client/clientset/versioned/scheme/register.go deleted file mode 100644 index 29e6059..0000000 --- a/bk/pkg/client/clientset/versioned/scheme/register.go +++ /dev/null @@ -1,53 +0,0 @@ -/* -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 scheme - -import ( - testiov1 "github.com/jinghzhu/k8scrd/pkg/apis/testio/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - schema "k8s.io/apimachinery/pkg/runtime/schema" - serializer "k8s.io/apimachinery/pkg/runtime/serializer" -) - -var Scheme = runtime.NewScheme() -var Codecs = serializer.NewCodecFactory(Scheme) -var ParameterCodec = runtime.NewParameterCodec(Scheme) - -func init() { - v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) - AddToScheme(Scheme) -} - -// AddToScheme adds all types of this clientset into the given scheme. This allows composition -// of clientsets, like in: -// -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kuberentes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) -// -// kclientset, _ := kubernetes.NewForConfig(c) -// aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) -// -// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types -// correctly. -func AddToScheme(scheme *runtime.Scheme) { - testiov1.AddToScheme(scheme) - -} diff --git a/bk/pkg/client/clientset/versioned/typed/testio/v1/doc.go b/bk/pkg/client/clientset/versioned/typed/testio/v1/doc.go deleted file mode 100644 index 54673bf..0000000 --- a/bk/pkg/client/clientset/versioned/typed/testio/v1/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -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. -*/ - -// This package is generated by client-gen with custom arguments. - -// This package has the automatically generated typed clients. -package v1 diff --git a/bk/pkg/client/clientset/versioned/typed/testio/v1/fake/doc.go b/bk/pkg/client/clientset/versioned/typed/testio/v1/fake/doc.go deleted file mode 100644 index c654833..0000000 --- a/bk/pkg/client/clientset/versioned/typed/testio/v1/fake/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -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. -*/ - -// This package is generated by client-gen with custom arguments. - -// Package fake has the automatically generated clients. -package fake diff --git a/bk/pkg/client/clientset/versioned/typed/testio/v1/fake/fake_testio_client.go b/bk/pkg/client/clientset/versioned/typed/testio/v1/fake/fake_testio_client.go deleted file mode 100644 index b01314d..0000000 --- a/bk/pkg/client/clientset/versioned/typed/testio/v1/fake/fake_testio_client.go +++ /dev/null @@ -1,21 +0,0 @@ -/* -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 fake - -import ( - v1 "github.com/jinghzhu/k8scrd/pkg/client/clientset/versioned/typed/testio/v1" -) diff --git a/bk/pkg/client/clientset/versioned/typed/testio/v1/generated_expansion.go b/bk/pkg/client/clientset/versioned/typed/testio/v1/generated_expansion.go deleted file mode 100644 index 42e76d5..0000000 --- a/bk/pkg/client/clientset/versioned/typed/testio/v1/generated_expansion.go +++ /dev/null @@ -1,17 +0,0 @@ -/* -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 v1 diff --git a/bk/pkg/client/clientset/versioned/typed/testio/v1/testio_client.go b/bk/pkg/client/clientset/versioned/typed/testio/v1/testio_client.go deleted file mode 100644 index 5256236..0000000 --- a/bk/pkg/client/clientset/versioned/typed/testio/v1/testio_client.go +++ /dev/null @@ -1,21 +0,0 @@ -/* -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 v1 - -import ( - "github.com/jinghzhu/k8scrd/pkg/client/clientset/versioned/scheme" -) diff --git a/client/client.go b/client/client.go index d658830..efbdfc1 100644 --- a/client/client.go +++ b/client/client.go @@ -1,51 +1,45 @@ +/* +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 client import ( - "time" - - "github.com/jinghzhu/GoUtils/logger" - crd "github.com/jinghzhu/k8scrd/apis/test0.io/v1" - corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/serializer" - "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/rest" + + crv1 "github.com/jinghzhu/k8scrd/apis/cr/v1" ) func NewClient(cfg *rest.Config) (*rest.RESTClient, *runtime.Scheme, error) { scheme := runtime.NewScheme() - if err := crd.AddToScheme(scheme); err != nil { + if err := crv1.AddToScheme(scheme); err != nil { return nil, nil, err } config := *cfg - config.GroupVersion = &crd.SchemeGroupVersion + config.GroupVersion = &crv1.SchemeGroupVersion config.APIPath = "/apis" config.ContentType = runtime.ContentTypeJSON config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: serializer.NewCodecFactory(scheme)} client, err := rest.RESTClientFor(&config) if err != nil { - logger.Error("Fail to generate REST client: " + err.Error()) return nil, nil, err } return client, scheme, nil } - -func WaitForInstanceProcessed(testClient *rest.RESTClient, name string) error { - return wait.Poll(100*time.Millisecond, 10*time.Second, func() (bool, error) { - var instance crd.Test - err := testClient.Get(). - Resource(crd.TestResourcePlural). - Namespace(corev1.NamespaceDefault). - Name(name). - Do().Into(&instance) - - if err == nil && instance.Status.State == crd.StateProcessed { - return true, nil - } - - return false, err - }) -} diff --git a/client/cr.go b/client/cr.go new file mode 100644 index 0000000..66513b5 --- /dev/null +++ b/client/cr.go @@ -0,0 +1,103 @@ +/* +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 client + +import ( + "fmt" + "reflect" + "time" + + apiv1 "k8s.io/api/core/v1" + crv1 "k8s.io/apiextensions-apiserver/examples/client-go/apis/cr/v1" + apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" + apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/errors" + "k8s.io/apimachinery/pkg/util/wait" + "k8s.io/client-go/rest" + // Uncomment the following line to load the gcp plugin (only required to authenticate against GKE clusters). + // _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" +) + +const exampleCRDName = crv1.ExampleResourcePlural + "." + crv1.GroupName + +func CreateCustomResourceDefinition(clientset apiextensionsclient.Interface) (*apiextensionsv1beta1.CustomResourceDefinition, error) { + crd := &apiextensionsv1beta1.CustomResourceDefinition{ + ObjectMeta: metav1.ObjectMeta{ + Name: exampleCRDName, + }, + Spec: apiextensionsv1beta1.CustomResourceDefinitionSpec{ + Group: crv1.GroupName, + Version: crv1.SchemeGroupVersion.Version, + Scope: apiextensionsv1beta1.NamespaceScoped, + Names: apiextensionsv1beta1.CustomResourceDefinitionNames{ + Plural: crv1.ExampleResourcePlural, + Kind: reflect.TypeOf(crv1.Example{}).Name(), + }, + }, + } + _, err := clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd) + if err != nil { + return nil, err + } + + // wait for CRD being established + err = wait.Poll(500*time.Millisecond, 60*time.Second, func() (bool, error) { + crd, err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Get(exampleCRDName, metav1.GetOptions{}) + if err != nil { + return false, err + } + for _, cond := range crd.Status.Conditions { + switch cond.Type { + case apiextensionsv1beta1.Established: + if cond.Status == apiextensionsv1beta1.ConditionTrue { + return true, err + } + case apiextensionsv1beta1.NamesAccepted: + if cond.Status == apiextensionsv1beta1.ConditionFalse { + fmt.Printf("Name conflict: %v\n", cond.Reason) + } + } + } + return false, err + }) + if err != nil { + deleteErr := clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete(exampleCRDName, nil) + if deleteErr != nil { + return nil, errors.NewAggregate([]error{err, deleteErr}) + } + return nil, err + } + return crd, nil +} + +func WaitForExampleInstanceProcessed(exampleClient *rest.RESTClient, name string) error { + return wait.Poll(100*time.Millisecond, 10*time.Second, func() (bool, error) { + var example crv1.Example + err := exampleClient.Get(). + Resource(crv1.ExampleResourcePlural). + Namespace(apiv1.NamespaceDefault). + Name(name). + Do().Into(&example) + + if err == nil && example.Status.State == crv1.ExampleStateProcessed { + return true, nil + } + + return false, err + }) +} diff --git a/controller/controller.go b/controller/controller.go index 2e58ffc..b71a4e1 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -1,92 +1,120 @@ +/* +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 controller import ( "context" "fmt" - logger "github.com/jinghzhu/GoUtils/logger" - crd "github.com/jinghzhu/k8scrd/apis/test0.io/v1" - corev1 "k8s.io/api/core/v1" + apiv1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/fields" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/client-go/rest" "k8s.io/client-go/tools/cache" + + crv1 "github.com/jinghzhu/k8scrd/apis/cr/v1" ) -// Run starts a CRD resource controller. -func (c *TestController) Run(ctx context.Context) error { - logger.Info("Watch CRD objects") +// Watcher is an example of watching on resource create/update/delete events +type ExampleController struct { + ExampleClient *rest.RESTClient + ExampleScheme *runtime.Scheme +} + +// Run starts an Example resource controller +func (c *ExampleController) Run(ctx context.Context) error { + fmt.Print("Watch Example objects\n") - // Watch CRD objects - _, err := c.watch(ctx) + // Watch Example objects + _, err := c.watchExamples(ctx) if err != nil { fmt.Printf("Failed to register watch for Example resource: %v\n", err) return err } - // <-ctx.Done() + <-ctx.Done() return ctx.Err() } -func (c *TestController) watch(ctx context.Context) (cache.Controller, error) { +func (c *ExampleController) watchExamples(ctx context.Context) (cache.Controller, error) { source := cache.NewListWatchFromClient( - c.TestClient, - crd.TestResourcePlural, - corev1.NamespaceAll, - fields.Everything(), - ) + c.ExampleClient, + crv1.ExampleResourcePlural, + apiv1.NamespaceAll, + fields.Everything()) _, controller := cache.NewInformer( source, - &crd.Test{}, + + // The object type. + &crv1.Example{}, + + // resyncPeriod // Every resyncPeriod, all resources in the cache will retrigger events. // Set to 0 to disable the resync. 0, - // CRD event handlers. + + // Your custom resource event handlers. cache.ResourceEventHandlerFuncs{ AddFunc: c.onAdd, UpdateFunc: c.onUpdate, DeleteFunc: c.onDelete, - }, - ) + }) - // go controller.Run(ctx.Done() + go controller.Run(ctx.Done()) return controller, nil } -func (c *TestController) onAdd(obj interface{}) { - test := obj.(*crd.Test) - logger.Info("[CONTROLLER] OnAdd " + test.ObjectMeta.SelfLink) +func (c *ExampleController) onAdd(obj interface{}) { + example := obj.(*crv1.Example) + fmt.Printf("[CONTROLLER] OnAdd %s\n", example.ObjectMeta.SelfLink) - // Use DeepCopy() to make a deep copy of original object and modify this copy - // or create a copy manually for better performance. - testCopy := test.DeepCopy() - testCopy.Status = crd.TestStatus{ - State: crd.StateProcessed, + // NEVER modify objects from the store. It's a read-only, local cache. + // You can use DeepCopy() to make a deep copy of original object and modify this copy + // Or create a copy manually for better performance + exampleCopy := example.DeepCopy() + exampleCopy.Status = crv1.ExampleStatus{ + State: crv1.ExampleStateProcessed, Message: "Successfully processed by controller", } - err := c.TestClient.Put(). - Name(test.ObjectMeta.Name). - Namespace(test.ObjectMeta.Namespace). - Resource(crd.TestResourcePlural). - Body(testCopy). + err := c.ExampleClient.Put(). + Name(example.ObjectMeta.Name). + Namespace(example.ObjectMeta.Namespace). + Resource(crv1.ExampleResourcePlural). + Body(exampleCopy). Do(). Error() if err != nil { - logger.Error("ERROR updating status: " + err.Error()) + fmt.Printf("ERROR updating status: %v\n", err) } else { - logger.Info("UPDATED status: " + testCopy.SelfLink) + fmt.Printf("UPDATED status: %#v\n", exampleCopy) } } -func (c *TestController) onUpdate(oldObj, newObj interface{}) { - old := oldObj.(*crd.Test) - new := newObj.(*crd.Test) - logger.Info("[CONTROLLER] OnUpdate old: " + old.ObjectMeta.SelfLink) - logger.Info("[CONTROLLER] OnUpdate new: " + new.ObjectMeta.SelfLink) +func (c *ExampleController) onUpdate(oldObj, newObj interface{}) { + oldExample := oldObj.(*crv1.Example) + newExample := newObj.(*crv1.Example) + fmt.Printf("[CONTROLLER] OnUpdate oldObj: %s\n", oldExample.ObjectMeta.SelfLink) + fmt.Printf("[CONTROLLER] OnUpdate newObj: %s\n", newExample.ObjectMeta.SelfLink) } -func (c *TestController) onDelete(obj interface{}) { - test := obj.(*crd.Test) - logger.Info("[CONTROLLER] OnDelete " + test.ObjectMeta.SelfLink) +func (c *ExampleController) onDelete(obj interface{}) { + example := obj.(*crv1.Example) + fmt.Printf("[CONTROLLER] OnDelete %s\n", example.ObjectMeta.SelfLink) } diff --git a/main.go b/main.go index d711d8f..c3fbfc8 100644 --- a/main.go +++ b/main.go @@ -2,95 +2,112 @@ package main import ( "context" + "flag" "fmt" - "os" - logger "github.com/jinghzhu/GoUtils/logger" - test0v1 "github.com/jinghzhu/k8scrd/apis/test0.io/v1" - "github.com/jinghzhu/k8scrd/client" - "github.com/jinghzhu/k8scrd/controller" - corev1 "k8s.io/api/core/v1" + apiv1 "k8s.io/api/core/v1" apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" + + // Uncomment the following line to load the gcp plugin (only required to authenticate against GKE clusters). + // _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" + + crv1 "github.com/jinghzhu/k8scrd/apis/cr/v1" + exampleclient "github.com/jinghzhu/k8scrd/client" + examplecontroller "github.com/jinghzhu/k8scrd/controller" ) func main() { - kubeconfig := os.Getenv("KUBECONFIG") + kubeconfig := flag.String("kubeconfig", "/Users/jinghuaz/.kube/config", "Path to a kube config. Only required if out-of-cluster.") + flag.Parse() - // Use kubeconfig to create client config. - clientConfig, err := clientcmd.BuildConfigFromFlags("", kubeconfig) + // Create the client config. Use kubeconfig if given, otherwise assume in-cluster. + config, err := buildConfig(*kubeconfig) if err != nil { panic(err) } - apiextensionsClientSet, err := apiextensionsclient.NewForConfig(clientConfig) + apiextensionsclientset, err := apiextensionsclient.NewForConfig(config) if err != nil { panic(err) } - // Init a CRD. - _, err = test0v1.CreateCustomResourceDefinition(apiextensionsClientSet) + // initialize custom resource using a CustomResourceDefinition if it does not exist + crd, err := exampleclient.CreateCustomResourceDefinition(apiextensionsclientset) if err != nil && !apierrors.IsAlreadyExists(err) { panic(err) } - // Make a new config for extension's API group and use the first one as the baseline. - testClient, testScheme, err := client.NewClient(clientConfig) + if crd != nil { + defer apiextensionsclientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete(crd.Name, nil) + } + + // make a new config for our extension's API group, using the first config as a baseline + exampleClient, exampleScheme, err := exampleclient.NewClient(config) if err != nil { panic(err) } - // Start CRD controller. - controller := controller.TestController{ - TestClient: testClient, - TestScheme: testScheme, + // start a controller on instances of our custom resource + controller := examplecontroller.ExampleController{ + ExampleClient: exampleClient, + ExampleScheme: exampleScheme, } - ctx := context.Background() + + ctx, cancelFunc := context.WithCancel(context.Background()) + defer cancelFunc() go controller.Run(ctx) - // Create an instance of CRD. - instanceName := "test1" - testInstance := test0v1.Test{ + // Create an instance of our custom resource + example := &crv1.Example{ ObjectMeta: metav1.ObjectMeta{ - Name: instanceName, + Name: "example1", }, - Spec: test0v1.TestSpec{ + Spec: crv1.ExampleSpec{ Foo: "hello", Bar: true, }, - Status: test0v1.TestStatus{ - State: test0v1.StateCreated, - Message: "Created but not processed yet", + Status: crv1.ExampleStatus{ + State: crv1.ExampleStateCreated, + Message: "Created, not processed yet", }, } - var result test0v1.Test - err = testClient.Post(). - Resource(test0v1.TestResourcePlural). - Namespace(corev1.NamespaceDefault). - Body(testInstance). + var result crv1.Example + err = exampleClient.Post(). + Resource(crv1.ExampleResourcePlural). + Namespace(apiv1.NamespaceDefault). + Body(example). Do().Into(&result) if err == nil { - logger.Info(fmt.Sprintf("CREATED: %#v", result)) + fmt.Printf("CREATED: %#v\n", result) } else if apierrors.IsAlreadyExists(err) { - logger.Info(fmt.Sprintf("ALREADY EXISTS: %#v", result)) + fmt.Printf("ALREADY EXISTS: %#v\n", result) } else { panic(err) } - // Wait until the CRD object is handled by controller and its status is changed to Processed. - err = client.WaitForInstanceProcessed(testClient, instanceName) + // Poll until Example object is handled by controller and gets status updated to "Processed" + err = exampleclient.WaitForExampleInstanceProcessed(exampleClient, "example1") if err != nil { panic(err) } - logger.Info("Porcessed") + fmt.Print("PROCESSED\n") - // Get the list of CRs. - testList := test0v1.TestList{} - err = testClient.Get().Resource(test0v1.TestResourcePlural).Do().Into(&testList) + // Fetch a list of our CRs + exampleList := crv1.ExampleList{} + err = exampleClient.Get().Resource(crv1.ExampleResourcePlural).Do().Into(&exampleList) if err != nil { panic(err) } - logger.Info(fmt.Sprintf("LIST: %#v", testList)) + fmt.Printf("LIST: %#v\n", exampleList) +} + +func buildConfig(kubeconfig string) (*rest.Config, error) { + if kubeconfig != "" { + return clientcmd.BuildConfigFromFlags("", kubeconfig) + } + return rest.InClusterConfig() } From eb1a2c943684363e079c2eb4fb6248e323048226 Mon Sep 17 00:00:00 2001 From: Jinghua Zhu Date: Tue, 12 Dec 2017 10:20:17 +0000 Subject: [PATCH 2/6] Add vendor --- apis/cr/v1/zz_generated.deepcopy.go | 146 ++++++++++++++++++ client/clientset/versioned/clientset.go | 98 ++++++++++++ client/clientset/versioned/doc.go | 20 +++ .../versioned/fake/clientset_generated.go | 71 +++++++++ client/clientset/versioned/fake/doc.go | 20 +++ client/clientset/versioned/fake/register.go | 53 +++++++ client/clientset/versioned/scheme/doc.go | 20 +++ client/clientset/versioned/scheme/register.go | 53 +++++++ .../versioned/typed/cr/v1/cr_client.go | 21 +++ client/clientset/versioned/typed/cr/v1/doc.go | 20 +++ .../versioned/typed/cr/v1/fake/doc.go | 20 +++ .../typed/cr/v1/fake/fake_cr_client.go | 21 +++ .../typed/cr/v1/generated_expansion.go | 17 ++ 13 files changed, 580 insertions(+) create mode 100644 apis/cr/v1/zz_generated.deepcopy.go create mode 100644 client/clientset/versioned/clientset.go create mode 100644 client/clientset/versioned/doc.go create mode 100644 client/clientset/versioned/fake/clientset_generated.go create mode 100644 client/clientset/versioned/fake/doc.go create mode 100644 client/clientset/versioned/fake/register.go create mode 100644 client/clientset/versioned/scheme/doc.go create mode 100644 client/clientset/versioned/scheme/register.go create mode 100644 client/clientset/versioned/typed/cr/v1/cr_client.go create mode 100644 client/clientset/versioned/typed/cr/v1/doc.go create mode 100644 client/clientset/versioned/typed/cr/v1/fake/doc.go create mode 100644 client/clientset/versioned/typed/cr/v1/fake/fake_cr_client.go create mode 100644 client/clientset/versioned/typed/cr/v1/generated_expansion.go diff --git a/apis/cr/v1/zz_generated.deepcopy.go b/apis/cr/v1/zz_generated.deepcopy.go new file mode 100644 index 0000000..e9f2a4c --- /dev/null +++ b/apis/cr/v1/zz_generated.deepcopy.go @@ -0,0 +1,146 @@ +// +build !ignore_autogenerated + +/* +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. +*/ + +// This file was autogenerated by deepcopy-gen. Do not edit it manually! + +package v1 + +import ( + conversion "k8s.io/apimachinery/pkg/conversion" + runtime "k8s.io/apimachinery/pkg/runtime" + reflect "reflect" +) + +// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them. +// +// Deprecated: deepcopy registration will go away when static deepcopy is fully implemented. +func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc { + return []conversion.GeneratedDeepCopyFunc{ + {Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error { + in.(*Example).DeepCopyInto(out.(*Example)) + return nil + }, InType: reflect.TypeOf(&Example{})}, + {Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error { + in.(*ExampleList).DeepCopyInto(out.(*ExampleList)) + return nil + }, InType: reflect.TypeOf(&ExampleList{})}, + {Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error { + in.(*ExampleSpec).DeepCopyInto(out.(*ExampleSpec)) + return nil + }, InType: reflect.TypeOf(&ExampleSpec{})}, + {Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error { + in.(*ExampleStatus).DeepCopyInto(out.(*ExampleStatus)) + return nil + }, InType: reflect.TypeOf(&ExampleStatus{})}, + } +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Example) DeepCopyInto(out *Example) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec + out.Status = in.Status + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Example. +func (in *Example) DeepCopy() *Example { + if in == nil { + return nil + } + out := new(Example) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Example) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } else { + return nil + } +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ExampleList) DeepCopyInto(out *ExampleList) { + *out = *in + out.TypeMeta = in.TypeMeta + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Example, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExampleList. +func (in *ExampleList) DeepCopy() *ExampleList { + if in == nil { + return nil + } + out := new(ExampleList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ExampleList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } else { + return nil + } +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ExampleSpec) DeepCopyInto(out *ExampleSpec) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExampleSpec. +func (in *ExampleSpec) DeepCopy() *ExampleSpec { + if in == nil { + return nil + } + out := new(ExampleSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ExampleStatus) DeepCopyInto(out *ExampleStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExampleStatus. +func (in *ExampleStatus) DeepCopy() *ExampleStatus { + if in == nil { + return nil + } + out := new(ExampleStatus) + in.DeepCopyInto(out) + return out +} diff --git a/client/clientset/versioned/clientset.go b/client/clientset/versioned/clientset.go new file mode 100644 index 0000000..be7e96a --- /dev/null +++ b/client/clientset/versioned/clientset.go @@ -0,0 +1,98 @@ +/* +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 versioned + +import ( + glog "github.com/golang/glog" + crv1 "github.com/jinghzhu/k8scrd/client/clientset/versioned/typed/cr/v1" + discovery "k8s.io/client-go/discovery" + rest "k8s.io/client-go/rest" + flowcontrol "k8s.io/client-go/util/flowcontrol" +) + +type Interface interface { + Discovery() discovery.DiscoveryInterface + CrV1() crv1.CrV1Interface + // Deprecated: please explicitly pick a version if possible. + Cr() crv1.CrV1Interface +} + +// Clientset contains the clients for groups. Each group has exactly one +// version included in a Clientset. +type Clientset struct { + *discovery.DiscoveryClient + crV1 *crv1.CrV1Client +} + +// CrV1 retrieves the CrV1Client +func (c *Clientset) CrV1() crv1.CrV1Interface { + return c.crV1 +} + +// Deprecated: Cr retrieves the default version of CrClient. +// Please explicitly pick a version. +func (c *Clientset) Cr() crv1.CrV1Interface { + return c.crV1 +} + +// Discovery retrieves the DiscoveryClient +func (c *Clientset) Discovery() discovery.DiscoveryInterface { + if c == nil { + return nil + } + return c.DiscoveryClient +} + +// NewForConfig creates a new Clientset for the given config. +func NewForConfig(c *rest.Config) (*Clientset, error) { + configShallowCopy := *c + if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { + configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) + } + var cs Clientset + var err error + cs.crV1, err = crv1.NewForConfig(&configShallowCopy) + if err != nil { + return nil, err + } + + cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(&configShallowCopy) + if err != nil { + glog.Errorf("failed to create the DiscoveryClient: %v", err) + return nil, err + } + return &cs, nil +} + +// NewForConfigOrDie creates a new Clientset for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *Clientset { + var cs Clientset + cs.crV1 = crv1.NewForConfigOrDie(c) + + cs.DiscoveryClient = discovery.NewDiscoveryClientForConfigOrDie(c) + return &cs +} + +// New creates a new Clientset for the given RESTClient. +func New(c rest.Interface) *Clientset { + var cs Clientset + cs.crV1 = crv1.New(c) + + cs.DiscoveryClient = discovery.NewDiscoveryClient(c) + return &cs +} diff --git a/client/clientset/versioned/doc.go b/client/clientset/versioned/doc.go new file mode 100644 index 0000000..8fd89c6 --- /dev/null +++ b/client/clientset/versioned/doc.go @@ -0,0 +1,20 @@ +/* +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. +*/ + +// This package is generated by client-gen with custom arguments. + +// This package has the automatically generated clientset. +package versioned diff --git a/client/clientset/versioned/fake/clientset_generated.go b/client/clientset/versioned/fake/clientset_generated.go new file mode 100644 index 0000000..b10e2a0 --- /dev/null +++ b/client/clientset/versioned/fake/clientset_generated.go @@ -0,0 +1,71 @@ +/* +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 fake + +import ( + clientset "github.com/jinghzhu/k8scrd/client/clientset/versioned" + crv1 "github.com/jinghzhu/k8scrd/client/clientset/versioned/typed/cr/v1" + fakecrv1 "github.com/jinghzhu/k8scrd/client/clientset/versioned/typed/cr/v1/fake" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/discovery" + fakediscovery "k8s.io/client-go/discovery/fake" + "k8s.io/client-go/testing" +) + +// NewSimpleClientset returns a clientset that will respond with the provided objects. +// It's backed by a very simple object tracker that processes creates, updates and deletions as-is, +// without applying any validations and/or defaults. It shouldn't be considered a replacement +// for a real clientset and is mostly useful in simple unit tests. +func NewSimpleClientset(objects ...runtime.Object) *Clientset { + o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) + for _, obj := range objects { + if err := o.Add(obj); err != nil { + panic(err) + } + } + + fakePtr := testing.Fake{} + fakePtr.AddReactor("*", "*", testing.ObjectReaction(o)) + fakePtr.AddWatchReactor("*", testing.DefaultWatchReactor(watch.NewFake(), nil)) + + return &Clientset{fakePtr, &fakediscovery.FakeDiscovery{Fake: &fakePtr}} +} + +// Clientset implements clientset.Interface. Meant to be embedded into a +// struct to get a default implementation. This makes faking out just the method +// you want to test easier. +type Clientset struct { + testing.Fake + discovery *fakediscovery.FakeDiscovery +} + +func (c *Clientset) Discovery() discovery.DiscoveryInterface { + return c.discovery +} + +var _ clientset.Interface = &Clientset{} + +// CrV1 retrieves the CrV1Client +func (c *Clientset) CrV1() crv1.CrV1Interface { + return &fakecrv1.FakeCrV1{Fake: &c.Fake} +} + +// Cr retrieves the CrV1Client +func (c *Clientset) Cr() crv1.CrV1Interface { + return &fakecrv1.FakeCrV1{Fake: &c.Fake} +} diff --git a/client/clientset/versioned/fake/doc.go b/client/clientset/versioned/fake/doc.go new file mode 100644 index 0000000..5f565b3 --- /dev/null +++ b/client/clientset/versioned/fake/doc.go @@ -0,0 +1,20 @@ +/* +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. +*/ + +// This package is generated by client-gen with custom arguments. + +// This package has the automatically generated fake clientset. +package fake diff --git a/client/clientset/versioned/fake/register.go b/client/clientset/versioned/fake/register.go new file mode 100644 index 0000000..35a254b --- /dev/null +++ b/client/clientset/versioned/fake/register.go @@ -0,0 +1,53 @@ +/* +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 fake + +import ( + crv1 "github.com/jinghzhu/k8scrd/apis/cr/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" +) + +var scheme = runtime.NewScheme() +var codecs = serializer.NewCodecFactory(scheme) +var parameterCodec = runtime.NewParameterCodec(scheme) + +func init() { + v1.AddToGroupVersion(scheme, schema.GroupVersion{Version: "v1"}) + AddToScheme(scheme) +} + +// AddToScheme adds all types of this clientset into the given scheme. This allows composition +// of clientsets, like in: +// +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kuberentes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) +// +// kclientset, _ := kubernetes.NewForConfig(c) +// aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// +// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types +// correctly. +func AddToScheme(scheme *runtime.Scheme) { + crv1.AddToScheme(scheme) + +} diff --git a/client/clientset/versioned/scheme/doc.go b/client/clientset/versioned/scheme/doc.go new file mode 100644 index 0000000..5d8ec82 --- /dev/null +++ b/client/clientset/versioned/scheme/doc.go @@ -0,0 +1,20 @@ +/* +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. +*/ + +// This package is generated by client-gen with custom arguments. + +// This package contains the scheme of the automatically generated clientset. +package scheme diff --git a/client/clientset/versioned/scheme/register.go b/client/clientset/versioned/scheme/register.go new file mode 100644 index 0000000..ca28b67 --- /dev/null +++ b/client/clientset/versioned/scheme/register.go @@ -0,0 +1,53 @@ +/* +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 scheme + +import ( + crv1 "github.com/jinghzhu/k8scrd/apis/cr/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" +) + +var Scheme = runtime.NewScheme() +var Codecs = serializer.NewCodecFactory(Scheme) +var ParameterCodec = runtime.NewParameterCodec(Scheme) + +func init() { + v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) + AddToScheme(Scheme) +} + +// AddToScheme adds all types of this clientset into the given scheme. This allows composition +// of clientsets, like in: +// +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kuberentes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) +// +// kclientset, _ := kubernetes.NewForConfig(c) +// aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// +// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types +// correctly. +func AddToScheme(scheme *runtime.Scheme) { + crv1.AddToScheme(scheme) + +} diff --git a/client/clientset/versioned/typed/cr/v1/cr_client.go b/client/clientset/versioned/typed/cr/v1/cr_client.go new file mode 100644 index 0000000..cc9b316 --- /dev/null +++ b/client/clientset/versioned/typed/cr/v1/cr_client.go @@ -0,0 +1,21 @@ +/* +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 v1 + +import ( + "github.com/jinghzhu/k8scrd/client/clientset/versioned/scheme" +) diff --git a/client/clientset/versioned/typed/cr/v1/doc.go b/client/clientset/versioned/typed/cr/v1/doc.go new file mode 100644 index 0000000..54673bf --- /dev/null +++ b/client/clientset/versioned/typed/cr/v1/doc.go @@ -0,0 +1,20 @@ +/* +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. +*/ + +// This package is generated by client-gen with custom arguments. + +// This package has the automatically generated typed clients. +package v1 diff --git a/client/clientset/versioned/typed/cr/v1/fake/doc.go b/client/clientset/versioned/typed/cr/v1/fake/doc.go new file mode 100644 index 0000000..c654833 --- /dev/null +++ b/client/clientset/versioned/typed/cr/v1/fake/doc.go @@ -0,0 +1,20 @@ +/* +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. +*/ + +// This package is generated by client-gen with custom arguments. + +// Package fake has the automatically generated clients. +package fake diff --git a/client/clientset/versioned/typed/cr/v1/fake/fake_cr_client.go b/client/clientset/versioned/typed/cr/v1/fake/fake_cr_client.go new file mode 100644 index 0000000..16aa379 --- /dev/null +++ b/client/clientset/versioned/typed/cr/v1/fake/fake_cr_client.go @@ -0,0 +1,21 @@ +/* +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 fake + +import ( + v1 "github.com/jinghzhu/k8scrd/client/clientset/versioned/typed/cr/v1" +) diff --git a/client/clientset/versioned/typed/cr/v1/generated_expansion.go b/client/clientset/versioned/typed/cr/v1/generated_expansion.go new file mode 100644 index 0000000..42e76d5 --- /dev/null +++ b/client/clientset/versioned/typed/cr/v1/generated_expansion.go @@ -0,0 +1,17 @@ +/* +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 v1 From f7dd9f5ab92834f5a371030ef77a476ccc113aa1 Mon Sep 17 00:00:00 2001 From: Jinghua ZHU Date: Tue, 12 Dec 2017 20:02:51 +0800 Subject: [PATCH 3/6] start test --- apis/cr/v1/register.go | 49 ------ apis/cr/v1/roundtrip_test.go | 66 -------- apis/cr/v1/zz_generated.deepcopy.go | 146 ------------------ apis/test.io/register.go | 5 + apis/{cr => test.io}/v1/doc.go | 0 apis/{cr => test.io}/v1/types.go | 2 +- client/clientset/versioned/clientset.go | 98 ------------ client/clientset/versioned/doc.go | 20 --- .../versioned/fake/clientset_generated.go | 71 --------- client/clientset/versioned/fake/doc.go | 20 --- client/clientset/versioned/fake/register.go | 53 ------- client/clientset/versioned/scheme/doc.go | 20 --- client/clientset/versioned/scheme/register.go | 53 ------- .../versioned/typed/cr/v1/cr_client.go | 21 --- client/clientset/versioned/typed/cr/v1/doc.go | 20 --- .../versioned/typed/cr/v1/fake/doc.go | 20 --- .../typed/cr/v1/fake/fake_cr_client.go | 21 --- .../typed/cr/v1/generated_expansion.go | 17 -- 18 files changed, 6 insertions(+), 696 deletions(-) delete mode 100644 apis/cr/v1/register.go delete mode 100644 apis/cr/v1/roundtrip_test.go delete mode 100644 apis/cr/v1/zz_generated.deepcopy.go create mode 100644 apis/test.io/register.go rename apis/{cr => test.io}/v1/doc.go (100%) rename apis/{cr => test.io}/v1/types.go (95%) delete mode 100644 client/clientset/versioned/clientset.go delete mode 100644 client/clientset/versioned/doc.go delete mode 100644 client/clientset/versioned/fake/clientset_generated.go delete mode 100644 client/clientset/versioned/fake/doc.go delete mode 100644 client/clientset/versioned/fake/register.go delete mode 100644 client/clientset/versioned/scheme/doc.go delete mode 100644 client/clientset/versioned/scheme/register.go delete mode 100644 client/clientset/versioned/typed/cr/v1/cr_client.go delete mode 100644 client/clientset/versioned/typed/cr/v1/doc.go delete mode 100644 client/clientset/versioned/typed/cr/v1/fake/doc.go delete mode 100644 client/clientset/versioned/typed/cr/v1/fake/fake_cr_client.go delete mode 100644 client/clientset/versioned/typed/cr/v1/generated_expansion.go diff --git a/apis/cr/v1/register.go b/apis/cr/v1/register.go deleted file mode 100644 index 1ee348e..0000000 --- a/apis/cr/v1/register.go +++ /dev/null @@ -1,49 +0,0 @@ -/* -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 v1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -var ( - SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - AddToScheme = SchemeBuilder.AddToScheme -) - -// GroupName is the group name used in this package. -const GroupName = "cr.client-go.k8s.io" - -// SchemeGroupVersion is the group version used to register these objects. -var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"} - -// Resource takes an unqualified resource and returns a Group-qualified GroupResource. -func Resource(resource string) schema.GroupResource { - return SchemeGroupVersion.WithResource(resource).GroupResource() -} - -// addKnownTypes adds the set of types defined in this package to the supplied scheme. -func addKnownTypes(scheme *runtime.Scheme) error { - scheme.AddKnownTypes(SchemeGroupVersion, - &Example{}, - &ExampleList{}, - ) - metav1.AddToGroupVersion(scheme, SchemeGroupVersion) - return nil -} diff --git a/apis/cr/v1/roundtrip_test.go b/apis/cr/v1/roundtrip_test.go deleted file mode 100644 index 7373c78..0000000 --- a/apis/cr/v1/roundtrip_test.go +++ /dev/null @@ -1,66 +0,0 @@ -/* -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 v1 - -import ( - "math/rand" - "testing" - - "github.com/google/gofuzz" - - "k8s.io/apimachinery/pkg/api/testing/fuzzer" - roundtrip "k8s.io/apimachinery/pkg/api/testing/roundtrip" - metafuzzer "k8s.io/apimachinery/pkg/apis/meta/fuzzer" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/serializer" - runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer" -) - -var _ runtime.Object = &Example{} -var _ metav1.ObjectMetaAccessor = &Example{} - -var _ runtime.Object = &ExampleList{} -var _ metav1.ListMetaAccessor = &ExampleList{} - -func exampleFuzzerFuncs(codecs runtimeserializer.CodecFactory) []interface{} { - return []interface{}{ - func(obj *ExampleList, c fuzz.Continue) { - c.FuzzNoCustom(obj) - obj.Items = make([]Example, c.Intn(10)) - for i := range obj.Items { - c.Fuzz(&obj.Items[i]) - } - }, - } -} - -// TestRoundTrip tests that the third-party kinds can be marshaled and unmarshaled correctly to/from JSON -// without the loss of information. Moreover, deep copy is tested. -func TestRoundTrip(t *testing.T) { - scheme := runtime.NewScheme() - codecs := serializer.NewCodecFactory(scheme) - - AddToScheme(scheme) - - seed := rand.Int63() - fuzzerFuncs := fuzzer.MergeFuzzerFuncs(metafuzzer.Funcs, exampleFuzzerFuncs) - fuzzer := fuzzer.FuzzerFor(fuzzerFuncs, rand.NewSource(seed), codecs) - - roundtrip.RoundTripSpecificKindWithoutProtobuf(t, SchemeGroupVersion.WithKind("Example"), scheme, codecs, fuzzer, nil) - roundtrip.RoundTripSpecificKindWithoutProtobuf(t, SchemeGroupVersion.WithKind("ExampleList"), scheme, codecs, fuzzer, nil) -} diff --git a/apis/cr/v1/zz_generated.deepcopy.go b/apis/cr/v1/zz_generated.deepcopy.go deleted file mode 100644 index e9f2a4c..0000000 --- a/apis/cr/v1/zz_generated.deepcopy.go +++ /dev/null @@ -1,146 +0,0 @@ -// +build !ignore_autogenerated - -/* -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. -*/ - -// This file was autogenerated by deepcopy-gen. Do not edit it manually! - -package v1 - -import ( - conversion "k8s.io/apimachinery/pkg/conversion" - runtime "k8s.io/apimachinery/pkg/runtime" - reflect "reflect" -) - -// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them. -// -// Deprecated: deepcopy registration will go away when static deepcopy is fully implemented. -func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc { - return []conversion.GeneratedDeepCopyFunc{ - {Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error { - in.(*Example).DeepCopyInto(out.(*Example)) - return nil - }, InType: reflect.TypeOf(&Example{})}, - {Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error { - in.(*ExampleList).DeepCopyInto(out.(*ExampleList)) - return nil - }, InType: reflect.TypeOf(&ExampleList{})}, - {Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error { - in.(*ExampleSpec).DeepCopyInto(out.(*ExampleSpec)) - return nil - }, InType: reflect.TypeOf(&ExampleSpec{})}, - {Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error { - in.(*ExampleStatus).DeepCopyInto(out.(*ExampleStatus)) - return nil - }, InType: reflect.TypeOf(&ExampleStatus{})}, - } -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Example) DeepCopyInto(out *Example) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec - out.Status = in.Status - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Example. -func (in *Example) DeepCopy() *Example { - if in == nil { - return nil - } - out := new(Example) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Example) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } else { - return nil - } -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ExampleList) DeepCopyInto(out *ExampleList) { - *out = *in - out.TypeMeta = in.TypeMeta - out.ListMeta = in.ListMeta - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Example, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExampleList. -func (in *ExampleList) DeepCopy() *ExampleList { - if in == nil { - return nil - } - out := new(ExampleList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *ExampleList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } else { - return nil - } -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ExampleSpec) DeepCopyInto(out *ExampleSpec) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExampleSpec. -func (in *ExampleSpec) DeepCopy() *ExampleSpec { - if in == nil { - return nil - } - out := new(ExampleSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ExampleStatus) DeepCopyInto(out *ExampleStatus) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExampleStatus. -func (in *ExampleStatus) DeepCopy() *ExampleStatus { - if in == nil { - return nil - } - out := new(ExampleStatus) - in.DeepCopyInto(out) - return out -} diff --git a/apis/test.io/register.go b/apis/test.io/register.go new file mode 100644 index 0000000..b2f6eac --- /dev/null +++ b/apis/test.io/register.go @@ -0,0 +1,5 @@ +package testio + +const ( + GroupName = "test.io" +) diff --git a/apis/cr/v1/doc.go b/apis/test.io/v1/doc.go similarity index 100% rename from apis/cr/v1/doc.go rename to apis/test.io/v1/doc.go diff --git a/apis/cr/v1/types.go b/apis/test.io/v1/types.go similarity index 95% rename from apis/cr/v1/types.go rename to apis/test.io/v1/types.go index cde811c..d07fe6d 100644 --- a/apis/cr/v1/types.go +++ b/apis/test.io/v1/types.go @@ -4,7 +4,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -const ExampleResourcePlural = "examples" +const ExampleResourcePlural = "tests" // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object type Example struct { diff --git a/client/clientset/versioned/clientset.go b/client/clientset/versioned/clientset.go deleted file mode 100644 index be7e96a..0000000 --- a/client/clientset/versioned/clientset.go +++ /dev/null @@ -1,98 +0,0 @@ -/* -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 versioned - -import ( - glog "github.com/golang/glog" - crv1 "github.com/jinghzhu/k8scrd/client/clientset/versioned/typed/cr/v1" - discovery "k8s.io/client-go/discovery" - rest "k8s.io/client-go/rest" - flowcontrol "k8s.io/client-go/util/flowcontrol" -) - -type Interface interface { - Discovery() discovery.DiscoveryInterface - CrV1() crv1.CrV1Interface - // Deprecated: please explicitly pick a version if possible. - Cr() crv1.CrV1Interface -} - -// Clientset contains the clients for groups. Each group has exactly one -// version included in a Clientset. -type Clientset struct { - *discovery.DiscoveryClient - crV1 *crv1.CrV1Client -} - -// CrV1 retrieves the CrV1Client -func (c *Clientset) CrV1() crv1.CrV1Interface { - return c.crV1 -} - -// Deprecated: Cr retrieves the default version of CrClient. -// Please explicitly pick a version. -func (c *Clientset) Cr() crv1.CrV1Interface { - return c.crV1 -} - -// Discovery retrieves the DiscoveryClient -func (c *Clientset) Discovery() discovery.DiscoveryInterface { - if c == nil { - return nil - } - return c.DiscoveryClient -} - -// NewForConfig creates a new Clientset for the given config. -func NewForConfig(c *rest.Config) (*Clientset, error) { - configShallowCopy := *c - if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { - configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) - } - var cs Clientset - var err error - cs.crV1, err = crv1.NewForConfig(&configShallowCopy) - if err != nil { - return nil, err - } - - cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(&configShallowCopy) - if err != nil { - glog.Errorf("failed to create the DiscoveryClient: %v", err) - return nil, err - } - return &cs, nil -} - -// NewForConfigOrDie creates a new Clientset for the given config and -// panics if there is an error in the config. -func NewForConfigOrDie(c *rest.Config) *Clientset { - var cs Clientset - cs.crV1 = crv1.NewForConfigOrDie(c) - - cs.DiscoveryClient = discovery.NewDiscoveryClientForConfigOrDie(c) - return &cs -} - -// New creates a new Clientset for the given RESTClient. -func New(c rest.Interface) *Clientset { - var cs Clientset - cs.crV1 = crv1.New(c) - - cs.DiscoveryClient = discovery.NewDiscoveryClient(c) - return &cs -} diff --git a/client/clientset/versioned/doc.go b/client/clientset/versioned/doc.go deleted file mode 100644 index 8fd89c6..0000000 --- a/client/clientset/versioned/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -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. -*/ - -// This package is generated by client-gen with custom arguments. - -// This package has the automatically generated clientset. -package versioned diff --git a/client/clientset/versioned/fake/clientset_generated.go b/client/clientset/versioned/fake/clientset_generated.go deleted file mode 100644 index b10e2a0..0000000 --- a/client/clientset/versioned/fake/clientset_generated.go +++ /dev/null @@ -1,71 +0,0 @@ -/* -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 fake - -import ( - clientset "github.com/jinghzhu/k8scrd/client/clientset/versioned" - crv1 "github.com/jinghzhu/k8scrd/client/clientset/versioned/typed/cr/v1" - fakecrv1 "github.com/jinghzhu/k8scrd/client/clientset/versioned/typed/cr/v1/fake" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/discovery" - fakediscovery "k8s.io/client-go/discovery/fake" - "k8s.io/client-go/testing" -) - -// NewSimpleClientset returns a clientset that will respond with the provided objects. -// It's backed by a very simple object tracker that processes creates, updates and deletions as-is, -// without applying any validations and/or defaults. It shouldn't be considered a replacement -// for a real clientset and is mostly useful in simple unit tests. -func NewSimpleClientset(objects ...runtime.Object) *Clientset { - o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) - for _, obj := range objects { - if err := o.Add(obj); err != nil { - panic(err) - } - } - - fakePtr := testing.Fake{} - fakePtr.AddReactor("*", "*", testing.ObjectReaction(o)) - fakePtr.AddWatchReactor("*", testing.DefaultWatchReactor(watch.NewFake(), nil)) - - return &Clientset{fakePtr, &fakediscovery.FakeDiscovery{Fake: &fakePtr}} -} - -// Clientset implements clientset.Interface. Meant to be embedded into a -// struct to get a default implementation. This makes faking out just the method -// you want to test easier. -type Clientset struct { - testing.Fake - discovery *fakediscovery.FakeDiscovery -} - -func (c *Clientset) Discovery() discovery.DiscoveryInterface { - return c.discovery -} - -var _ clientset.Interface = &Clientset{} - -// CrV1 retrieves the CrV1Client -func (c *Clientset) CrV1() crv1.CrV1Interface { - return &fakecrv1.FakeCrV1{Fake: &c.Fake} -} - -// Cr retrieves the CrV1Client -func (c *Clientset) Cr() crv1.CrV1Interface { - return &fakecrv1.FakeCrV1{Fake: &c.Fake} -} diff --git a/client/clientset/versioned/fake/doc.go b/client/clientset/versioned/fake/doc.go deleted file mode 100644 index 5f565b3..0000000 --- a/client/clientset/versioned/fake/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -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. -*/ - -// This package is generated by client-gen with custom arguments. - -// This package has the automatically generated fake clientset. -package fake diff --git a/client/clientset/versioned/fake/register.go b/client/clientset/versioned/fake/register.go deleted file mode 100644 index 35a254b..0000000 --- a/client/clientset/versioned/fake/register.go +++ /dev/null @@ -1,53 +0,0 @@ -/* -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 fake - -import ( - crv1 "github.com/jinghzhu/k8scrd/apis/cr/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - schema "k8s.io/apimachinery/pkg/runtime/schema" - serializer "k8s.io/apimachinery/pkg/runtime/serializer" -) - -var scheme = runtime.NewScheme() -var codecs = serializer.NewCodecFactory(scheme) -var parameterCodec = runtime.NewParameterCodec(scheme) - -func init() { - v1.AddToGroupVersion(scheme, schema.GroupVersion{Version: "v1"}) - AddToScheme(scheme) -} - -// AddToScheme adds all types of this clientset into the given scheme. This allows composition -// of clientsets, like in: -// -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kuberentes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) -// -// kclientset, _ := kubernetes.NewForConfig(c) -// aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) -// -// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types -// correctly. -func AddToScheme(scheme *runtime.Scheme) { - crv1.AddToScheme(scheme) - -} diff --git a/client/clientset/versioned/scheme/doc.go b/client/clientset/versioned/scheme/doc.go deleted file mode 100644 index 5d8ec82..0000000 --- a/client/clientset/versioned/scheme/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -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. -*/ - -// This package is generated by client-gen with custom arguments. - -// This package contains the scheme of the automatically generated clientset. -package scheme diff --git a/client/clientset/versioned/scheme/register.go b/client/clientset/versioned/scheme/register.go deleted file mode 100644 index ca28b67..0000000 --- a/client/clientset/versioned/scheme/register.go +++ /dev/null @@ -1,53 +0,0 @@ -/* -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 scheme - -import ( - crv1 "github.com/jinghzhu/k8scrd/apis/cr/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - schema "k8s.io/apimachinery/pkg/runtime/schema" - serializer "k8s.io/apimachinery/pkg/runtime/serializer" -) - -var Scheme = runtime.NewScheme() -var Codecs = serializer.NewCodecFactory(Scheme) -var ParameterCodec = runtime.NewParameterCodec(Scheme) - -func init() { - v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) - AddToScheme(Scheme) -} - -// AddToScheme adds all types of this clientset into the given scheme. This allows composition -// of clientsets, like in: -// -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kuberentes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) -// -// kclientset, _ := kubernetes.NewForConfig(c) -// aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) -// -// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types -// correctly. -func AddToScheme(scheme *runtime.Scheme) { - crv1.AddToScheme(scheme) - -} diff --git a/client/clientset/versioned/typed/cr/v1/cr_client.go b/client/clientset/versioned/typed/cr/v1/cr_client.go deleted file mode 100644 index cc9b316..0000000 --- a/client/clientset/versioned/typed/cr/v1/cr_client.go +++ /dev/null @@ -1,21 +0,0 @@ -/* -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 v1 - -import ( - "github.com/jinghzhu/k8scrd/client/clientset/versioned/scheme" -) diff --git a/client/clientset/versioned/typed/cr/v1/doc.go b/client/clientset/versioned/typed/cr/v1/doc.go deleted file mode 100644 index 54673bf..0000000 --- a/client/clientset/versioned/typed/cr/v1/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -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. -*/ - -// This package is generated by client-gen with custom arguments. - -// This package has the automatically generated typed clients. -package v1 diff --git a/client/clientset/versioned/typed/cr/v1/fake/doc.go b/client/clientset/versioned/typed/cr/v1/fake/doc.go deleted file mode 100644 index c654833..0000000 --- a/client/clientset/versioned/typed/cr/v1/fake/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -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. -*/ - -// This package is generated by client-gen with custom arguments. - -// Package fake has the automatically generated clients. -package fake diff --git a/client/clientset/versioned/typed/cr/v1/fake/fake_cr_client.go b/client/clientset/versioned/typed/cr/v1/fake/fake_cr_client.go deleted file mode 100644 index 16aa379..0000000 --- a/client/clientset/versioned/typed/cr/v1/fake/fake_cr_client.go +++ /dev/null @@ -1,21 +0,0 @@ -/* -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 fake - -import ( - v1 "github.com/jinghzhu/k8scrd/client/clientset/versioned/typed/cr/v1" -) diff --git a/client/clientset/versioned/typed/cr/v1/generated_expansion.go b/client/clientset/versioned/typed/cr/v1/generated_expansion.go deleted file mode 100644 index 42e76d5..0000000 --- a/client/clientset/versioned/typed/cr/v1/generated_expansion.go +++ /dev/null @@ -1,17 +0,0 @@ -/* -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 v1 From d0c60b1c996793d98b9d42c81f9451f3b6192e39 Mon Sep 17 00:00:00 2001 From: Jinghua ZHU Date: Tue, 12 Dec 2017 20:05:14 +0800 Subject: [PATCH 4/6] Renmae test.io as test --- apis/{test.io => test}/register.go | 0 apis/{test.io => test}/v1/doc.go | 0 apis/{test.io => test}/v1/types.go | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename apis/{test.io => test}/register.go (100%) rename apis/{test.io => test}/v1/doc.go (100%) rename apis/{test.io => test}/v1/types.go (100%) diff --git a/apis/test.io/register.go b/apis/test/register.go similarity index 100% rename from apis/test.io/register.go rename to apis/test/register.go diff --git a/apis/test.io/v1/doc.go b/apis/test/v1/doc.go similarity index 100% rename from apis/test.io/v1/doc.go rename to apis/test/v1/doc.go diff --git a/apis/test.io/v1/types.go b/apis/test/v1/types.go similarity index 100% rename from apis/test.io/v1/types.go rename to apis/test/v1/types.go From b83559597e3f13cc5ac3af76ccf86a49c39d1c64 Mon Sep 17 00:00:00 2001 From: Jinghua Zhu Date: Tue, 12 Dec 2017 12:07:05 +0000 Subject: [PATCH 5/6] generate-groups --- apis/test/v1/zz_generated.deepcopy.go | 146 ++++++++++++++++++ client/clientset/versioned/clientset.go | 98 ++++++++++++ client/clientset/versioned/doc.go | 20 +++ .../versioned/fake/clientset_generated.go | 71 +++++++++ client/clientset/versioned/fake/doc.go | 20 +++ client/clientset/versioned/fake/register.go | 53 +++++++ client/clientset/versioned/scheme/doc.go | 20 +++ client/clientset/versioned/scheme/register.go | 53 +++++++ .../clientset/versioned/typed/test/v1/doc.go | 20 +++ .../versioned/typed/test/v1/fake/doc.go | 20 +++ .../typed/test/v1/fake/fake_test_client.go | 21 +++ .../typed/test/v1/generated_expansion.go | 17 ++ .../versioned/typed/test/v1/test_client.go | 21 +++ 13 files changed, 580 insertions(+) create mode 100644 apis/test/v1/zz_generated.deepcopy.go create mode 100644 client/clientset/versioned/clientset.go create mode 100644 client/clientset/versioned/doc.go create mode 100644 client/clientset/versioned/fake/clientset_generated.go create mode 100644 client/clientset/versioned/fake/doc.go create mode 100644 client/clientset/versioned/fake/register.go create mode 100644 client/clientset/versioned/scheme/doc.go create mode 100644 client/clientset/versioned/scheme/register.go create mode 100644 client/clientset/versioned/typed/test/v1/doc.go create mode 100644 client/clientset/versioned/typed/test/v1/fake/doc.go create mode 100644 client/clientset/versioned/typed/test/v1/fake/fake_test_client.go create mode 100644 client/clientset/versioned/typed/test/v1/generated_expansion.go create mode 100644 client/clientset/versioned/typed/test/v1/test_client.go diff --git a/apis/test/v1/zz_generated.deepcopy.go b/apis/test/v1/zz_generated.deepcopy.go new file mode 100644 index 0000000..e9f2a4c --- /dev/null +++ b/apis/test/v1/zz_generated.deepcopy.go @@ -0,0 +1,146 @@ +// +build !ignore_autogenerated + +/* +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. +*/ + +// This file was autogenerated by deepcopy-gen. Do not edit it manually! + +package v1 + +import ( + conversion "k8s.io/apimachinery/pkg/conversion" + runtime "k8s.io/apimachinery/pkg/runtime" + reflect "reflect" +) + +// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them. +// +// Deprecated: deepcopy registration will go away when static deepcopy is fully implemented. +func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc { + return []conversion.GeneratedDeepCopyFunc{ + {Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error { + in.(*Example).DeepCopyInto(out.(*Example)) + return nil + }, InType: reflect.TypeOf(&Example{})}, + {Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error { + in.(*ExampleList).DeepCopyInto(out.(*ExampleList)) + return nil + }, InType: reflect.TypeOf(&ExampleList{})}, + {Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error { + in.(*ExampleSpec).DeepCopyInto(out.(*ExampleSpec)) + return nil + }, InType: reflect.TypeOf(&ExampleSpec{})}, + {Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error { + in.(*ExampleStatus).DeepCopyInto(out.(*ExampleStatus)) + return nil + }, InType: reflect.TypeOf(&ExampleStatus{})}, + } +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Example) DeepCopyInto(out *Example) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec + out.Status = in.Status + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Example. +func (in *Example) DeepCopy() *Example { + if in == nil { + return nil + } + out := new(Example) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Example) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } else { + return nil + } +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ExampleList) DeepCopyInto(out *ExampleList) { + *out = *in + out.TypeMeta = in.TypeMeta + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Example, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExampleList. +func (in *ExampleList) DeepCopy() *ExampleList { + if in == nil { + return nil + } + out := new(ExampleList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ExampleList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } else { + return nil + } +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ExampleSpec) DeepCopyInto(out *ExampleSpec) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExampleSpec. +func (in *ExampleSpec) DeepCopy() *ExampleSpec { + if in == nil { + return nil + } + out := new(ExampleSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ExampleStatus) DeepCopyInto(out *ExampleStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExampleStatus. +func (in *ExampleStatus) DeepCopy() *ExampleStatus { + if in == nil { + return nil + } + out := new(ExampleStatus) + in.DeepCopyInto(out) + return out +} diff --git a/client/clientset/versioned/clientset.go b/client/clientset/versioned/clientset.go new file mode 100644 index 0000000..4c1131b --- /dev/null +++ b/client/clientset/versioned/clientset.go @@ -0,0 +1,98 @@ +/* +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 versioned + +import ( + glog "github.com/golang/glog" + testv1 "github.com/jinghzhu/k8scrd/client/clientset/versioned/typed/test/v1" + discovery "k8s.io/client-go/discovery" + rest "k8s.io/client-go/rest" + flowcontrol "k8s.io/client-go/util/flowcontrol" +) + +type Interface interface { + Discovery() discovery.DiscoveryInterface + TestV1() testv1.TestV1Interface + // Deprecated: please explicitly pick a version if possible. + Test() testv1.TestV1Interface +} + +// Clientset contains the clients for groups. Each group has exactly one +// version included in a Clientset. +type Clientset struct { + *discovery.DiscoveryClient + testV1 *testv1.TestV1Client +} + +// TestV1 retrieves the TestV1Client +func (c *Clientset) TestV1() testv1.TestV1Interface { + return c.testV1 +} + +// Deprecated: Test retrieves the default version of TestClient. +// Please explicitly pick a version. +func (c *Clientset) Test() testv1.TestV1Interface { + return c.testV1 +} + +// Discovery retrieves the DiscoveryClient +func (c *Clientset) Discovery() discovery.DiscoveryInterface { + if c == nil { + return nil + } + return c.DiscoveryClient +} + +// NewForConfig creates a new Clientset for the given config. +func NewForConfig(c *rest.Config) (*Clientset, error) { + configShallowCopy := *c + if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { + configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) + } + var cs Clientset + var err error + cs.testV1, err = testv1.NewForConfig(&configShallowCopy) + if err != nil { + return nil, err + } + + cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(&configShallowCopy) + if err != nil { + glog.Errorf("failed to create the DiscoveryClient: %v", err) + return nil, err + } + return &cs, nil +} + +// NewForConfigOrDie creates a new Clientset for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *Clientset { + var cs Clientset + cs.testV1 = testv1.NewForConfigOrDie(c) + + cs.DiscoveryClient = discovery.NewDiscoveryClientForConfigOrDie(c) + return &cs +} + +// New creates a new Clientset for the given RESTClient. +func New(c rest.Interface) *Clientset { + var cs Clientset + cs.testV1 = testv1.New(c) + + cs.DiscoveryClient = discovery.NewDiscoveryClient(c) + return &cs +} diff --git a/client/clientset/versioned/doc.go b/client/clientset/versioned/doc.go new file mode 100644 index 0000000..8fd89c6 --- /dev/null +++ b/client/clientset/versioned/doc.go @@ -0,0 +1,20 @@ +/* +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. +*/ + +// This package is generated by client-gen with custom arguments. + +// This package has the automatically generated clientset. +package versioned diff --git a/client/clientset/versioned/fake/clientset_generated.go b/client/clientset/versioned/fake/clientset_generated.go new file mode 100644 index 0000000..8f5abff --- /dev/null +++ b/client/clientset/versioned/fake/clientset_generated.go @@ -0,0 +1,71 @@ +/* +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 fake + +import ( + clientset "github.com/jinghzhu/k8scrd/client/clientset/versioned" + testv1 "github.com/jinghzhu/k8scrd/client/clientset/versioned/typed/test/v1" + faketestv1 "github.com/jinghzhu/k8scrd/client/clientset/versioned/typed/test/v1/fake" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/discovery" + fakediscovery "k8s.io/client-go/discovery/fake" + "k8s.io/client-go/testing" +) + +// NewSimpleClientset returns a clientset that will respond with the provided objects. +// It's backed by a very simple object tracker that processes creates, updates and deletions as-is, +// without applying any validations and/or defaults. It shouldn't be considered a replacement +// for a real clientset and is mostly useful in simple unit tests. +func NewSimpleClientset(objects ...runtime.Object) *Clientset { + o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) + for _, obj := range objects { + if err := o.Add(obj); err != nil { + panic(err) + } + } + + fakePtr := testing.Fake{} + fakePtr.AddReactor("*", "*", testing.ObjectReaction(o)) + fakePtr.AddWatchReactor("*", testing.DefaultWatchReactor(watch.NewFake(), nil)) + + return &Clientset{fakePtr, &fakediscovery.FakeDiscovery{Fake: &fakePtr}} +} + +// Clientset implements clientset.Interface. Meant to be embedded into a +// struct to get a default implementation. This makes faking out just the method +// you want to test easier. +type Clientset struct { + testing.Fake + discovery *fakediscovery.FakeDiscovery +} + +func (c *Clientset) Discovery() discovery.DiscoveryInterface { + return c.discovery +} + +var _ clientset.Interface = &Clientset{} + +// TestV1 retrieves the TestV1Client +func (c *Clientset) TestV1() testv1.TestV1Interface { + return &faketestv1.FakeTestV1{Fake: &c.Fake} +} + +// Test retrieves the TestV1Client +func (c *Clientset) Test() testv1.TestV1Interface { + return &faketestv1.FakeTestV1{Fake: &c.Fake} +} diff --git a/client/clientset/versioned/fake/doc.go b/client/clientset/versioned/fake/doc.go new file mode 100644 index 0000000..5f565b3 --- /dev/null +++ b/client/clientset/versioned/fake/doc.go @@ -0,0 +1,20 @@ +/* +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. +*/ + +// This package is generated by client-gen with custom arguments. + +// This package has the automatically generated fake clientset. +package fake diff --git a/client/clientset/versioned/fake/register.go b/client/clientset/versioned/fake/register.go new file mode 100644 index 0000000..b530849 --- /dev/null +++ b/client/clientset/versioned/fake/register.go @@ -0,0 +1,53 @@ +/* +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 fake + +import ( + testv1 "github.com/jinghzhu/k8scrd/apis/test/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" +) + +var scheme = runtime.NewScheme() +var codecs = serializer.NewCodecFactory(scheme) +var parameterCodec = runtime.NewParameterCodec(scheme) + +func init() { + v1.AddToGroupVersion(scheme, schema.GroupVersion{Version: "v1"}) + AddToScheme(scheme) +} + +// AddToScheme adds all types of this clientset into the given scheme. This allows composition +// of clientsets, like in: +// +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kuberentes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) +// +// kclientset, _ := kubernetes.NewForConfig(c) +// aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// +// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types +// correctly. +func AddToScheme(scheme *runtime.Scheme) { + testv1.AddToScheme(scheme) + +} diff --git a/client/clientset/versioned/scheme/doc.go b/client/clientset/versioned/scheme/doc.go new file mode 100644 index 0000000..5d8ec82 --- /dev/null +++ b/client/clientset/versioned/scheme/doc.go @@ -0,0 +1,20 @@ +/* +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. +*/ + +// This package is generated by client-gen with custom arguments. + +// This package contains the scheme of the automatically generated clientset. +package scheme diff --git a/client/clientset/versioned/scheme/register.go b/client/clientset/versioned/scheme/register.go new file mode 100644 index 0000000..440cc87 --- /dev/null +++ b/client/clientset/versioned/scheme/register.go @@ -0,0 +1,53 @@ +/* +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 scheme + +import ( + testv1 "github.com/jinghzhu/k8scrd/apis/test/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" +) + +var Scheme = runtime.NewScheme() +var Codecs = serializer.NewCodecFactory(Scheme) +var ParameterCodec = runtime.NewParameterCodec(Scheme) + +func init() { + v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) + AddToScheme(Scheme) +} + +// AddToScheme adds all types of this clientset into the given scheme. This allows composition +// of clientsets, like in: +// +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kuberentes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) +// +// kclientset, _ := kubernetes.NewForConfig(c) +// aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// +// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types +// correctly. +func AddToScheme(scheme *runtime.Scheme) { + testv1.AddToScheme(scheme) + +} diff --git a/client/clientset/versioned/typed/test/v1/doc.go b/client/clientset/versioned/typed/test/v1/doc.go new file mode 100644 index 0000000..54673bf --- /dev/null +++ b/client/clientset/versioned/typed/test/v1/doc.go @@ -0,0 +1,20 @@ +/* +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. +*/ + +// This package is generated by client-gen with custom arguments. + +// This package has the automatically generated typed clients. +package v1 diff --git a/client/clientset/versioned/typed/test/v1/fake/doc.go b/client/clientset/versioned/typed/test/v1/fake/doc.go new file mode 100644 index 0000000..c654833 --- /dev/null +++ b/client/clientset/versioned/typed/test/v1/fake/doc.go @@ -0,0 +1,20 @@ +/* +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. +*/ + +// This package is generated by client-gen with custom arguments. + +// Package fake has the automatically generated clients. +package fake diff --git a/client/clientset/versioned/typed/test/v1/fake/fake_test_client.go b/client/clientset/versioned/typed/test/v1/fake/fake_test_client.go new file mode 100644 index 0000000..fe843bc --- /dev/null +++ b/client/clientset/versioned/typed/test/v1/fake/fake_test_client.go @@ -0,0 +1,21 @@ +/* +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 fake + +import ( + v1 "github.com/jinghzhu/k8scrd/client/clientset/versioned/typed/test/v1" +) diff --git a/client/clientset/versioned/typed/test/v1/generated_expansion.go b/client/clientset/versioned/typed/test/v1/generated_expansion.go new file mode 100644 index 0000000..42e76d5 --- /dev/null +++ b/client/clientset/versioned/typed/test/v1/generated_expansion.go @@ -0,0 +1,17 @@ +/* +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 v1 diff --git a/client/clientset/versioned/typed/test/v1/test_client.go b/client/clientset/versioned/typed/test/v1/test_client.go new file mode 100644 index 0000000..cc9b316 --- /dev/null +++ b/client/clientset/versioned/typed/test/v1/test_client.go @@ -0,0 +1,21 @@ +/* +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 v1 + +import ( + "github.com/jinghzhu/k8scrd/client/clientset/versioned/scheme" +) From 00edbf6261d6e905c7291f51f0784aa3eb49f066 Mon Sep 17 00:00:00 2001 From: Jinghua ZHU Date: Tue, 12 Dec 2017 20:10:23 +0800 Subject: [PATCH 6/6] Save --- apis/test/register.go | 5 ---- apis/test/v1/register.go | 49 ++++++++++++++++++++++++++++++++++++++++ client/client.go | 2 +- client/cr.go | 2 +- controller/controller.go | 2 +- main.go | 2 +- 6 files changed, 53 insertions(+), 9 deletions(-) delete mode 100644 apis/test/register.go create mode 100644 apis/test/v1/register.go diff --git a/apis/test/register.go b/apis/test/register.go deleted file mode 100644 index b2f6eac..0000000 --- a/apis/test/register.go +++ /dev/null @@ -1,5 +0,0 @@ -package testio - -const ( - GroupName = "test.io" -) diff --git a/apis/test/v1/register.go b/apis/test/v1/register.go new file mode 100644 index 0000000..be0217c --- /dev/null +++ b/apis/test/v1/register.go @@ -0,0 +1,49 @@ +/* +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 v1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +var ( + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + AddToScheme = SchemeBuilder.AddToScheme +) + +// GroupName is the group name used in this package. +const GroupName = "cr.test.io" + +// SchemeGroupVersion is the group version used to register these objects. +var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"} + +// Resource takes an unqualified resource and returns a Group-qualified GroupResource. +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +// addKnownTypes adds the set of types defined in this package to the supplied scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &Example{}, + &ExampleList{}, + ) + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/client/client.go b/client/client.go index efbdfc1..7dac88c 100644 --- a/client/client.go +++ b/client/client.go @@ -21,7 +21,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/serializer" "k8s.io/client-go/rest" - crv1 "github.com/jinghzhu/k8scrd/apis/cr/v1" + crv1 "github.com/jinghzhu/k8scrd/apis/test/v1" ) func NewClient(cfg *rest.Config) (*rest.RESTClient, *runtime.Scheme, error) { diff --git a/client/cr.go b/client/cr.go index 66513b5..c163789 100644 --- a/client/cr.go +++ b/client/cr.go @@ -21,8 +21,8 @@ import ( "reflect" "time" + crv1 "github.com/jinghzhu/k8scrd/apis/test/v1" apiv1 "k8s.io/api/core/v1" - crv1 "k8s.io/apiextensions-apiserver/examples/client-go/apis/cr/v1" apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/controller/controller.go b/controller/controller.go index b71a4e1..069fce5 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -26,7 +26,7 @@ import ( "k8s.io/client-go/rest" "k8s.io/client-go/tools/cache" - crv1 "github.com/jinghzhu/k8scrd/apis/cr/v1" + crv1 "github.com/jinghzhu/k8scrd/apis/test/v1" ) // Watcher is an example of watching on resource create/update/delete events diff --git a/main.go b/main.go index c3fbfc8..0a42999 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,7 @@ import ( // Uncomment the following line to load the gcp plugin (only required to authenticate against GKE clusters). // _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" - crv1 "github.com/jinghzhu/k8scrd/apis/cr/v1" + crv1 "github.com/jinghzhu/k8scrd/apis/test/v1" exampleclient "github.com/jinghzhu/k8scrd/client" examplecontroller "github.com/jinghzhu/k8scrd/controller" )