From b25a5e34b3215b7faf32325b8d8aa9d7465a4055 Mon Sep 17 00:00:00 2001 From: mengyang02 Date: Fri, 25 Aug 2017 09:47:31 +0800 Subject: [PATCH 1/3] site of notebook should be same as cloud server's by default --- paddlecloud/paddlecloud/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paddlecloud/paddlecloud/settings.py b/paddlecloud/paddlecloud/settings.py index 0cd29d45..7e264da3 100644 --- a/paddlecloud/paddlecloud/settings.py +++ b/paddlecloud/paddlecloud/settings.py @@ -323,7 +323,7 @@ ETCD_IMAGE="quay.io/coreos/etcd:v3.2.1" # domains that allow notebook to enter -NOTEBOOK_DOMAINS=["www.paddlepaddle.org"] +NOTEBOOK_DOMAINS=["cloud.paddlepaddle.org"] # GPU limit for users # TODO(Yancey1989): From ae182da39dbb66ea3513e30922116813f3bce184 Mon Sep 17 00:00:00 2001 From: mengyang02 Date: Tue, 17 Oct 2017 10:37:02 +0800 Subject: [PATCH 2/3] fix error in usage doc --- doc/usage_cn.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/usage_cn.md b/doc/usage_cn.md index 91f2f070..ee278e67 100644 --- a/doc/usage_cn.md +++ b/doc/usage_cn.md @@ -129,12 +129,12 @@ def recordio_reader(filepath, parallelism, trainer_id): paddlecloud命令集成了上传数据的功能,目前仅针对存储系统是CephFS的环境。如果希望上传,执行: ```bash -paddlecloud file src dest +paddlecloud file put src dest ``` - `src` 必须是当前目录的子目录,`../`是不允许的。 - `src` 如果以'/'结尾,则表示上传`src`目录下的文件,不会在`dest`下创建新的目录。 - `src` 如果没有以`/`结尾,则表示上传`src`目录,会在`dest`下创建一个新的目录。 -- `dest` 必须包含`/pfs/{datacenter}/user/{username}`目录。 +- `dest` 必须包含`/pfs/{datacenter}/home/{username}`目录。 From 692b42c6229631ccb334fa66a4e17419d44283d2 Mon Sep 17 00:00:00 2001 From: m3ngyang Date: Sat, 27 Jan 2018 23:58:38 +0800 Subject: [PATCH 3/3] implement registration and listening of crd trainingjob --- .gitignore | 1 + .travis.yml | 6 +- go/cmd/operator/Dockerfile | 7 + go/cmd/operator/operator.go | 59 ++++ go/glide.lock | 24 +- go/glide.yaml | 4 +- go/hack/custom-boilerplate.go.txt | 15 + go/hack/update-codegen.sh | 5 +- go/pkg/apis/paddlepaddle/v1alpha1/types.go | 15 +- .../v1alpha1/zz_generated.deepcopy.go | 287 ++++++++++++++++++ .../client/clientset/versioned/clientset.go | 97 ++++++ go/pkg/client/clientset/versioned/doc.go | 20 ++ .../versioned/fake/clientset_generated.go | 70 +++++ go/pkg/client/clientset/versioned/fake/doc.go | 20 ++ .../clientset/versioned/fake/register.go | 52 ++++ .../client/clientset/versioned/scheme/doc.go | 20 ++ .../clientset/versioned/scheme/register.go | 52 ++++ .../typed/paddlepaddle/v1alpha1/doc.go | 20 ++ .../typed/paddlepaddle/v1alpha1/fake/doc.go | 20 ++ .../v1alpha1/fake/fake_paddlepaddle_client.go | 37 +++ .../v1alpha1/fake/fake_trainingjob.go | 125 ++++++++ .../v1alpha1/generated_expansion.go | 18 ++ .../v1alpha1/paddlepaddle_client.go | 87 ++++++ .../paddlepaddle/v1alpha1/trainingjob.go | 154 ++++++++++ .../informers/externalversions/factory.go | 118 +++++++ .../informers/externalversions/generic.go | 61 ++++ .../internalinterfaces/factory_interfaces.go | 34 +++ .../paddlepaddle/interface.go | 44 +++ .../paddlepaddle/v1alpha1/interface.go | 43 +++ .../paddlepaddle/v1alpha1/trainingjob.go | 73 +++++ .../v1alpha1/expansion_generated.go | 27 ++ .../paddlepaddle/v1alpha1/trainingjob.go | 94 ++++++ go/pkg/controller/controller.go | 248 +++++++++++++++ go/pkg/signals/signals.go | 30 ++ 34 files changed, 1970 insertions(+), 17 deletions(-) create mode 100644 go/cmd/operator/Dockerfile create mode 100644 go/cmd/operator/operator.go create mode 100644 go/hack/custom-boilerplate.go.txt create mode 100644 go/pkg/apis/paddlepaddle/v1alpha1/zz_generated.deepcopy.go create mode 100644 go/pkg/client/clientset/versioned/clientset.go create mode 100644 go/pkg/client/clientset/versioned/doc.go create mode 100644 go/pkg/client/clientset/versioned/fake/clientset_generated.go create mode 100644 go/pkg/client/clientset/versioned/fake/doc.go create mode 100644 go/pkg/client/clientset/versioned/fake/register.go create mode 100644 go/pkg/client/clientset/versioned/scheme/doc.go create mode 100644 go/pkg/client/clientset/versioned/scheme/register.go create mode 100644 go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/doc.go create mode 100644 go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/fake/doc.go create mode 100644 go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/fake/fake_paddlepaddle_client.go create mode 100644 go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/fake/fake_trainingjob.go create mode 100644 go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/generated_expansion.go create mode 100644 go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/paddlepaddle_client.go create mode 100644 go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/trainingjob.go create mode 100644 go/pkg/client/informers/externalversions/factory.go create mode 100644 go/pkg/client/informers/externalversions/generic.go create mode 100644 go/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go create mode 100644 go/pkg/client/informers/externalversions/paddlepaddle/interface.go create mode 100644 go/pkg/client/informers/externalversions/paddlepaddle/v1alpha1/interface.go create mode 100644 go/pkg/client/informers/externalversions/paddlepaddle/v1alpha1/trainingjob.go create mode 100644 go/pkg/client/listers/paddlepaddle/v1alpha1/expansion_generated.go create mode 100644 go/pkg/client/listers/paddlepaddle/v1alpha1/trainingjob.go create mode 100644 go/pkg/controller/controller.go create mode 100644 go/pkg/signals/signals.go diff --git a/.gitignore b/.gitignore index 147de47f..39d89b06 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ vendor *~ *.pyc *.idea +*.vscode diff --git a/.travis.yml b/.travis.yml index 79e8b1d2..82ce5d32 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,11 +11,7 @@ matrix: - | bash .tools/check_style.sh RESULT=$?; if [ $RESULT -eq 0 ]; then true; else false; fi; - - ln -s $GOPATH/src/github.com/PaddlePaddle $GOPATH/src/github.com/paddlepaddle - - cd go && glide install && go get k8s.io/kubernetes || echo 1 - - bash ./vendor/k8s.io/code-generator/generate-groups.sh "deepcopy,client,informer,lister" github.com/PaddlePaddle/cloud/go/pkg/client github.com/PaddlePaddle/cloud/go/pkg/apis paddlepaddle:v1alpha1 - - grep "github.com/paddlepaddle/cloud" -nR pkg/client | awk -F ':' '{print $1}' | xargs sed -i 's|github.com/paddlepaddle/cloud|github.com/PaddlePaddle/cloud|g' - - bash .tools/gen_config.sh && glide install --strip-vendor && go test $(glide novendor) + - cd go && bash .tools/gen_config.sh && glide install --strip-vendor && go test $(glide novendor) - language: python python: 2.7 sudo: required diff --git a/go/cmd/operator/Dockerfile b/go/cmd/operator/Dockerfile new file mode 100644 index 00000000..c5f5dc47 --- /dev/null +++ b/go/cmd/operator/Dockerfile @@ -0,0 +1,7 @@ +FROM golang:1.9 +RUN go get github.com/Masterminds/glide +COPY cloud $GOPATH/src/github.com/PaddlePaddle/cloud +WORKDIR $GOPATH/src/github.com/PaddlePaddle/cloud/go +RUN glide install --strip-vendor +RUN go build -o /usr/local/bin/operator github.com/PaddlePaddle/cloud/go/cmd/operator +CMD ["operator"] diff --git a/go/cmd/operator/operator.go b/go/cmd/operator/operator.go new file mode 100644 index 00000000..d1293095 --- /dev/null +++ b/go/cmd/operator/operator.go @@ -0,0 +1,59 @@ +package main + +import ( + "flag" + "time" + + "github.com/golang/glog" + + apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" + "k8s.io/client-go/kubernetes" + "k8s.io/client-go/tools/clientcmd" + + paddleclientset "github.com/PaddlePaddle/cloud/go/pkg/client/clientset/versioned" + paddleinformers "github.com/PaddlePaddle/cloud/go/pkg/client/informers/externalversions" + paddlecontroller "github.com/PaddlePaddle/cloud/go/pkg/controller" + "github.com/PaddlePaddle/cloud/go/pkg/signals" +) + +func init() { + +} + +func main() { + masterURL := flag.String("master", "", "Address of a kube master.") + kubeConfig := flag.String("kubeconfig", "", "Path to a kube config. Only required if out-of-cluster.") + flag.Parse() + + stopCh := signals.SetupSignalHandler() + + cfg, err := clientcmd.BuildConfigFromFlags(*masterURL, *kubeConfig) + if err != nil { + glog.Fatalf("Error building kubeconfig: %s", err.Error()) + } + + kubeClient, err := kubernetes.NewForConfig(cfg) + if err != nil { + glog.Fatalf("Error building kubernetes clientset: %s", err.Error()) + } + + extapiClient, err := apiextensionsclient.NewForConfig(cfg) + if err != nil { + glog.Fatalf("Error building kubernetes extension api clientset: %s", err.Error()) + } + + paddleClient, err := paddleclientset.NewForConfig(cfg) + if err != nil { + glog.Fatalf("Error building paddle clientset: %s", err.Error()) + } + + paddleInformer := paddleinformers.NewSharedInformerFactory(paddleClient, time.Second*10) + + controller := paddlecontroller.New(kubeClient, extapiClient, paddleClient, paddleInformer) + + go paddleInformer.Start(stopCh) + + if controller.Run(2, stopCh); err != nil { + glog.Fatalf("Error running paddle trainingjob controller: %s", err.Error()) + } +} diff --git a/go/glide.lock b/go/glide.lock index 73cdb86c..3dc7b526 100644 --- a/go/glide.lock +++ b/go/glide.lock @@ -1,5 +1,5 @@ -hash: 9c125b7ddc893ea6228034bc28995209118f4702b183cb6cec49ab7a776708db -updated: 2018-01-15T20:33:34.067167+08:00 +hash: 0cbae2cb21676e83b46e9d0c0284c7580e82f88c3c64b7ddb35aeeccc48dc36e +updated: 2018-01-27T23:00:42.907198+08:00 imports: - name: github.com/bitly/go-simplejson version: aabad6e819789e569bd6aabf444c935aa9ba1e44 @@ -34,6 +34,10 @@ imports: - sortkeys - name: github.com/golang/glog version: 44145f04b68cf362d9c4df2182967c2275eaefed +- name: github.com/golang/groupcache + version: 02826c3e79038b59d737d3b1c0a1d937f71a4433 + subpackages: + - lru - name: github.com/golang/protobuf version: 4bd1920723d7b7c925de087aa32e2187708897f7 subpackages: @@ -57,7 +61,7 @@ imports: - name: github.com/gorilla/context version: 215affda49addc4c8ef7e2534915df2c8c35c6cd - name: github.com/gorilla/mux - version: 7f08801859139f86dfafd1c296e2cba9a80d292e + version: 53c1911da2b537f792e7cafcb446b05ffe33b996 - name: github.com/gregjones/httpcache version: 787624de3eb7bd915c329cba748687a3b22666a6 subpackages: @@ -157,6 +161,14 @@ imports: - settings/v1alpha1 - storage/v1 - storage/v1beta1 +- name: k8s.io/apiextensions-apiserver + version: 996a70a27a0dcf53642ca52601b9107cb2ad810a + subpackages: + - pkg/apis/apiextensions + - pkg/apis/apiextensions/v1beta1 + - pkg/client/clientset/clientset + - pkg/client/clientset/clientset/scheme + - pkg/client/clientset/clientset/typed/apiextensions/v1beta1 - name: k8s.io/apimachinery version: 019ae5ada31de202164b118aee88ee2d14075c31 subpackages: @@ -214,6 +226,7 @@ imports: version: 35874c597fed17ca62cd197e516d7d5ff9a2958c subpackages: - discovery + - discovery/fake - kubernetes - kubernetes/scheme - kubernetes/typed/admissionregistration/v1alpha1 @@ -243,6 +256,7 @@ imports: - pkg/version - rest - rest/watch + - testing - tools/auth - tools/cache - tools/clientcmd @@ -251,12 +265,14 @@ imports: - tools/clientcmd/api/v1 - tools/metrics - tools/pager + - tools/record - tools/reference - transport - util/cert - util/flowcontrol - util/homedir - util/integer + - util/workqueue - name: k8s.io/code-generator version: 25fd8c8ddbf75b223882df4479f8b8e615da05ae - name: k8s.io/kube-openapi @@ -264,7 +280,7 @@ imports: subpackages: - pkg/common - name: k8s.io/kubernetes - version: f50b3431ea82d981d7d2e62d9f9da44e724fbe41 + version: ce87b2ba95dcf70dd12a4c977e006a65a77708c4 subpackages: - pkg/api testImports: diff --git a/go/glide.yaml b/go/glide.yaml index 45d33f60..1c426441 100644 --- a/go/glide.yaml +++ b/go/glide.yaml @@ -19,4 +19,6 @@ import: - package: github.com/go-stack/stack version: v1.6.0 - package: k8s.io/code-generator - version: kubernetes-1.8.5 \ No newline at end of file + version: kubernetes-1.8.6 +- package: k8s.io/apiextensions-apiserver + version: kubernetes-1.8.6 diff --git a/go/hack/custom-boilerplate.go.txt b/go/hack/custom-boilerplate.go.txt new file mode 100644 index 00000000..043b6fa8 --- /dev/null +++ b/go/hack/custom-boilerplate.go.txt @@ -0,0 +1,15 @@ +/* +Copyright (c) 2016 PaddlePaddle Authors All Rights Reserve. + +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. +*/ diff --git a/go/hack/update-codegen.sh b/go/hack/update-codegen.sh index 86a7269d..54ffa81e 100755 --- a/go/hack/update-codegen.sh +++ b/go/hack/update-codegen.sh @@ -32,5 +32,8 @@ echo ${CODEGEN_PKG} # instead of the $GOPATH directly. For normal projects this can be dropped. ${CODEGEN_PKG}/generate-groups.sh "deepcopy,client,informer,lister" \ github.com/PaddlePaddle/cloud/go/pkg/client github.com/PaddlePaddle/cloud/go/pkg/apis \ - paddlepaddle:v1alpha1 + paddlepaddle:v1alpha1 \ + --go-header-file ${SCRIPT_ROOT}/hack/custom-boilerplate.go.txt +# --output-base "$(dirname ${BASH_SOURCE})/../../../../.." +grep "github.com/paddlepaddle/cloud" -nR pkg/client | awk -F ':' '{print $1}' | xargs sed -i "" 's|github.com/paddlepaddle/cloud|github.com/PaddlePaddle/cloud|g' diff --git a/go/pkg/apis/paddlepaddle/v1alpha1/types.go b/go/pkg/apis/paddlepaddle/v1alpha1/types.go index 58648c4f..58cba1ec 100644 --- a/go/pkg/apis/paddlepaddle/v1alpha1/types.go +++ b/go/pkg/apis/paddlepaddle/v1alpha1/types.go @@ -8,8 +8,9 @@ import ( ) const ( - CRDKind = "TraingingJob" - CRDKindPlural = "traingingjobs" + CRDKind = "TrainingJob" + CRDKindPlural = "trainingjobs" + CRDShortName = "tj" CRDGroup = "paddlepaddle.org" CRDVersion = "v1alpha1" ) @@ -21,7 +22,6 @@ func CRDName() string { // +genclient // +genclient:noStatus -// +genclient:nonNamespaced // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +resource:path=trainingjob @@ -36,7 +36,10 @@ type TrainingJob struct { // TrainingJobSpec is the spec for a TrainingJob resource type TrainingJobSpec struct { // General job attributes. - Image string `json:"image,omitempty"` + Image string `json:"image,omitempty"` + // If you want to use the hostnetwork instead of container network + // portmanager is necessary. + HostNetwork bool `json:"host_network,omitempty"` Port int `json:"port,omitempty"` PortsNum int `json:"ports_num,omitempty"` PortsNumForSparse int `json:"ports_num_for_sparse,omitempty"` @@ -125,10 +128,10 @@ type TrainingJobStatus struct { // Reason is the reason of job phase failed Reason string `json:"reason"` // ScaleStatus is autoscale status of trainer jobs - // TODO(ZhengQi): this will used in autoscale mode in future. + // TODO(ZhengQi): this will be used in autoscale mode in future. ScaleStatus TrainerJobScaleStatus `json:"scale_status"` // ReplicaStatuses is detail status of resources - // TODO(ZhengQi): should we only considered trainer job now? + // TODO(ZhengQi): should we only consider trainer job now? ReplicaStatuses []*TrainingResourceStatus `json:"replica_statuses"` } diff --git a/go/pkg/apis/paddlepaddle/v1alpha1/zz_generated.deepcopy.go b/go/pkg/apis/paddlepaddle/v1alpha1/zz_generated.deepcopy.go new file mode 100644 index 00000000..647a1522 --- /dev/null +++ b/go/pkg/apis/paddlepaddle/v1alpha1/zz_generated.deepcopy.go @@ -0,0 +1,287 @@ +// +build !ignore_autogenerated + +/* +Copyright (c) 2016 PaddlePaddle Authors All Rights Reserve. + +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 ( + v1 "k8s.io/api/core/v1" + conversion "k8s.io/apimachinery/pkg/conversion" + runtime "k8s.io/apimachinery/pkg/runtime" + reflect "reflect" +) + +// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them. +// +// Deprecated: deepcopy registration will go away when static deepcopy is fully implemented. +func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc { + return []conversion.GeneratedDeepCopyFunc{ + {Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error { + in.(*MasterSpec).DeepCopyInto(out.(*MasterSpec)) + return nil + }, InType: reflect.TypeOf(&MasterSpec{})}, + {Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error { + in.(*PserverSpec).DeepCopyInto(out.(*PserverSpec)) + return nil + }, InType: reflect.TypeOf(&PserverSpec{})}, + {Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error { + in.(*TrainerJobScaleStatus).DeepCopyInto(out.(*TrainerJobScaleStatus)) + return nil + }, InType: reflect.TypeOf(&TrainerJobScaleStatus{})}, + {Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error { + in.(*TrainerSpec).DeepCopyInto(out.(*TrainerSpec)) + return nil + }, InType: reflect.TypeOf(&TrainerSpec{})}, + {Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error { + in.(*TrainingJob).DeepCopyInto(out.(*TrainingJob)) + return nil + }, InType: reflect.TypeOf(&TrainingJob{})}, + {Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error { + in.(*TrainingJobList).DeepCopyInto(out.(*TrainingJobList)) + return nil + }, InType: reflect.TypeOf(&TrainingJobList{})}, + {Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error { + in.(*TrainingJobSpec).DeepCopyInto(out.(*TrainingJobSpec)) + return nil + }, InType: reflect.TypeOf(&TrainingJobSpec{})}, + {Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error { + in.(*TrainingJobStatus).DeepCopyInto(out.(*TrainingJobStatus)) + return nil + }, InType: reflect.TypeOf(&TrainingJobStatus{})}, + {Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error { + in.(*TrainingResourceStatus).DeepCopyInto(out.(*TrainingResourceStatus)) + return nil + }, InType: reflect.TypeOf(&TrainingResourceStatus{})}, + } +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MasterSpec) DeepCopyInto(out *MasterSpec) { + *out = *in + in.Resources.DeepCopyInto(&out.Resources) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MasterSpec. +func (in *MasterSpec) DeepCopy() *MasterSpec { + if in == nil { + return nil + } + out := new(MasterSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PserverSpec) DeepCopyInto(out *PserverSpec) { + *out = *in + in.Resources.DeepCopyInto(&out.Resources) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PserverSpec. +func (in *PserverSpec) DeepCopy() *PserverSpec { + if in == nil { + return nil + } + out := new(PserverSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TrainerJobScaleStatus) DeepCopyInto(out *TrainerJobScaleStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TrainerJobScaleStatus. +func (in *TrainerJobScaleStatus) DeepCopy() *TrainerJobScaleStatus { + if in == nil { + return nil + } + out := new(TrainerJobScaleStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TrainerSpec) DeepCopyInto(out *TrainerSpec) { + *out = *in + in.Resources.DeepCopyInto(&out.Resources) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TrainerSpec. +func (in *TrainerSpec) DeepCopy() *TrainerSpec { + if in == nil { + return nil + } + out := new(TrainerSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TrainingJob) DeepCopyInto(out *TrainingJob) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TrainingJob. +func (in *TrainingJob) DeepCopy() *TrainingJob { + if in == nil { + return nil + } + out := new(TrainingJob) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *TrainingJob) 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 *TrainingJobList) DeepCopyInto(out *TrainingJobList) { + *out = *in + out.TypeMeta = in.TypeMeta + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]TrainingJob, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TrainingJobList. +func (in *TrainingJobList) DeepCopy() *TrainingJobList { + if in == nil { + return nil + } + out := new(TrainingJobList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *TrainingJobList) 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 *TrainingJobSpec) DeepCopyInto(out *TrainingJobSpec) { + *out = *in + if in.Volumes != nil { + in, out := &in.Volumes, &out.Volumes + *out = make([]v1.Volume, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.VolumeMounts != nil { + in, out := &in.VolumeMounts, &out.VolumeMounts + *out = make([]v1.VolumeMount, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + in.Master.DeepCopyInto(&out.Master) + in.Pserver.DeepCopyInto(&out.Pserver) + in.Trainer.DeepCopyInto(&out.Trainer) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TrainingJobSpec. +func (in *TrainingJobSpec) DeepCopy() *TrainingJobSpec { + if in == nil { + return nil + } + out := new(TrainingJobSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TrainingJobStatus) DeepCopyInto(out *TrainingJobStatus) { + *out = *in + out.ScaleStatus = in.ScaleStatus + if in.ReplicaStatuses != nil { + in, out := &in.ReplicaStatuses, &out.ReplicaStatuses + *out = make([]*TrainingResourceStatus, len(*in)) + for i := range *in { + if (*in)[i] == nil { + (*out)[i] = nil + } else { + (*out)[i] = new(TrainingResourceStatus) + (*in)[i].DeepCopyInto((*out)[i]) + } + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TrainingJobStatus. +func (in *TrainingJobStatus) DeepCopy() *TrainingJobStatus { + if in == nil { + return nil + } + out := new(TrainingJobStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TrainingResourceStatus) DeepCopyInto(out *TrainingResourceStatus) { + *out = *in + if in.ResourceStates != nil { + in, out := &in.ResourceStates, &out.ResourceStates + *out = make(map[ResourceState]int, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TrainingResourceStatus. +func (in *TrainingResourceStatus) DeepCopy() *TrainingResourceStatus { + if in == nil { + return nil + } + out := new(TrainingResourceStatus) + in.DeepCopyInto(out) + return out +} diff --git a/go/pkg/client/clientset/versioned/clientset.go b/go/pkg/client/clientset/versioned/clientset.go new file mode 100644 index 00000000..681029dc --- /dev/null +++ b/go/pkg/client/clientset/versioned/clientset.go @@ -0,0 +1,97 @@ +/* +Copyright (c) 2016 PaddlePaddle Authors All Rights Reserve. + +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 ( + paddlepaddlev1alpha1 "github.com/PaddlePaddle/cloud/go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1" + glog "github.com/golang/glog" + discovery "k8s.io/client-go/discovery" + rest "k8s.io/client-go/rest" + flowcontrol "k8s.io/client-go/util/flowcontrol" +) + +type Interface interface { + Discovery() discovery.DiscoveryInterface + PaddlepaddleV1alpha1() paddlepaddlev1alpha1.PaddlepaddleV1alpha1Interface + // Deprecated: please explicitly pick a version if possible. + Paddlepaddle() paddlepaddlev1alpha1.PaddlepaddleV1alpha1Interface +} + +// Clientset contains the clients for groups. Each group has exactly one +// version included in a Clientset. +type Clientset struct { + *discovery.DiscoveryClient + paddlepaddleV1alpha1 *paddlepaddlev1alpha1.PaddlepaddleV1alpha1Client +} + +// PaddlepaddleV1alpha1 retrieves the PaddlepaddleV1alpha1Client +func (c *Clientset) PaddlepaddleV1alpha1() paddlepaddlev1alpha1.PaddlepaddleV1alpha1Interface { + return c.paddlepaddleV1alpha1 +} + +// Deprecated: Paddlepaddle retrieves the default version of PaddlepaddleClient. +// Please explicitly pick a version. +func (c *Clientset) Paddlepaddle() paddlepaddlev1alpha1.PaddlepaddleV1alpha1Interface { + return c.paddlepaddleV1alpha1 +} + +// 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.paddlepaddleV1alpha1, err = paddlepaddlev1alpha1.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.paddlepaddleV1alpha1 = paddlepaddlev1alpha1.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.paddlepaddleV1alpha1 = paddlepaddlev1alpha1.New(c) + + cs.DiscoveryClient = discovery.NewDiscoveryClient(c) + return &cs +} diff --git a/go/pkg/client/clientset/versioned/doc.go b/go/pkg/client/clientset/versioned/doc.go new file mode 100644 index 00000000..a63e1517 --- /dev/null +++ b/go/pkg/client/clientset/versioned/doc.go @@ -0,0 +1,20 @@ +/* +Copyright (c) 2016 PaddlePaddle Authors All Rights Reserve. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// This package is generated by client-gen with custom arguments. + +// This package has the automatically generated clientset. +package versioned diff --git a/go/pkg/client/clientset/versioned/fake/clientset_generated.go b/go/pkg/client/clientset/versioned/fake/clientset_generated.go new file mode 100644 index 00000000..0dbf7091 --- /dev/null +++ b/go/pkg/client/clientset/versioned/fake/clientset_generated.go @@ -0,0 +1,70 @@ +/* +Copyright (c) 2016 PaddlePaddle Authors All Rights Reserve. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package fake + +import ( + clientset "github.com/PaddlePaddle/cloud/go/pkg/client/clientset/versioned" + paddlepaddlev1alpha1 "github.com/PaddlePaddle/cloud/go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1" + fakepaddlepaddlev1alpha1 "github.com/PaddlePaddle/cloud/go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/fake" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/discovery" + fakediscovery "k8s.io/client-go/discovery/fake" + "k8s.io/client-go/testing" +) + +// NewSimpleClientset returns a clientset that will respond with the provided objects. +// It's backed by a very simple object tracker that processes creates, updates and deletions as-is, +// without applying any validations and/or defaults. It shouldn't be considered a replacement +// for a real clientset and is mostly useful in simple unit tests. +func NewSimpleClientset(objects ...runtime.Object) *Clientset { + o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) + for _, obj := range objects { + if err := o.Add(obj); err != nil { + panic(err) + } + } + + fakePtr := testing.Fake{} + fakePtr.AddReactor("*", "*", testing.ObjectReaction(o)) + fakePtr.AddWatchReactor("*", testing.DefaultWatchReactor(watch.NewFake(), nil)) + + return &Clientset{fakePtr, &fakediscovery.FakeDiscovery{Fake: &fakePtr}} +} + +// Clientset implements clientset.Interface. Meant to be embedded into a +// struct to get a default implementation. This makes faking out just the method +// you want to test easier. +type Clientset struct { + testing.Fake + discovery *fakediscovery.FakeDiscovery +} + +func (c *Clientset) Discovery() discovery.DiscoveryInterface { + return c.discovery +} + +var _ clientset.Interface = &Clientset{} + +// PaddlepaddleV1alpha1 retrieves the PaddlepaddleV1alpha1Client +func (c *Clientset) PaddlepaddleV1alpha1() paddlepaddlev1alpha1.PaddlepaddleV1alpha1Interface { + return &fakepaddlepaddlev1alpha1.FakePaddlepaddleV1alpha1{Fake: &c.Fake} +} + +// Paddlepaddle retrieves the PaddlepaddleV1alpha1Client +func (c *Clientset) Paddlepaddle() paddlepaddlev1alpha1.PaddlepaddleV1alpha1Interface { + return &fakepaddlepaddlev1alpha1.FakePaddlepaddleV1alpha1{Fake: &c.Fake} +} diff --git a/go/pkg/client/clientset/versioned/fake/doc.go b/go/pkg/client/clientset/versioned/fake/doc.go new file mode 100644 index 00000000..16ddbc99 --- /dev/null +++ b/go/pkg/client/clientset/versioned/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright (c) 2016 PaddlePaddle Authors All Rights Reserve. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// This package is generated by client-gen with custom arguments. + +// This package has the automatically generated fake clientset. +package fake diff --git a/go/pkg/client/clientset/versioned/fake/register.go b/go/pkg/client/clientset/versioned/fake/register.go new file mode 100644 index 00000000..93a12b11 --- /dev/null +++ b/go/pkg/client/clientset/versioned/fake/register.go @@ -0,0 +1,52 @@ +/* +Copyright (c) 2016 PaddlePaddle Authors All Rights Reserve. + +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 ( + paddlepaddlev1alpha1 "github.com/PaddlePaddle/cloud/go/pkg/apis/paddlepaddle/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" +) + +var scheme = runtime.NewScheme() +var codecs = serializer.NewCodecFactory(scheme) +var parameterCodec = runtime.NewParameterCodec(scheme) + +func init() { + v1.AddToGroupVersion(scheme, schema.GroupVersion{Version: "v1"}) + AddToScheme(scheme) +} + +// AddToScheme adds all types of this clientset into the given scheme. This allows composition +// of clientsets, like in: +// +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kuberentes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) +// +// kclientset, _ := kubernetes.NewForConfig(c) +// aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// +// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types +// correctly. +func AddToScheme(scheme *runtime.Scheme) { + paddlepaddlev1alpha1.AddToScheme(scheme) + +} diff --git a/go/pkg/client/clientset/versioned/scheme/doc.go b/go/pkg/client/clientset/versioned/scheme/doc.go new file mode 100644 index 00000000..1894e4ab --- /dev/null +++ b/go/pkg/client/clientset/versioned/scheme/doc.go @@ -0,0 +1,20 @@ +/* +Copyright (c) 2016 PaddlePaddle Authors All Rights Reserve. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// This package is generated by client-gen with custom arguments. + +// This package contains the scheme of the automatically generated clientset. +package scheme diff --git a/go/pkg/client/clientset/versioned/scheme/register.go b/go/pkg/client/clientset/versioned/scheme/register.go new file mode 100644 index 00000000..582bd4d5 --- /dev/null +++ b/go/pkg/client/clientset/versioned/scheme/register.go @@ -0,0 +1,52 @@ +/* +Copyright (c) 2016 PaddlePaddle Authors All Rights Reserve. + +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 ( + paddlepaddlev1alpha1 "github.com/PaddlePaddle/cloud/go/pkg/apis/paddlepaddle/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" +) + +var Scheme = runtime.NewScheme() +var Codecs = serializer.NewCodecFactory(Scheme) +var ParameterCodec = runtime.NewParameterCodec(Scheme) + +func init() { + v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) + AddToScheme(Scheme) +} + +// AddToScheme adds all types of this clientset into the given scheme. This allows composition +// of clientsets, like in: +// +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kuberentes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) +// +// kclientset, _ := kubernetes.NewForConfig(c) +// aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// +// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types +// correctly. +func AddToScheme(scheme *runtime.Scheme) { + paddlepaddlev1alpha1.AddToScheme(scheme) + +} diff --git a/go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/doc.go b/go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/doc.go new file mode 100644 index 00000000..e8b00e03 --- /dev/null +++ b/go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/doc.go @@ -0,0 +1,20 @@ +/* +Copyright (c) 2016 PaddlePaddle Authors All Rights Reserve. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// This package is generated by client-gen with custom arguments. + +// This package has the automatically generated typed clients. +package v1alpha1 diff --git a/go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/fake/doc.go b/go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/fake/doc.go new file mode 100644 index 00000000..36c0c31a --- /dev/null +++ b/go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright (c) 2016 PaddlePaddle Authors All Rights Reserve. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// This package is generated by client-gen with custom arguments. + +// Package fake has the automatically generated clients. +package fake diff --git a/go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/fake/fake_paddlepaddle_client.go b/go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/fake/fake_paddlepaddle_client.go new file mode 100644 index 00000000..7a78e2be --- /dev/null +++ b/go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/fake/fake_paddlepaddle_client.go @@ -0,0 +1,37 @@ +/* +Copyright (c) 2016 PaddlePaddle Authors All Rights Reserve. + +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 ( + v1alpha1 "github.com/PaddlePaddle/cloud/go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1" + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" +) + +type FakePaddlepaddleV1alpha1 struct { + *testing.Fake +} + +func (c *FakePaddlepaddleV1alpha1) TrainingJobs(namespace string) v1alpha1.TrainingJobInterface { + return &FakeTrainingJobs{c, namespace} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakePaddlepaddleV1alpha1) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/fake/fake_trainingjob.go b/go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/fake/fake_trainingjob.go new file mode 100644 index 00000000..675b87a2 --- /dev/null +++ b/go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/fake/fake_trainingjob.go @@ -0,0 +1,125 @@ +/* +Copyright (c) 2016 PaddlePaddle Authors All Rights Reserve. + +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 ( + v1alpha1 "github.com/PaddlePaddle/cloud/go/pkg/apis/paddlepaddle/v1alpha1" + 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" +) + +// FakeTrainingJobs implements TrainingJobInterface +type FakeTrainingJobs struct { + Fake *FakePaddlepaddleV1alpha1 + ns string +} + +var trainingjobsResource = schema.GroupVersionResource{Group: "paddlepaddle.org", Version: "v1alpha1", Resource: "trainingjobs"} + +var trainingjobsKind = schema.GroupVersionKind{Group: "paddlepaddle.org", Version: "v1alpha1", Kind: "TrainingJob"} + +// Get takes name of the trainingJob, and returns the corresponding trainingJob object, and an error if there is any. +func (c *FakeTrainingJobs) Get(name string, options v1.GetOptions) (result *v1alpha1.TrainingJob, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(trainingjobsResource, c.ns, name), &v1alpha1.TrainingJob{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.TrainingJob), err +} + +// List takes label and field selectors, and returns the list of TrainingJobs that match those selectors. +func (c *FakeTrainingJobs) List(opts v1.ListOptions) (result *v1alpha1.TrainingJobList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(trainingjobsResource, trainingjobsKind, c.ns, opts), &v1alpha1.TrainingJobList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.TrainingJobList{} + for _, item := range obj.(*v1alpha1.TrainingJobList).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 trainingJobs. +func (c *FakeTrainingJobs) Watch(opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(trainingjobsResource, c.ns, opts)) + +} + +// Create takes the representation of a trainingJob and creates it. Returns the server's representation of the trainingJob, and an error, if there is any. +func (c *FakeTrainingJobs) Create(trainingJob *v1alpha1.TrainingJob) (result *v1alpha1.TrainingJob, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(trainingjobsResource, c.ns, trainingJob), &v1alpha1.TrainingJob{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.TrainingJob), err +} + +// Update takes the representation of a trainingJob and updates it. Returns the server's representation of the trainingJob, and an error, if there is any. +func (c *FakeTrainingJobs) Update(trainingJob *v1alpha1.TrainingJob) (result *v1alpha1.TrainingJob, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(trainingjobsResource, c.ns, trainingJob), &v1alpha1.TrainingJob{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.TrainingJob), err +} + +// Delete takes name of the trainingJob and deletes it. Returns an error if one occurs. +func (c *FakeTrainingJobs) Delete(name string, options *v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteAction(trainingjobsResource, c.ns, name), &v1alpha1.TrainingJob{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeTrainingJobs) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(trainingjobsResource, c.ns, listOptions) + + _, err := c.Fake.Invokes(action, &v1alpha1.TrainingJobList{}) + return err +} + +// Patch applies the patch and returns the patched trainingJob. +func (c *FakeTrainingJobs) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.TrainingJob, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(trainingjobsResource, c.ns, name, data, subresources...), &v1alpha1.TrainingJob{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.TrainingJob), err +} diff --git a/go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/generated_expansion.go b/go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/generated_expansion.go new file mode 100644 index 00000000..8a87af6b --- /dev/null +++ b/go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/generated_expansion.go @@ -0,0 +1,18 @@ +/* +Copyright (c) 2016 PaddlePaddle Authors All Rights Reserve. + +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 TrainingJobExpansion interface{} diff --git a/go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/paddlepaddle_client.go b/go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/paddlepaddle_client.go new file mode 100644 index 00000000..0ff10989 --- /dev/null +++ b/go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/paddlepaddle_client.go @@ -0,0 +1,87 @@ +/* +Copyright (c) 2016 PaddlePaddle Authors All Rights Reserve. + +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 ( + v1alpha1 "github.com/PaddlePaddle/cloud/go/pkg/apis/paddlepaddle/v1alpha1" + "github.com/PaddlePaddle/cloud/go/pkg/client/clientset/versioned/scheme" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + rest "k8s.io/client-go/rest" +) + +type PaddlepaddleV1alpha1Interface interface { + RESTClient() rest.Interface + TrainingJobsGetter +} + +// PaddlepaddleV1alpha1Client is used to interact with features provided by the paddlepaddle.org group. +type PaddlepaddleV1alpha1Client struct { + restClient rest.Interface +} + +func (c *PaddlepaddleV1alpha1Client) TrainingJobs(namespace string) TrainingJobInterface { + return newTrainingJobs(c, namespace) +} + +// NewForConfig creates a new PaddlepaddleV1alpha1Client for the given config. +func NewForConfig(c *rest.Config) (*PaddlepaddleV1alpha1Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + client, err := rest.RESTClientFor(&config) + if err != nil { + return nil, err + } + return &PaddlepaddleV1alpha1Client{client}, nil +} + +// NewForConfigOrDie creates a new PaddlepaddleV1alpha1Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *PaddlepaddleV1alpha1Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new PaddlepaddleV1alpha1Client for the given RESTClient. +func New(c rest.Interface) *PaddlepaddleV1alpha1Client { + return &PaddlepaddleV1alpha1Client{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 *PaddlepaddleV1alpha1Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/trainingjob.go b/go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/trainingjob.go new file mode 100644 index 00000000..0b39a211 --- /dev/null +++ b/go/pkg/client/clientset/versioned/typed/paddlepaddle/v1alpha1/trainingjob.go @@ -0,0 +1,154 @@ +/* +Copyright (c) 2016 PaddlePaddle Authors All Rights Reserve. + +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 ( + v1alpha1 "github.com/PaddlePaddle/cloud/go/pkg/apis/paddlepaddle/v1alpha1" + scheme "github.com/PaddlePaddle/cloud/go/pkg/client/clientset/versioned/scheme" + 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" +) + +// TrainingJobsGetter has a method to return a TrainingJobInterface. +// A group's client should implement this interface. +type TrainingJobsGetter interface { + TrainingJobs(namespace string) TrainingJobInterface +} + +// TrainingJobInterface has methods to work with TrainingJob resources. +type TrainingJobInterface interface { + Create(*v1alpha1.TrainingJob) (*v1alpha1.TrainingJob, error) + Update(*v1alpha1.TrainingJob) (*v1alpha1.TrainingJob, error) + Delete(name string, options *v1.DeleteOptions) error + DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error + Get(name string, options v1.GetOptions) (*v1alpha1.TrainingJob, error) + List(opts v1.ListOptions) (*v1alpha1.TrainingJobList, error) + Watch(opts v1.ListOptions) (watch.Interface, error) + Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.TrainingJob, err error) + TrainingJobExpansion +} + +// trainingJobs implements TrainingJobInterface +type trainingJobs struct { + client rest.Interface + ns string +} + +// newTrainingJobs returns a TrainingJobs +func newTrainingJobs(c *PaddlepaddleV1alpha1Client, namespace string) *trainingJobs { + return &trainingJobs{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the trainingJob, and returns the corresponding trainingJob object, and an error if there is any. +func (c *trainingJobs) Get(name string, options v1.GetOptions) (result *v1alpha1.TrainingJob, err error) { + result = &v1alpha1.TrainingJob{} + err = c.client.Get(). + Namespace(c.ns). + Resource("trainingjobs"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of TrainingJobs that match those selectors. +func (c *trainingJobs) List(opts v1.ListOptions) (result *v1alpha1.TrainingJobList, err error) { + result = &v1alpha1.TrainingJobList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("trainingjobs"). + VersionedParams(&opts, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested trainingJobs. +func (c *trainingJobs) Watch(opts v1.ListOptions) (watch.Interface, error) { + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("trainingjobs"). + VersionedParams(&opts, scheme.ParameterCodec). + Watch() +} + +// Create takes the representation of a trainingJob and creates it. Returns the server's representation of the trainingJob, and an error, if there is any. +func (c *trainingJobs) Create(trainingJob *v1alpha1.TrainingJob) (result *v1alpha1.TrainingJob, err error) { + result = &v1alpha1.TrainingJob{} + err = c.client.Post(). + Namespace(c.ns). + Resource("trainingjobs"). + Body(trainingJob). + Do(). + Into(result) + return +} + +// Update takes the representation of a trainingJob and updates it. Returns the server's representation of the trainingJob, and an error, if there is any. +func (c *trainingJobs) Update(trainingJob *v1alpha1.TrainingJob) (result *v1alpha1.TrainingJob, err error) { + result = &v1alpha1.TrainingJob{} + err = c.client.Put(). + Namespace(c.ns). + Resource("trainingjobs"). + Name(trainingJob.Name). + Body(trainingJob). + Do(). + Into(result) + return +} + +// Delete takes name of the trainingJob and deletes it. Returns an error if one occurs. +func (c *trainingJobs) Delete(name string, options *v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("trainingjobs"). + Name(name). + Body(options). + Do(). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *trainingJobs) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("trainingjobs"). + VersionedParams(&listOptions, scheme.ParameterCodec). + Body(options). + Do(). + Error() +} + +// Patch applies the patch and returns the patched trainingJob. +func (c *trainingJobs) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.TrainingJob, err error) { + result = &v1alpha1.TrainingJob{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("trainingjobs"). + SubResource(subresources...). + Name(name). + Body(data). + Do(). + Into(result) + return +} diff --git a/go/pkg/client/informers/externalversions/factory.go b/go/pkg/client/informers/externalversions/factory.go new file mode 100644 index 00000000..22a1afbd --- /dev/null +++ b/go/pkg/client/informers/externalversions/factory.go @@ -0,0 +1,118 @@ +/* +Copyright (c) 2016 PaddlePaddle Authors All Rights Reserve. + +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 ( + versioned "github.com/PaddlePaddle/cloud/go/pkg/client/clientset/versioned" + internalinterfaces "github.com/PaddlePaddle/cloud/go/pkg/client/informers/externalversions/internalinterfaces" + paddlepaddle "github.com/PaddlePaddle/cloud/go/pkg/client/informers/externalversions/paddlepaddle" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" + reflect "reflect" + sync "sync" + time "time" +) + +type sharedInformerFactory struct { + client versioned.Interface + 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 &sharedInformerFactory{ + client: client, + 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 + + Paddlepaddle() paddlepaddle.Interface +} + +func (f *sharedInformerFactory) Paddlepaddle() paddlepaddle.Interface { + return paddlepaddle.New(f) +} diff --git a/go/pkg/client/informers/externalversions/generic.go b/go/pkg/client/informers/externalversions/generic.go new file mode 100644 index 00000000..f074d0da --- /dev/null +++ b/go/pkg/client/informers/externalversions/generic.go @@ -0,0 +1,61 @@ +/* +Copyright (c) 2016 PaddlePaddle Authors All Rights Reserve. + +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" + v1alpha1 "github.com/PaddlePaddle/cloud/go/pkg/apis/paddlepaddle/v1alpha1" + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" +) + +// 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=Paddlepaddle, Version=V1alpha1 + case v1alpha1.SchemeGroupVersion.WithResource("trainingjobs"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Paddlepaddle().V1alpha1().TrainingJobs().Informer()}, nil + + } + + return nil, fmt.Errorf("no informer found for %v", resource) +} diff --git a/go/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go b/go/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go new file mode 100644 index 00000000..5f4683cb --- /dev/null +++ b/go/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -0,0 +1,34 @@ +/* +Copyright (c) 2016 PaddlePaddle Authors All Rights Reserve. + +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 ( + versioned "github.com/PaddlePaddle/cloud/go/pkg/client/clientset/versioned" + runtime "k8s.io/apimachinery/pkg/runtime" + cache "k8s.io/client-go/tools/cache" + 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 +} diff --git a/go/pkg/client/informers/externalversions/paddlepaddle/interface.go b/go/pkg/client/informers/externalversions/paddlepaddle/interface.go new file mode 100644 index 00000000..e72bd7ea --- /dev/null +++ b/go/pkg/client/informers/externalversions/paddlepaddle/interface.go @@ -0,0 +1,44 @@ +/* +Copyright (c) 2016 PaddlePaddle Authors All Rights Reserve. + +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 paddlepaddle + +import ( + internalinterfaces "github.com/PaddlePaddle/cloud/go/pkg/client/informers/externalversions/internalinterfaces" + v1alpha1 "github.com/PaddlePaddle/cloud/go/pkg/client/informers/externalversions/paddlepaddle/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 { + internalinterfaces.SharedInformerFactory +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory) Interface { + return &group{f} +} + +// V1alpha1 returns a new v1alpha1.Interface. +func (g *group) V1alpha1() v1alpha1.Interface { + return v1alpha1.New(g.SharedInformerFactory) +} diff --git a/go/pkg/client/informers/externalversions/paddlepaddle/v1alpha1/interface.go b/go/pkg/client/informers/externalversions/paddlepaddle/v1alpha1/interface.go new file mode 100644 index 00000000..270a3312 --- /dev/null +++ b/go/pkg/client/informers/externalversions/paddlepaddle/v1alpha1/interface.go @@ -0,0 +1,43 @@ +/* +Copyright (c) 2016 PaddlePaddle Authors All Rights Reserve. + +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 "github.com/PaddlePaddle/cloud/go/pkg/client/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // TrainingJobs returns a TrainingJobInformer. + TrainingJobs() TrainingJobInformer +} + +type version struct { + internalinterfaces.SharedInformerFactory +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory) Interface { + return &version{f} +} + +// TrainingJobs returns a TrainingJobInformer. +func (v *version) TrainingJobs() TrainingJobInformer { + return &trainingJobInformer{factory: v.SharedInformerFactory} +} diff --git a/go/pkg/client/informers/externalversions/paddlepaddle/v1alpha1/trainingjob.go b/go/pkg/client/informers/externalversions/paddlepaddle/v1alpha1/trainingjob.go new file mode 100644 index 00000000..10375bbd --- /dev/null +++ b/go/pkg/client/informers/externalversions/paddlepaddle/v1alpha1/trainingjob.go @@ -0,0 +1,73 @@ +/* +Copyright (c) 2016 PaddlePaddle Authors All Rights Reserve. + +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 ( + paddlepaddle_v1alpha1 "github.com/PaddlePaddle/cloud/go/pkg/apis/paddlepaddle/v1alpha1" + versioned "github.com/PaddlePaddle/cloud/go/pkg/client/clientset/versioned" + internalinterfaces "github.com/PaddlePaddle/cloud/go/pkg/client/informers/externalversions/internalinterfaces" + v1alpha1 "github.com/PaddlePaddle/cloud/go/pkg/client/listers/paddlepaddle/v1alpha1" + 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" + time "time" +) + +// TrainingJobInformer provides access to a shared informer and lister for +// TrainingJobs. +type TrainingJobInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.TrainingJobLister +} + +type trainingJobInformer struct { + factory internalinterfaces.SharedInformerFactory +} + +// NewTrainingJobInformer constructs a new informer for TrainingJob 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 NewTrainingJobInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + return client.PaddlepaddleV1alpha1().TrainingJobs(namespace).List(options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + return client.PaddlepaddleV1alpha1().TrainingJobs(namespace).Watch(options) + }, + }, + &paddlepaddle_v1alpha1.TrainingJob{}, + resyncPeriod, + indexers, + ) +} + +func defaultTrainingJobInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewTrainingJobInformer(client, v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) +} + +func (f *trainingJobInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&paddlepaddle_v1alpha1.TrainingJob{}, defaultTrainingJobInformer) +} + +func (f *trainingJobInformer) Lister() v1alpha1.TrainingJobLister { + return v1alpha1.NewTrainingJobLister(f.Informer().GetIndexer()) +} diff --git a/go/pkg/client/listers/paddlepaddle/v1alpha1/expansion_generated.go b/go/pkg/client/listers/paddlepaddle/v1alpha1/expansion_generated.go new file mode 100644 index 00000000..0d1dd311 --- /dev/null +++ b/go/pkg/client/listers/paddlepaddle/v1alpha1/expansion_generated.go @@ -0,0 +1,27 @@ +/* +Copyright (c) 2016 PaddlePaddle Authors All Rights Reserve. + +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 + +// TrainingJobListerExpansion allows custom methods to be added to +// TrainingJobLister. +type TrainingJobListerExpansion interface{} + +// TrainingJobNamespaceListerExpansion allows custom methods to be added to +// TrainingJobNamespaceLister. +type TrainingJobNamespaceListerExpansion interface{} diff --git a/go/pkg/client/listers/paddlepaddle/v1alpha1/trainingjob.go b/go/pkg/client/listers/paddlepaddle/v1alpha1/trainingjob.go new file mode 100644 index 00000000..3ac400dd --- /dev/null +++ b/go/pkg/client/listers/paddlepaddle/v1alpha1/trainingjob.go @@ -0,0 +1,94 @@ +/* +Copyright (c) 2016 PaddlePaddle Authors All Rights Reserve. + +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 ( + v1alpha1 "github.com/PaddlePaddle/cloud/go/pkg/apis/paddlepaddle/v1alpha1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// TrainingJobLister helps list TrainingJobs. +type TrainingJobLister interface { + // List lists all TrainingJobs in the indexer. + List(selector labels.Selector) (ret []*v1alpha1.TrainingJob, err error) + // TrainingJobs returns an object that can list and get TrainingJobs. + TrainingJobs(namespace string) TrainingJobNamespaceLister + TrainingJobListerExpansion +} + +// trainingJobLister implements the TrainingJobLister interface. +type trainingJobLister struct { + indexer cache.Indexer +} + +// NewTrainingJobLister returns a new TrainingJobLister. +func NewTrainingJobLister(indexer cache.Indexer) TrainingJobLister { + return &trainingJobLister{indexer: indexer} +} + +// List lists all TrainingJobs in the indexer. +func (s *trainingJobLister) List(selector labels.Selector) (ret []*v1alpha1.TrainingJob, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.TrainingJob)) + }) + return ret, err +} + +// TrainingJobs returns an object that can list and get TrainingJobs. +func (s *trainingJobLister) TrainingJobs(namespace string) TrainingJobNamespaceLister { + return trainingJobNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// TrainingJobNamespaceLister helps list and get TrainingJobs. +type TrainingJobNamespaceLister interface { + // List lists all TrainingJobs in the indexer for a given namespace. + List(selector labels.Selector) (ret []*v1alpha1.TrainingJob, err error) + // Get retrieves the TrainingJob from the indexer for a given namespace and name. + Get(name string) (*v1alpha1.TrainingJob, error) + TrainingJobNamespaceListerExpansion +} + +// trainingJobNamespaceLister implements the TrainingJobNamespaceLister +// interface. +type trainingJobNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all TrainingJobs in the indexer for a given namespace. +func (s trainingJobNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.TrainingJob, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.TrainingJob)) + }) + return ret, err +} + +// Get retrieves the TrainingJob from the indexer for a given namespace and name. +func (s trainingJobNamespaceLister) Get(name string) (*v1alpha1.TrainingJob, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("trainingjob"), name) + } + return obj.(*v1alpha1.TrainingJob), nil +} diff --git a/go/pkg/controller/controller.go b/go/pkg/controller/controller.go new file mode 100644 index 00000000..e9e722dc --- /dev/null +++ b/go/pkg/controller/controller.go @@ -0,0 +1,248 @@ +package controller + +import ( + "fmt" + "time" + + "github.com/golang/glog" + + corev1 "k8s.io/api/core/v1" + apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" + apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" + apierrors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/runtime" + "k8s.io/apimachinery/pkg/util/wait" + "k8s.io/client-go/kubernetes" + "k8s.io/client-go/kubernetes/scheme" + typedcorev1 "k8s.io/client-go/kubernetes/typed/core/v1" + "k8s.io/client-go/tools/cache" + "k8s.io/client-go/tools/record" + "k8s.io/client-go/util/workqueue" + + paddlev1alpha1 "github.com/PaddlePaddle/cloud/go/pkg/apis/paddlepaddle/v1alpha1" + paddleclientset "github.com/PaddlePaddle/cloud/go/pkg/client/clientset/versioned" + paddlescheme "github.com/PaddlePaddle/cloud/go/pkg/client/clientset/versioned/scheme" + paddleinformers "github.com/PaddlePaddle/cloud/go/pkg/client/informers/externalversions" + paddlelisters "github.com/PaddlePaddle/cloud/go/pkg/client/listers/paddlepaddle/v1alpha1" +) + +type Controller struct { + // KubeCli is a standard kubernetes clientset + KubeCli kubernetes.Interface + // ApiCli is the extension kubernetes clientset + ApiCli apiextensionsclient.Interface + // PaddleCli is a clientset for our own API group + PaddleCli paddleclientset.Interface + + trainingjobLister paddlelisters.TrainingJobLister + trainingjobSynced cache.InformerSynced + + // TODO jobtracker keep track of every training job + jobtracker map[string]interface{} + + // workqueue is a rate limited work queue. This is used to queue work to be + // processed instead of performing it as soon as a change happens. + workqueue workqueue.RateLimitingInterface + // recorder is an event recorder for recording Event resources to the + // Kubernetes API. + recorder record.EventRecorder +} + +func New( + kubeCli kubernetes.Interface, + apiCli apiextensionsclient.Interface, + paddleCli paddleclientset.Interface, + tjInformer paddleinformers.SharedInformerFactory) *Controller { + + traingingjobInformer := tjInformer.Paddlepaddle().V1alpha1().TrainingJobs() + + paddlescheme.AddToScheme(scheme.Scheme) + glog.V(4).Info("Creating trainingjob event broadcaster") + eventtBroadcaster := record.NewBroadcaster() + eventtBroadcaster.StartLogging(glog.Infof) + eventtBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: kubeCli.CoreV1().Events("")}) + recorder := eventtBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: "TrainingJobController"}) + + controller := &Controller{ + KubeCli: kubeCli, + ApiCli: apiCli, + PaddleCli: paddleCli, + trainingjobLister: traingingjobInformer.Lister(), + trainingjobSynced: traingingjobInformer.Informer().HasSynced, + jobtracker: make(map[string]interface{}, 0), + workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "TrainingJob"), + recorder: recorder, + } + + glog.Info("Setting up event handlers") + traingingjobInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ + AddFunc: controller.enqueue, + UpdateFunc: func(oldObj, newObj interface{}) { + oldTj := oldObj.(*paddlev1alpha1.TrainingJob) + newTj := newObj.(*paddlev1alpha1.TrainingJob) + if oldTj.ResourceVersion == newTj.ResourceVersion { + glog.V(4).Infof("same resourceversion for training job %s/%s, skipped", oldTj.Namespace, oldTj.Name) + return + } + glog.V(4).Infof("resourceversion for training job %s/%s updated", oldTj.Namespace, oldTj.Name) + controller.enqueue(newObj) + }, + DeleteFunc: controller.dequeue, + }) + + return controller +} + +// Run will set up the event handlers for trainingjob, as well as syncing +// informer caches and starting workers. It will block until stopCh +// is closed, at which point it will shutdown the workqueue and wait for +// workers to finish processing their current work items. +func (c *Controller) Run(threadiness int, stopCh <-chan struct{}) error { + // TODO add a lock to ensure there is only one controller in the cluster + defer runtime.HandleCrash() + defer c.workqueue.ShutDown() + + glog.Info("Starting trainingjob controller") + glog.Info("Starting to create custom resource definition") + + if err := c.createCRD(); err != nil { + return fmt.Errorf("failed to create kind TrainingJob: %v", err) + } + + glog.Info("Waiting for informer caches to sync") + if ok := cache.WaitForCacheSync(stopCh, c.trainingjobSynced); !ok { + return fmt.Errorf("failed to wait for caches to sync") + } + + glog.Info("Starting workers") + for i := 0; i < threadiness; i++ { + go wait.Until(c.runWorker, time.Second, stopCh) + } + + glog.Info("Started workers") + <-stopCh + glog.Info("Shutting down workers") + + return nil +} + +func (c *Controller) createCRD() error { + crd := &apiextensionsv1beta1.CustomResourceDefinition{ + ObjectMeta: metav1.ObjectMeta{ + Name: paddlev1alpha1.CRDName(), + }, + Spec: apiextensionsv1beta1.CustomResourceDefinitionSpec{ + Group: paddlev1alpha1.CRDGroup, + Version: paddlev1alpha1.CRDVersion, + Scope: apiextensionsv1beta1.NamespaceScoped, + Names: apiextensionsv1beta1.CustomResourceDefinitionNames{ + Kind: paddlev1alpha1.CRDKind, + Plural: paddlev1alpha1.CRDKindPlural, + ShortNames: []string{paddlev1alpha1.CRDShortName}, + }, + }, + } + + _, err := c.ApiCli.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd) + if err != nil && !apierrors.IsAlreadyExists(err) { + return err + } + + glog.Infof("CRD %s created", paddlev1alpha1.CRDName()) + + return nil +} + +// enqueue takes a TrainingJob resource and converts it into a namespace/name +// string which is then put onto the work queue. +func (c *Controller) enqueue(obj interface{}) { + var key string + var err error + if key, err = cache.MetaNamespaceKeyFunc(obj); err != nil { + runtime.HandleError(err) + return + } + glog.Infof("enqueue key: %v", key) + c.workqueue.AddRateLimited(key) +} + +func (c *Controller) dequeue(obj interface{}) { + job := obj.(*paddlev1alpha1.TrainingJob) + key := job.Namespace + "/" + job.Name + glog.Infof("dequeue key: %v", key) + if _, ok := c.jobtracker[key]; !ok { + glog.Warningf("unsafe state. %s was never created but we received delete event", key) + } + //c.jobtracker[key].Delete() + delete(c.jobtracker, key) +} + +func (c *Controller) runWorker() { + for c.processNestWorkItem() { + } +} + +func (c *Controller) processNestWorkItem() bool { + obj, shutdown := c.workqueue.Get() + + if shutdown { + return false + } + + err := func(obj interface{}) error { + defer c.workqueue.Done(obj) + var key string + var ok bool + if key, ok = obj.(string); !ok { + c.workqueue.Forget(obj) + runtime.HandleError(fmt.Errorf("expected string in workqueue but got %#v", obj)) + return nil + } + + if err := c.syncHandler(key); err != nil { + return fmt.Errorf("error syncing '%s': %s", key, err.Error()) + } + + c.workqueue.Forget(obj) + glog.Infof("Successfully synced '%s'", key) + return nil + }(obj) + + if err != nil { + runtime.HandleError(err) + return true + } + + return true +} + +func (c *Controller) syncHandler(key string) error { + glog.Infof("syncHandler, key: %s", key) + ns, name, err := cache.SplitMetaNamespaceKey(key) + if err != nil { + runtime.HandleError(fmt.Errorf("invalid resource key: %s", key)) + return nil + } + + job, createErr := c.trainingjobLister.TrainingJobs(ns).Get(name) + if createErr != nil { + glog.Errorf("get trainingjob error: %v", err) + if apierrors.IsNotFound(err) { + runtime.HandleError(fmt.Errorf("trainingjob '%s' in the work queue no longer exists", key)) + return nil + } + + return err + } + + _, ok := c.jobtracker[key] + if !ok { + glog.Infof("create a new job tracker, key: '%s'", key) + glog.Infof("received job: %+v", job) + // TODO create a tracker for the job, just record its name here + c.jobtracker[key] = job.Name + } + + return nil +} diff --git a/go/pkg/signals/signals.go b/go/pkg/signals/signals.go new file mode 100644 index 00000000..a62b2e5e --- /dev/null +++ b/go/pkg/signals/signals.go @@ -0,0 +1,30 @@ +package signals + +import ( + "os" + "os/signal" +) + +var ( + onlyOneSignalHandler = make(chan struct{}) + shutdownSignals = []os.Signal{os.Interrupt} +) + +// SetupSignalHandler registered for SIGTERM and SIGINT. A stop channel is returned +// which is closed on one of these signals. If a second signal is caught, the program +// is terminated with exit code 1. +func SetupSignalHandler() (stopCh <-chan struct{}) { + close(onlyOneSignalHandler) // panics when called twice + + stop := make(chan struct{}) + c := make(chan os.Signal, 2) + signal.Notify(c, shutdownSignals...) + go func() { + <-c + close(stop) + <-c + os.Exit(1) // second signal. Exit directly. + }() + + return stop +}