diff --git a/samples/full/controller/src/samplecontroller/cmd/controller-manager/main.go b/samples/full/controller/src/samplecontroller/cmd/controller-manager/main.go new file mode 100644 index 00000000000..37bdb2dba4a --- /dev/null +++ b/samples/full/controller/src/samplecontroller/cmd/controller-manager/main.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 main + +import ( + "flag" + "log" + + // Import auth/gcp to connect to GKE clusters remotely + _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" + + configlib "github.com/kubernetes-sigs/kubebuilder/pkg/config" + "github.com/kubernetes-sigs/kubebuilder/pkg/inject/run" + "github.com/kubernetes-sigs/kubebuilder/pkg/install" + "github.com/kubernetes-sigs/kubebuilder/pkg/signals" + extensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" + + "samplecontroller/pkg/inject" + "samplecontroller/pkg/inject/args" +) + +var installCRDs = flag.Bool("install-crds", true, "install the CRDs used by the controller as part of startup") + +// Controller-manager main. +func main() { + flag.Parse() + + stopCh := signals.SetupSignalHandler() + + config := configlib.GetConfigOrDie() + + if *installCRDs { + if err := install.NewInstaller(config).Install(&InstallStrategy{crds: inject.Injector.CRDs}); err != nil { + log.Fatalf("Could not create CRDs: %v", err) + } + } + + // Start the controllers + if err := inject.RunAll(run.RunArguments{Stop: stopCh}, args.CreateInjectArgs(config)); err != nil { + log.Fatalf("%v", err) + } +} + +type InstallStrategy struct { + install.EmptyInstallStrategy + crds []*extensionsv1beta1.CustomResourceDefinition +} + +func (s *InstallStrategy) GetCRDs() []*extensionsv1beta1.CustomResourceDefinition { + return s.crds +} diff --git a/samples/full/controller/src/samplecontroller/pkg/apis/doc.go b/samples/full/controller/src/samplecontroller/pkg/apis/doc.go new file mode 100644 index 00000000000..91ac5053e1f --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/apis/doc.go @@ -0,0 +1,23 @@ + +/* +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. +*/ + + +// +// +domain=k8s.io + +package apis + diff --git a/samples/full/controller/src/samplecontroller/pkg/apis/samplecontroller/doc.go b/samples/full/controller/src/samplecontroller/pkg/apis/samplecontroller/doc.go new file mode 100644 index 00000000000..6a289236226 --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/apis/samplecontroller/doc.go @@ -0,0 +1,24 @@ + +/* +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. +*/ + + + +// +k8s:deepcopy-gen=package,register +// +groupName=samplecontroller.k8s.io + +// Package api is the internal version of the API. +package samplecontroller diff --git a/samples/full/controller/src/samplecontroller/pkg/apis/samplecontroller/v1alpha1/doc.go b/samples/full/controller/src/samplecontroller/pkg/apis/samplecontroller/v1alpha1/doc.go new file mode 100644 index 00000000000..eaeba9eb140 --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/apis/samplecontroller/v1alpha1/doc.go @@ -0,0 +1,28 @@ + +/* +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. +*/ + + +// Api versions allow the api contract for a resource to be changed while keeping +// backward compatibility by support multiple concurrent versions +// of the same resource + +// +k8s:openapi-gen=true +// +k8s:deepcopy-gen=package,register +// +k8s:conversion-gen=samplecontroller/pkg/apis/samplecontroller +// +k8s:defaulter-gen=TypeMeta +// +groupName=samplecontroller.k8s.io +package v1alpha1 // import "samplecontroller/pkg/apis/samplecontroller/v1alpha1" diff --git a/samples/full/controller/src/samplecontroller/pkg/apis/samplecontroller/v1alpha1/foo_types.go b/samples/full/controller/src/samplecontroller/pkg/apis/samplecontroller/v1alpha1/foo_types.go new file mode 100644 index 00000000000..4dc60f11934 --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/apis/samplecontroller/v1alpha1/foo_types.go @@ -0,0 +1,52 @@ + +/* +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 v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// EDIT THIS FILE! +// Created by "kubebuilder create resource" for you to implement the Foo resource schema definition +// as a go struct. +// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. + +// FooSpec defines the desired state of Foo +type FooSpec struct { + // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster +} + +// FooStatus defines the observed state of Foo +type FooStatus struct { + // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster +} + +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// Foo +// +k8s:openapi-gen=true +// +resource:path=foos +type Foo struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec FooSpec `json:"spec,omitempty"` + Status FooStatus `json:"status,omitempty"` +} diff --git a/samples/full/controller/src/samplecontroller/pkg/apis/samplecontroller/v1alpha1/foo_types_test.go b/samples/full/controller/src/samplecontroller/pkg/apis/samplecontroller/v1alpha1/foo_types_test.go new file mode 100644 index 00000000000..2da7d3a898b --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/apis/samplecontroller/v1alpha1/foo_types_test.go @@ -0,0 +1,85 @@ + +/* +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 v1alpha1_test + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + . "samplecontroller/pkg/apis/samplecontroller/v1alpha1" + . "samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1" +) + +// EDIT THIS FILE! +// Created by "kubebuilder create resource" for you to implement the Foo resource tests + +var _ = Describe("Foo", func() { + var instance Foo + var expected Foo + var client FooInterface + + BeforeEach(func() { + instance = Foo{} + instance.Name = "instance-1" + + expected = instance + }) + + AfterEach(func() { + client.Delete(instance.Name, &metav1.DeleteOptions{}) + }) + + // INSERT YOUR CODE HERE - add more "Describe" tests + + // Automatically created storage tests + Describe("when sending a storage request", func() { + Context("for a valid config", func() { + It("should provide CRUD access to the object", func() { + client = cs.SamplecontrollerV1alpha1().Foos("default") + + By("returning success from the create request") + actual, err := client.Create(&instance) + Expect(err).ShouldNot(HaveOccurred()) + + By("defaulting the expected fields") + Expect(actual.Spec).To(Equal(expected.Spec)) + + By("returning the item for list requests") + result, err := client.List(metav1.ListOptions{}) + Expect(err).ShouldNot(HaveOccurred()) + Expect(result.Items).To(HaveLen(1)) + Expect(result.Items[0].Spec).To(Equal(expected.Spec)) + + By("returning the item for get requests") + actual, err = client.Get(instance.Name, metav1.GetOptions{}) + Expect(err).ShouldNot(HaveOccurred()) + Expect(actual.Spec).To(Equal(expected.Spec)) + + By("deleting the item for delete requests") + err = client.Delete(instance.Name, &metav1.DeleteOptions{}) + Expect(err).ShouldNot(HaveOccurred()) + result, err = client.List(metav1.ListOptions{}) + Expect(err).ShouldNot(HaveOccurred()) + Expect(result.Items).To(HaveLen(0)) + }) + }) + }) +}) diff --git a/samples/full/controller/src/samplecontroller/pkg/apis/samplecontroller/v1alpha1/v1alpha1_suite_test.go b/samples/full/controller/src/samplecontroller/pkg/apis/samplecontroller/v1alpha1/v1alpha1_suite_test.go new file mode 100644 index 00000000000..af77d5b44bd --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/apis/samplecontroller/v1alpha1/v1alpha1_suite_test.go @@ -0,0 +1,54 @@ + +/* +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 v1alpha1_test + +import ( + "testing" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "github.com/kubernetes-sigs/kubebuilder/pkg/test" + "k8s.io/client-go/rest" + + "samplecontroller/pkg/inject" + "samplecontroller/pkg/client/clientset/versioned" +) + +var testenv *test.TestEnvironment +var config *rest.Config +var cs *versioned.Clientset + +func TestV1alpha1(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecsWithDefaultAndCustomReporters(t, "v1 Suite", []Reporter{test.NewlineReporter{}}) +} + +var _ = BeforeSuite(func() { + testenv = &test.TestEnvironment{CRDs: inject.Injector.CRDs} + + var err error + config, err = testenv.Start() + Expect(err).NotTo(HaveOccurred()) + + cs = versioned.NewForConfigOrDie(config) +}) + +var _ = AfterSuite(func() { + testenv.Stop() +}) diff --git a/samples/full/controller/src/samplecontroller/pkg/apis/samplecontroller/v1alpha1/zz_generated.deepcopy.go b/samples/full/controller/src/samplecontroller/pkg/apis/samplecontroller/v1alpha1/zz_generated.deepcopy.go new file mode 100644 index 00000000000..68b1991902c --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/apis/samplecontroller/v1alpha1/zz_generated.deepcopy.go @@ -0,0 +1,120 @@ +// +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 v1alpha1 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Foo) DeepCopyInto(out *Foo) { + *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 Foo. +func (in *Foo) DeepCopy() *Foo { + if in == nil { + return nil + } + out := new(Foo) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Foo) 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 *FooList) DeepCopyInto(out *FooList) { + *out = *in + out.TypeMeta = in.TypeMeta + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Foo, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FooList. +func (in *FooList) DeepCopy() *FooList { + if in == nil { + return nil + } + out := new(FooList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *FooList) 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 *FooSpec) DeepCopyInto(out *FooSpec) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FooSpec. +func (in *FooSpec) DeepCopy() *FooSpec { + if in == nil { + return nil + } + out := new(FooSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *FooStatus) DeepCopyInto(out *FooStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FooStatus. +func (in *FooStatus) DeepCopy() *FooStatus { + if in == nil { + return nil + } + out := new(FooStatus) + in.DeepCopyInto(out) + return out +} diff --git a/samples/full/controller/src/samplecontroller/pkg/apis/samplecontroller/v1alpha1/zz_generated.kubebuilder.go b/samples/full/controller/src/samplecontroller/pkg/apis/samplecontroller/v1alpha1/zz_generated.kubebuilder.go new file mode 100644 index 00000000000..7e3b388e45f --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/apis/samplecontroller/v1alpha1/zz_generated.kubebuilder.go @@ -0,0 +1,106 @@ +/* +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 v1alpha1 + +import ( + "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// SchemeGroupVersion is group version used to register these objects +var SchemeGroupVersion = schema.GroupVersion{Group: "samplecontroller.k8s.io", Version: "v1alpha1"} + +// Kind takes an unqualified kind and returns back a Group qualified GroupKind +func Kind(kind string) schema.GroupKind { + return SchemeGroupVersion.WithKind(kind).GroupKind() +} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + AddToScheme = SchemeBuilder.AddToScheme +) + +// Adds the list of known types to Scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &Foo{}, + &FooList{}, + ) + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +type FooList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []Foo `json:"items"` +} + +// CRD Generation +func getFloat(f float64) *float64 { + return &f +} + +var ( + // Define CRDs for resources + FooCRD = v1beta1.CustomResourceDefinition{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foos.samplecontroller.k8s.io", + }, + Spec: v1beta1.CustomResourceDefinitionSpec{ + Group: "samplecontroller.k8s.io", + Version: "v1alpha1", + Names: v1beta1.CustomResourceDefinitionNames{ + Kind: "Foo", + Plural: "foos", + }, + Scope: "Namespaced", + Validation: &v1beta1.CustomResourceValidation{ + OpenAPIV3Schema: &v1beta1.JSONSchemaProps{ + Type: "object", + Properties: map[string]v1beta1.JSONSchemaProps{ + "apiVersion": v1beta1.JSONSchemaProps{ + Type: "string", + }, + "kind": v1beta1.JSONSchemaProps{ + Type: "string", + }, + "metadata": v1beta1.JSONSchemaProps{ + Type: "object", + }, + "spec": v1beta1.JSONSchemaProps{ + Type: "object", + Properties: map[string]v1beta1.JSONSchemaProps{}, + }, + "status": v1beta1.JSONSchemaProps{ + Type: "object", + Properties: map[string]v1beta1.JSONSchemaProps{}, + }, + }, + }, + }, + }, + } +) diff --git a/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/clientset.go b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/clientset.go new file mode 100644 index 00000000000..f4e5cfd6e8b --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/clientset.go @@ -0,0 +1,97 @@ +/* +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" + discovery "k8s.io/client-go/discovery" + rest "k8s.io/client-go/rest" + flowcontrol "k8s.io/client-go/util/flowcontrol" + samplecontrollerv1alpha1 "samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1" +) + +type Interface interface { + Discovery() discovery.DiscoveryInterface + SamplecontrollerV1alpha1() samplecontrollerv1alpha1.SamplecontrollerV1alpha1Interface + // Deprecated: please explicitly pick a version if possible. + Samplecontroller() samplecontrollerv1alpha1.SamplecontrollerV1alpha1Interface +} + +// Clientset contains the clients for groups. Each group has exactly one +// version included in a Clientset. +type Clientset struct { + *discovery.DiscoveryClient + samplecontrollerV1alpha1 *samplecontrollerv1alpha1.SamplecontrollerV1alpha1Client +} + +// SamplecontrollerV1alpha1 retrieves the SamplecontrollerV1alpha1Client +func (c *Clientset) SamplecontrollerV1alpha1() samplecontrollerv1alpha1.SamplecontrollerV1alpha1Interface { + return c.samplecontrollerV1alpha1 +} + +// Deprecated: Samplecontroller retrieves the default version of SamplecontrollerClient. +// Please explicitly pick a version. +func (c *Clientset) Samplecontroller() samplecontrollerv1alpha1.SamplecontrollerV1alpha1Interface { + return c.samplecontrollerV1alpha1 +} + +// 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.samplecontrollerV1alpha1, err = samplecontrollerv1alpha1.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.samplecontrollerV1alpha1 = samplecontrollerv1alpha1.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.samplecontrollerV1alpha1 = samplecontrollerv1alpha1.New(c) + + cs.DiscoveryClient = discovery.NewDiscoveryClient(c) + return &cs +} diff --git a/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/doc.go b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/doc.go new file mode 100644 index 00000000000..2de0f88ca12 --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/doc.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. +*/ +// This package has the automatically generated clientset. +package versioned diff --git a/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/fake/clientset_generated.go b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/fake/clientset_generated.go new file mode 100644 index 00000000000..e80ffd3420b --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/fake/clientset_generated.go @@ -0,0 +1,70 @@ +/* +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 ( + "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" + clientset "samplecontroller/pkg/client/clientset/versioned" + samplecontrollerv1alpha1 "samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1" + fakesamplecontrollerv1alpha1 "samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1/fake" +) + +// 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{} + +// SamplecontrollerV1alpha1 retrieves the SamplecontrollerV1alpha1Client +func (c *Clientset) SamplecontrollerV1alpha1() samplecontrollerv1alpha1.SamplecontrollerV1alpha1Interface { + return &fakesamplecontrollerv1alpha1.FakeSamplecontrollerV1alpha1{Fake: &c.Fake} +} + +// Samplecontroller retrieves the SamplecontrollerV1alpha1Client +func (c *Clientset) Samplecontroller() samplecontrollerv1alpha1.SamplecontrollerV1alpha1Interface { + return &fakesamplecontrollerv1alpha1.FakeSamplecontrollerV1alpha1{Fake: &c.Fake} +} diff --git a/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/fake/doc.go b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/fake/doc.go new file mode 100644 index 00000000000..c9e1ce62e7b --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/fake/doc.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. +*/ +// This package has the automatically generated fake clientset. +package fake diff --git a/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/fake/register.go b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/fake/register.go new file mode 100644 index 00000000000..cb60fdc590e --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/fake/register.go @@ -0,0 +1,52 @@ +/* +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 "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" + samplecontrollerv1alpha1 "samplecontroller/pkg/apis/samplecontroller/v1alpha1" +) + +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) { + samplecontrollerv1alpha1.AddToScheme(scheme) + +} diff --git a/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/scheme/doc.go b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/scheme/doc.go new file mode 100644 index 00000000000..aa812db80ee --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/scheme/doc.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. +*/ +// This package contains the scheme of the automatically generated clientset. +package scheme diff --git a/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/scheme/register.go b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/scheme/register.go new file mode 100644 index 00000000000..baae89d40bf --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/scheme/register.go @@ -0,0 +1,52 @@ +/* +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 ( + 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" + samplecontrollerv1alpha1 "samplecontroller/pkg/apis/samplecontroller/v1alpha1" +) + +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) { + samplecontrollerv1alpha1.AddToScheme(scheme) + +} diff --git a/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1/doc.go b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1/doc.go new file mode 100644 index 00000000000..5343c14f50d --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1/doc.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. +*/ +// This package has the automatically generated typed clients. +package v1alpha1 diff --git a/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1/fake/doc.go b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1/fake/doc.go new file mode 100644 index 00000000000..24424a01c19 --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1/fake/doc.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 fake has the automatically generated clients. +package fake diff --git a/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1/fake/fake_foo.go b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1/fake/fake_foo.go new file mode 100644 index 00000000000..5fdd6e38ffa --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1/fake/fake_foo.go @@ -0,0 +1,137 @@ +/* +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 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" + v1alpha1 "samplecontroller/pkg/apis/samplecontroller/v1alpha1" +) + +// FakeFoos implements FooInterface +type FakeFoos struct { + Fake *FakeSamplecontrollerV1alpha1 + ns string +} + +var foosResource = schema.GroupVersionResource{Group: "samplecontroller.k8s.io", Version: "v1alpha1", Resource: "foos"} + +var foosKind = schema.GroupVersionKind{Group: "samplecontroller.k8s.io", Version: "v1alpha1", Kind: "Foo"} + +// Get takes name of the foo, and returns the corresponding foo object, and an error if there is any. +func (c *FakeFoos) Get(name string, options v1.GetOptions) (result *v1alpha1.Foo, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(foosResource, c.ns, name), &v1alpha1.Foo{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Foo), err +} + +// List takes label and field selectors, and returns the list of Foos that match those selectors. +func (c *FakeFoos) List(opts v1.ListOptions) (result *v1alpha1.FooList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(foosResource, foosKind, c.ns, opts), &v1alpha1.FooList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.FooList{} + for _, item := range obj.(*v1alpha1.FooList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested foos. +func (c *FakeFoos) Watch(opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(foosResource, c.ns, opts)) + +} + +// Create takes the representation of a foo and creates it. Returns the server's representation of the foo, and an error, if there is any. +func (c *FakeFoos) Create(foo *v1alpha1.Foo) (result *v1alpha1.Foo, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(foosResource, c.ns, foo), &v1alpha1.Foo{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Foo), err +} + +// Update takes the representation of a foo and updates it. Returns the server's representation of the foo, and an error, if there is any. +func (c *FakeFoos) Update(foo *v1alpha1.Foo) (result *v1alpha1.Foo, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(foosResource, c.ns, foo), &v1alpha1.Foo{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Foo), err +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *FakeFoos) UpdateStatus(foo *v1alpha1.Foo) (*v1alpha1.Foo, error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceAction(foosResource, "status", c.ns, foo), &v1alpha1.Foo{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Foo), err +} + +// Delete takes name of the foo and deletes it. Returns an error if one occurs. +func (c *FakeFoos) Delete(name string, options *v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteAction(foosResource, c.ns, name), &v1alpha1.Foo{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeFoos) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(foosResource, c.ns, listOptions) + + _, err := c.Fake.Invokes(action, &v1alpha1.FooList{}) + return err +} + +// Patch applies the patch and returns the patched foo. +func (c *FakeFoos) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Foo, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(foosResource, c.ns, name, data, subresources...), &v1alpha1.Foo{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Foo), err +} diff --git a/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1/fake/fake_samplecontroller_client.go b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1/fake/fake_samplecontroller_client.go new file mode 100644 index 00000000000..847ead580e5 --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1/fake/fake_samplecontroller_client.go @@ -0,0 +1,37 @@ +/* +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 ( + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" + v1alpha1 "samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1" +) + +type FakeSamplecontrollerV1alpha1 struct { + *testing.Fake +} + +func (c *FakeSamplecontrollerV1alpha1) Foos(namespace string) v1alpha1.FooInterface { + return &FakeFoos{c, namespace} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeSamplecontrollerV1alpha1) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1/foo.go b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1/foo.go new file mode 100644 index 00000000000..83ff95614fd --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1/foo.go @@ -0,0 +1,171 @@ +/* +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 v1alpha1 + +import ( + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" + v1alpha1 "samplecontroller/pkg/apis/samplecontroller/v1alpha1" + scheme "samplecontroller/pkg/client/clientset/versioned/scheme" +) + +// FoosGetter has a method to return a FooInterface. +// A group's client should implement this interface. +type FoosGetter interface { + Foos(namespace string) FooInterface +} + +// FooInterface has methods to work with Foo resources. +type FooInterface interface { + Create(*v1alpha1.Foo) (*v1alpha1.Foo, error) + Update(*v1alpha1.Foo) (*v1alpha1.Foo, error) + UpdateStatus(*v1alpha1.Foo) (*v1alpha1.Foo, error) + Delete(name string, options *v1.DeleteOptions) error + DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error + Get(name string, options v1.GetOptions) (*v1alpha1.Foo, error) + List(opts v1.ListOptions) (*v1alpha1.FooList, error) + Watch(opts v1.ListOptions) (watch.Interface, error) + Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Foo, err error) + FooExpansion +} + +// foos implements FooInterface +type foos struct { + client rest.Interface + ns string +} + +// newFoos returns a Foos +func newFoos(c *SamplecontrollerV1alpha1Client, namespace string) *foos { + return &foos{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the foo, and returns the corresponding foo object, and an error if there is any. +func (c *foos) Get(name string, options v1.GetOptions) (result *v1alpha1.Foo, err error) { + result = &v1alpha1.Foo{} + err = c.client.Get(). + Namespace(c.ns). + Resource("foos"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of Foos that match those selectors. +func (c *foos) List(opts v1.ListOptions) (result *v1alpha1.FooList, err error) { + result = &v1alpha1.FooList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("foos"). + VersionedParams(&opts, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested foos. +func (c *foos) Watch(opts v1.ListOptions) (watch.Interface, error) { + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("foos"). + VersionedParams(&opts, scheme.ParameterCodec). + Watch() +} + +// Create takes the representation of a foo and creates it. Returns the server's representation of the foo, and an error, if there is any. +func (c *foos) Create(foo *v1alpha1.Foo) (result *v1alpha1.Foo, err error) { + result = &v1alpha1.Foo{} + err = c.client.Post(). + Namespace(c.ns). + Resource("foos"). + Body(foo). + Do(). + Into(result) + return +} + +// Update takes the representation of a foo and updates it. Returns the server's representation of the foo, and an error, if there is any. +func (c *foos) Update(foo *v1alpha1.Foo) (result *v1alpha1.Foo, err error) { + result = &v1alpha1.Foo{} + err = c.client.Put(). + Namespace(c.ns). + Resource("foos"). + Name(foo.Name). + Body(foo). + Do(). + Into(result) + return +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). + +func (c *foos) UpdateStatus(foo *v1alpha1.Foo) (result *v1alpha1.Foo, err error) { + result = &v1alpha1.Foo{} + err = c.client.Put(). + Namespace(c.ns). + Resource("foos"). + Name(foo.Name). + SubResource("status"). + Body(foo). + Do(). + Into(result) + return +} + +// Delete takes name of the foo and deletes it. Returns an error if one occurs. +func (c *foos) Delete(name string, options *v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("foos"). + Name(name). + Body(options). + Do(). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *foos) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("foos"). + VersionedParams(&listOptions, scheme.ParameterCodec). + Body(options). + Do(). + Error() +} + +// Patch applies the patch and returns the patched foo. +func (c *foos) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Foo, err error) { + result = &v1alpha1.Foo{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("foos"). + SubResource(subresources...). + Name(name). + Body(data). + Do(). + Into(result) + return +} diff --git a/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1/generated_expansion.go b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1/generated_expansion.go new file mode 100644 index 00000000000..93278160fb0 --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1/generated_expansion.go @@ -0,0 +1,18 @@ +/* +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 v1alpha1 + +type FooExpansion interface{} diff --git a/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1/samplecontroller_client.go b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1/samplecontroller_client.go new file mode 100644 index 00000000000..46166aa1b50 --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1/samplecontroller_client.go @@ -0,0 +1,87 @@ +/* +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 v1alpha1 + +import ( + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + rest "k8s.io/client-go/rest" + v1alpha1 "samplecontroller/pkg/apis/samplecontroller/v1alpha1" + "samplecontroller/pkg/client/clientset/versioned/scheme" +) + +type SamplecontrollerV1alpha1Interface interface { + RESTClient() rest.Interface + FoosGetter +} + +// SamplecontrollerV1alpha1Client is used to interact with features provided by the samplecontroller.k8s.io group. +type SamplecontrollerV1alpha1Client struct { + restClient rest.Interface +} + +func (c *SamplecontrollerV1alpha1Client) Foos(namespace string) FooInterface { + return newFoos(c, namespace) +} + +// NewForConfig creates a new SamplecontrollerV1alpha1Client for the given config. +func NewForConfig(c *rest.Config) (*SamplecontrollerV1alpha1Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + client, err := rest.RESTClientFor(&config) + if err != nil { + return nil, err + } + return &SamplecontrollerV1alpha1Client{client}, nil +} + +// NewForConfigOrDie creates a new SamplecontrollerV1alpha1Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *SamplecontrollerV1alpha1Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new SamplecontrollerV1alpha1Client for the given RESTClient. +func New(c rest.Interface) *SamplecontrollerV1alpha1Client { + return &SamplecontrollerV1alpha1Client{c} +} + +func setConfigDefaults(config *rest.Config) error { + gv := v1alpha1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: scheme.Codecs} + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } + + return nil +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *SamplecontrollerV1alpha1Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/samples/full/controller/src/samplecontroller/pkg/client/informers/externalversions/factory.go b/samples/full/controller/src/samplecontroller/pkg/client/informers/externalversions/factory.go new file mode 100644 index 00000000000..21a4ec98eb8 --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/client/informers/externalversions/factory.go @@ -0,0 +1,130 @@ +/* +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 automatically generated by informer-gen + +package externalversions + +import ( + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" + reflect "reflect" + versioned "samplecontroller/pkg/client/clientset/versioned" + internalinterfaces "samplecontroller/pkg/client/informers/externalversions/internalinterfaces" + samplecontroller "samplecontroller/pkg/client/informers/externalversions/samplecontroller" + sync "sync" + time "time" +) + +type sharedInformerFactory struct { + client versioned.Interface + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc + lock sync.Mutex + defaultResync time.Duration + + informers map[reflect.Type]cache.SharedIndexInformer + // startedInformers is used for tracking which informers have been started. + // This allows Start() to be called multiple times safely. + startedInformers map[reflect.Type]bool +} + +// NewSharedInformerFactory constructs a new instance of sharedInformerFactory +func NewSharedInformerFactory(client versioned.Interface, defaultResync time.Duration) SharedInformerFactory { + return NewFilteredSharedInformerFactory(client, defaultResync, v1.NamespaceAll, nil) +} + +// NewFilteredSharedInformerFactory constructs a new instance of sharedInformerFactory. +// Listers obtained via this SharedInformerFactory will be subject to the same filters +// as specified here. +func NewFilteredSharedInformerFactory(client versioned.Interface, defaultResync time.Duration, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerFactory { + return &sharedInformerFactory{ + client: client, + namespace: namespace, + tweakListOptions: tweakListOptions, + defaultResync: defaultResync, + informers: make(map[reflect.Type]cache.SharedIndexInformer), + startedInformers: make(map[reflect.Type]bool), + } +} + +// Start initializes all requested informers. +func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) { + f.lock.Lock() + defer f.lock.Unlock() + + for informerType, informer := range f.informers { + if !f.startedInformers[informerType] { + go informer.Run(stopCh) + f.startedInformers[informerType] = true + } + } +} + +// WaitForCacheSync waits for all started informers' cache were synced. +func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool { + informers := func() map[reflect.Type]cache.SharedIndexInformer { + f.lock.Lock() + defer f.lock.Unlock() + + informers := map[reflect.Type]cache.SharedIndexInformer{} + for informerType, informer := range f.informers { + if f.startedInformers[informerType] { + informers[informerType] = informer + } + } + return informers + }() + + res := map[reflect.Type]bool{} + for informType, informer := range informers { + res[informType] = cache.WaitForCacheSync(stopCh, informer.HasSynced) + } + return res +} + +// InternalInformerFor returns the SharedIndexInformer for obj using an internal +// client. +func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer { + f.lock.Lock() + defer f.lock.Unlock() + + informerType := reflect.TypeOf(obj) + informer, exists := f.informers[informerType] + if exists { + return informer + } + informer = newFunc(f.client, f.defaultResync) + f.informers[informerType] = informer + + return informer +} + +// SharedInformerFactory provides shared informers for resources in all known +// API group versions. +type SharedInformerFactory interface { + internalinterfaces.SharedInformerFactory + ForResource(resource schema.GroupVersionResource) (GenericInformer, error) + WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool + + Samplecontroller() samplecontroller.Interface +} + +func (f *sharedInformerFactory) Samplecontroller() samplecontroller.Interface { + return samplecontroller.New(f, f.namespace, f.tweakListOptions) +} diff --git a/samples/full/controller/src/samplecontroller/pkg/client/informers/externalversions/generic.go b/samples/full/controller/src/samplecontroller/pkg/client/informers/externalversions/generic.go new file mode 100644 index 00000000000..45c3deca36e --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/client/informers/externalversions/generic.go @@ -0,0 +1,61 @@ +/* +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 automatically generated by informer-gen + +package externalversions + +import ( + "fmt" + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" + v1alpha1 "samplecontroller/pkg/apis/samplecontroller/v1alpha1" +) + +// GenericInformer is type of SharedIndexInformer which will locate and delegate to other +// sharedInformers based on type +type GenericInformer interface { + Informer() cache.SharedIndexInformer + Lister() cache.GenericLister +} + +type genericInformer struct { + informer cache.SharedIndexInformer + resource schema.GroupResource +} + +// Informer returns the SharedIndexInformer. +func (f *genericInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +// Lister returns the GenericLister. +func (f *genericInformer) Lister() cache.GenericLister { + return cache.NewGenericLister(f.Informer().GetIndexer(), f.resource) +} + +// ForResource gives generic access to a shared informer of the matching type +// TODO extend this to unknown resources with a client pool +func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { + switch resource { + // Group=samplecontroller.k8s.io, Version=v1alpha1 + case v1alpha1.SchemeGroupVersion.WithResource("foos"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Samplecontroller().V1alpha1().Foos().Informer()}, nil + + } + + return nil, fmt.Errorf("no informer found for %v", resource) +} diff --git a/samples/full/controller/src/samplecontroller/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go b/samples/full/controller/src/samplecontroller/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go new file mode 100644 index 00000000000..928a869a118 --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -0,0 +1,37 @@ +/* +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 automatically generated by informer-gen + +package internalinterfaces + +import ( + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + cache "k8s.io/client-go/tools/cache" + versioned "samplecontroller/pkg/client/clientset/versioned" + time "time" +) + +type NewInformerFunc func(versioned.Interface, time.Duration) cache.SharedIndexInformer + +// SharedInformerFactory a small interface to allow for adding an informer without an import cycle +type SharedInformerFactory interface { + Start(stopCh <-chan struct{}) + InformerFor(obj runtime.Object, newFunc NewInformerFunc) cache.SharedIndexInformer +} + +type TweakListOptionsFunc func(*v1.ListOptions) diff --git a/samples/full/controller/src/samplecontroller/pkg/client/informers/externalversions/samplecontroller/interface.go b/samples/full/controller/src/samplecontroller/pkg/client/informers/externalversions/samplecontroller/interface.go new file mode 100644 index 00000000000..5294dcf50c4 --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/client/informers/externalversions/samplecontroller/interface.go @@ -0,0 +1,46 @@ +/* +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 automatically generated by informer-gen + +package samplecontroller + +import ( + internalinterfaces "samplecontroller/pkg/client/informers/externalversions/internalinterfaces" + v1alpha1 "samplecontroller/pkg/client/informers/externalversions/samplecontroller/v1alpha1" +) + +// Interface provides access to each of this group's versions. +type Interface interface { + // V1alpha1 provides access to shared informers for resources in V1alpha1. + V1alpha1() v1alpha1.Interface +} + +type group struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// V1alpha1 returns a new v1alpha1.Interface. +func (g *group) V1alpha1() v1alpha1.Interface { + return v1alpha1.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/samples/full/controller/src/samplecontroller/pkg/client/informers/externalversions/samplecontroller/v1alpha1/foo.go b/samples/full/controller/src/samplecontroller/pkg/client/informers/externalversions/samplecontroller/v1alpha1/foo.go new file mode 100644 index 00000000000..33deae93159 --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/client/informers/externalversions/samplecontroller/v1alpha1/foo.go @@ -0,0 +1,88 @@ +/* +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 automatically generated by informer-gen + +package v1alpha1 + +import ( + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + samplecontroller_v1alpha1 "samplecontroller/pkg/apis/samplecontroller/v1alpha1" + versioned "samplecontroller/pkg/client/clientset/versioned" + internalinterfaces "samplecontroller/pkg/client/informers/externalversions/internalinterfaces" + v1alpha1 "samplecontroller/pkg/client/listers/samplecontroller/v1alpha1" + time "time" +) + +// FooInformer provides access to a shared informer and lister for +// Foos. +type FooInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.FooLister +} + +type fooInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewFooInformer constructs a new informer for Foo type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFooInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredFooInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredFooInformer constructs a new informer for Foo type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredFooInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.SamplecontrollerV1alpha1().Foos(namespace).List(options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.SamplecontrollerV1alpha1().Foos(namespace).Watch(options) + }, + }, + &samplecontroller_v1alpha1.Foo{}, + resyncPeriod, + indexers, + ) +} + +func (f *fooInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredFooInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *fooInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&samplecontroller_v1alpha1.Foo{}, f.defaultInformer) +} + +func (f *fooInformer) Lister() v1alpha1.FooLister { + return v1alpha1.NewFooLister(f.Informer().GetIndexer()) +} diff --git a/samples/full/controller/src/samplecontroller/pkg/client/informers/externalversions/samplecontroller/v1alpha1/interface.go b/samples/full/controller/src/samplecontroller/pkg/client/informers/externalversions/samplecontroller/v1alpha1/interface.go new file mode 100644 index 00000000000..a6af7eb318c --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/client/informers/externalversions/samplecontroller/v1alpha1/interface.go @@ -0,0 +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. +*/ + +// This file was automatically generated by informer-gen + +package v1alpha1 + +import ( + internalinterfaces "samplecontroller/pkg/client/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // Foos returns a FooInformer. + Foos() FooInformer +} + +type version struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// Foos returns a FooInformer. +func (v *version) Foos() FooInformer { + return &fooInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/samples/full/controller/src/samplecontroller/pkg/client/listers/samplecontroller/v1alpha1/expansion_generated.go b/samples/full/controller/src/samplecontroller/pkg/client/listers/samplecontroller/v1alpha1/expansion_generated.go new file mode 100644 index 00000000000..8829daba673 --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/client/listers/samplecontroller/v1alpha1/expansion_generated.go @@ -0,0 +1,27 @@ +/* +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 automatically generated by lister-gen + +package v1alpha1 + +// FooListerExpansion allows custom methods to be added to +// FooLister. +type FooListerExpansion interface{} + +// FooNamespaceListerExpansion allows custom methods to be added to +// FooNamespaceLister. +type FooNamespaceListerExpansion interface{} diff --git a/samples/full/controller/src/samplecontroller/pkg/client/listers/samplecontroller/v1alpha1/foo.go b/samples/full/controller/src/samplecontroller/pkg/client/listers/samplecontroller/v1alpha1/foo.go new file mode 100644 index 00000000000..63a77e47e9d --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/client/listers/samplecontroller/v1alpha1/foo.go @@ -0,0 +1,94 @@ +/* +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 automatically generated by lister-gen + +package v1alpha1 + +import ( + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" + v1alpha1 "samplecontroller/pkg/apis/samplecontroller/v1alpha1" +) + +// FooLister helps list Foos. +type FooLister interface { + // List lists all Foos in the indexer. + List(selector labels.Selector) (ret []*v1alpha1.Foo, err error) + // Foos returns an object that can list and get Foos. + Foos(namespace string) FooNamespaceLister + FooListerExpansion +} + +// fooLister implements the FooLister interface. +type fooLister struct { + indexer cache.Indexer +} + +// NewFooLister returns a new FooLister. +func NewFooLister(indexer cache.Indexer) FooLister { + return &fooLister{indexer: indexer} +} + +// List lists all Foos in the indexer. +func (s *fooLister) List(selector labels.Selector) (ret []*v1alpha1.Foo, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.Foo)) + }) + return ret, err +} + +// Foos returns an object that can list and get Foos. +func (s *fooLister) Foos(namespace string) FooNamespaceLister { + return fooNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// FooNamespaceLister helps list and get Foos. +type FooNamespaceLister interface { + // List lists all Foos in the indexer for a given namespace. + List(selector labels.Selector) (ret []*v1alpha1.Foo, err error) + // Get retrieves the Foo from the indexer for a given namespace and name. + Get(name string) (*v1alpha1.Foo, error) + FooNamespaceListerExpansion +} + +// fooNamespaceLister implements the FooNamespaceLister +// interface. +type fooNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all Foos in the indexer for a given namespace. +func (s fooNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.Foo, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.Foo)) + }) + return ret, err +} + +// Get retrieves the Foo from the indexer for a given namespace and name. +func (s fooNamespaceLister) Get(name string) (*v1alpha1.Foo, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("foo"), name) + } + return obj.(*v1alpha1.Foo), nil +} diff --git a/samples/full/controller/src/samplecontroller/pkg/controller/doc.go b/samples/full/controller/src/samplecontroller/pkg/controller/doc.go new file mode 100644 index 00000000000..c3eea3a1a02 --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/controller/doc.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 controller + diff --git a/samples/full/controller/src/samplecontroller/pkg/controller/foo/controller.go b/samples/full/controller/src/samplecontroller/pkg/controller/foo/controller.go new file mode 100644 index 00000000000..3b2100e058c --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/controller/foo/controller.go @@ -0,0 +1,72 @@ +/* +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 foo + +import ( + "log" + + "github.com/kubernetes-sigs/kubebuilder/pkg/controller" + "github.com/kubernetes-sigs/kubebuilder/pkg/controller/types" + + samplecontrollerv1alpha1client "samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1" + samplecontrollerv1alpha1lister "samplecontroller/pkg/client/listers/samplecontroller/v1alpha1" + samplecontrollerv1alpha1 "samplecontroller/pkg/apis/samplecontroller/v1alpha1" + samplecontrollerv1alpha1informer "samplecontroller/pkg/client/informers/externalversions/samplecontroller/v1alpha1" + "samplecontroller/pkg/inject/args" +) + +// EDIT THIS FILE +// This files was created by "kubebuilder create resource" for you to edit. +// Controller implementation logic for Foo resources goes here. + +func (bc *FooController) Reconcile(k types.ReconcileKey) error { + // INSERT YOUR CODE HERE + log.Printf("Implement the Reconcile function on foo.FooController to reconcile %s\n", k.Name) + return nil +} + +// +controller:group=samplecontroller,version=v1alpha1,kind=Foo,resource=foos +type FooController struct { + // INSERT ADDITIONAL FIELDS HERE + fooLister samplecontrollerv1alpha1lister.FooLister + fooclient samplecontrollerv1alpha1client.SamplecontrollerV1alpha1Interface +} + +// ProvideController provides a controller that will be run at startup. Kubebuilder will use codegeneration +// to automatically register this controller in the inject package +func ProvideController(arguments args.InjectArgs) (*controller.GenericController, error) { + // INSERT INITIALIZATIONS FOR ADDITIONAL FIELDS HERE + bc := &FooController{ + fooLister: arguments.ControllerManager.GetInformerProvider(&samplecontrollerv1alpha1.Foo{}).(samplecontrollerv1alpha1informer.FooInformer).Lister(), + fooclient: arguments.Clientset.SamplecontrollerV1alpha1(), + } + + // Create a new controller that will call FooController.Reconcile on changes to Foos + gc := &controller.GenericController{ + Name: "FooController", + Reconcile: bc.Reconcile, + InformerRegistry: arguments.ControllerManager, + } + if err := gc.Watch(&samplecontrollerv1alpha1.Foo{}); err != nil { + return gc, err + } + + // INSERT ADDITIONAL WATCHES HERE BY CALLING gc.Watch.*() FUNCTIONS + // NOTE: Informers for Kubernetes resources *MUST* be registered in the pkg/inject package so that they are started. + return gc, nil +} diff --git a/samples/full/controller/src/samplecontroller/pkg/controller/foo/controller_test.go b/samples/full/controller/src/samplecontroller/pkg/controller/foo/controller_test.go new file mode 100644 index 00000000000..428a43fe46d --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/controller/foo/controller_test.go @@ -0,0 +1,78 @@ + +/* +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 foo_test + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + "github.com/kubernetes-sigs/kubebuilder/pkg/controller/types" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + . "samplecontroller/pkg/apis/samplecontroller/v1alpha1" + . "samplecontroller/pkg/client/clientset/versioned/typed/samplecontroller/v1alpha1" +) + +// EDIT THIS FILE! +// Created by "kubebuilder create resource" for you to implement controller logic tests + +var _ = Describe("Foo controller", func() { + var instance Foo + var expectedKey types.ReconcileKey + var client FooInterface + + BeforeEach(func() { + instance = Foo{} + instance.Name = "instance-1" + expectedKey = types.ReconcileKey{ + Namespace: "default", + Name: "instance-1", + } + }) + + AfterEach(func() { + client.Delete(instance.Name, &metav1.DeleteOptions{}) + }) + + Describe("when creating a new object", func() { + It("invoke the reconcile method", func() { + after := make(chan struct{}) + ctrl.AfterReconcile = func(key types.ReconcileKey, err error) { + defer func() { + // Recover in case the key is reconciled multiple times + defer func() { recover() }() + close(after) + }() + defer GinkgoRecover() + Expect(key).To(Equal(expectedKey)) + Expect(err).ToNot(HaveOccurred()) + } + + // Create the instance + client = cs.SamplecontrollerV1alpha1().Foos("default") + _, err := client.Create(&instance) + Expect(err).ShouldNot(HaveOccurred()) + + // Wait for reconcile to happen + Eventually(after, "10s", "100ms").Should(BeClosed()) + + // INSERT YOUR CODE HERE - test conditions post reconcile + }) + }) +}) diff --git a/samples/full/controller/src/samplecontroller/pkg/controller/foo/foo_suite_test.go b/samples/full/controller/src/samplecontroller/pkg/controller/foo/foo_suite_test.go new file mode 100644 index 00000000000..c23b8ed6a8f --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/controller/foo/foo_suite_test.go @@ -0,0 +1,77 @@ + +/* +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 foo_test + +import ( + "testing" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "github.com/kubernetes-sigs/kubebuilder/pkg/controller" + "github.com/kubernetes-sigs/kubebuilder/pkg/inject/run" + "github.com/kubernetes-sigs/kubebuilder/pkg/test" + "k8s.io/client-go/kubernetes" + "k8s.io/client-go/rest" + + "samplecontroller/pkg/client/clientset/versioned" + "samplecontroller/pkg/inject" + "samplecontroller/pkg/inject/args" +) + +var ( + testenv *test.TestEnvironment + config *rest.Config + cs *versioned.Clientset + ks *kubernetes.Clientset + shutdown chan struct{} + ctrl *controller.GenericController +) + +func TestBee(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecsWithDefaultAndCustomReporters(t, "Foo Suite", []Reporter{test.NewlineReporter{}}) +} + +var _ = BeforeSuite(func() { + testenv = &test.TestEnvironment{CRDs: inject.Injector.CRDs} + var err error + config, err = testenv.Start() + Expect(err).NotTo(HaveOccurred()) + cs = versioned.NewForConfigOrDie(config) + ks = kubernetes.NewForConfigOrDie(config) + + shutdown = make(chan struct{}) + arguments := args.CreateInjectArgs(config) + go func() { + defer GinkgoRecover() + Expect(inject.RunAll(run.RunArguments{Stop: shutdown}, arguments)). + To(BeNil()) + }() + + // Wait for RunAll to create the controllers and then set the reference + defer GinkgoRecover() + Eventually(func() interface{} { return arguments.ControllerManager.GetController("FooController") }). + Should(Not(BeNil())) + ctrl = arguments.ControllerManager.GetController("FooController") +}) + +var _ = AfterSuite(func() { + close(shutdown) + testenv.Stop() +}) diff --git a/samples/full/controller/src/samplecontroller/pkg/doc.go b/samples/full/controller/src/samplecontroller/pkg/doc.go new file mode 100644 index 00000000000..b71ef504a53 --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/doc.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 pkg + diff --git a/samples/full/controller/src/samplecontroller/pkg/inject/args/args.go b/samples/full/controller/src/samplecontroller/pkg/inject/args/args.go new file mode 100644 index 00000000000..1b24ebb43c6 --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/inject/args/args.go @@ -0,0 +1,47 @@ +/* +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 args + +import ( + "time" + + "github.com/kubernetes-sigs/kubebuilder/pkg/inject/args" + "k8s.io/client-go/rest" + + "samplecontroller/pkg/client/clientset/versioned" + "samplecontroller/pkg/client/informers/externalversions" +) + +// InjectArgs are the arguments need to initialize controllers +type InjectArgs struct { + args.InjectArgs + + Clientset *versioned.Clientset + Informers externalversions.SharedInformerFactory +} + + +// CreateInjectArgs returns new controller args +func CreateInjectArgs(config *rest.Config) InjectArgs { + cs := versioned.NewForConfigOrDie(config) + return InjectArgs{ + InjectArgs: args.CreateInjectArgs(config), + Clientset: cs, + Informers: externalversions.NewSharedInformerFactory(cs, 2 * time.Minute), + } +} diff --git a/samples/full/controller/src/samplecontroller/pkg/inject/doc.go b/samples/full/controller/src/samplecontroller/pkg/inject/doc.go new file mode 100644 index 00000000000..0d780ce9ce9 --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/inject/doc.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 inject + diff --git a/samples/full/controller/src/samplecontroller/pkg/inject/inject.go b/samples/full/controller/src/samplecontroller/pkg/inject/inject.go new file mode 100644 index 00000000000..373023d48f1 --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/inject/inject.go @@ -0,0 +1,46 @@ +/* +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 inject + +import ( + "github.com/kubernetes-sigs/kubebuilder/pkg/inject/run" + injectargs "github.com/kubernetes-sigs/kubebuilder/pkg/inject/args" + + "samplecontroller/pkg/inject/args" +) + +var ( + // Inject is used to add items to the Injector + Inject []func(args.InjectArgs) error + + // Injector runs items + Injector injectargs.Injector +) + +// RunAll starts all of the informers and Controllers +func RunAll(rargs run.RunArguments, iargs args.InjectArgs) error { + // Run functions to initialize injector + for _, i := range Inject { + if err := i(iargs); err != nil { + return err + } + } + Injector.Run(rargs) + <-rargs.Stop + return nil +} diff --git a/samples/full/controller/src/samplecontroller/pkg/inject/zz_generated.kubebuilder.go b/samples/full/controller/src/samplecontroller/pkg/inject/zz_generated.kubebuilder.go new file mode 100644 index 00000000000..75d786921e3 --- /dev/null +++ b/samples/full/controller/src/samplecontroller/pkg/inject/zz_generated.kubebuilder.go @@ -0,0 +1,68 @@ +/* +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 inject + +import ( + samplecontrollerv1alpha1 "samplecontroller/pkg/apis/samplecontroller/v1alpha1" + rscheme "samplecontroller/pkg/client/clientset/versioned/scheme" + "samplecontroller/pkg/controller/foo" + "samplecontroller/pkg/inject/args" + + "github.com/kubernetes-sigs/kubebuilder/pkg/inject/run" + rbacv1 "k8s.io/api/rbac/v1" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/client-go/kubernetes/scheme" +) + +func init() { + rscheme.AddToScheme(scheme.Scheme) + + // Inject Informers + Inject = append(Inject, func(arguments args.InjectArgs) error { + Injector.ControllerManager = arguments.ControllerManager + + if err := arguments.ControllerManager.AddInformerProvider(&samplecontrollerv1alpha1.Foo{}, arguments.Informers.Samplecontroller().V1alpha1().Foos()); err != nil { + return err + } + + // Add Kubernetes informers + + if c, err := foo.ProvideController(arguments); err != nil { + return err + } else { + arguments.ControllerManager.AddController(c) + } + return nil + }) + + // Inject CRDs + Injector.CRDs = append(Injector.CRDs, &samplecontrollerv1alpha1.FooCRD) + // Inject PolicyRules + Injector.PolicyRules = append(Injector.PolicyRules, rbacv1.PolicyRule{ + APIGroups: []string{"samplecontroller.k8s.io"}, + Resources: []string{"*"}, + Verbs: []string{"*"}, + }) + // Inject GroupVersions + Injector.GroupVersions = append(Injector.GroupVersions, schema.GroupVersion{ + Group: "samplecontroller.k8s.io", + Version: "v1alpha1", + }) + Injector.RunFns = append(Injector.RunFns, func(arguments run.RunArguments) error { + Injector.ControllerManager.RunInformersAndControllers(arguments) + return nil + }) +}