Skip to content

Commit

Permalink
add XGBoostJob API
Browse files Browse the repository at this point in the history
  • Loading branch information
zw0610 committed Jul 4, 2021
1 parent 476c700 commit c153e32
Show file tree
Hide file tree
Showing 20 changed files with 14,354 additions and 337 deletions.
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@ layout:
- go.kubebuilder.io/v3
projectName: tf-operator
repo: github.com/kubeflow/tf-operator
resources:
- api:
crdVersion: v1
namespaced: true
controller: true
group: kubeflow.org
kind: XGBoostJob
path: github.com/kubeflow/tf-operator/pkg/apis/xgboost/v1
version: v1
version: "3"
6,899 changes: 6,899 additions & 0 deletions config/crd/bases/kubeflow.org_tfjobs.yaml

Large diffs are not rendered by default.

6,889 changes: 6,889 additions & 0 deletions config/crd/bases/kubeflow.org_xgboostjobs.yaml

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This kustomization.yaml is not intended to be run by itself,
# since it depends on service name and namespace that are out of this kustomize package.
# It should be run by config/default
resources:
- bases/kubeflow.org_xgboostjobs.yaml
#+kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
#- patches/webhook_in_xgboostjobs.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
#- patches/cainjection_in_xgboostjobs.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
configurations:
- kustomizeconfig.yaml
19 changes: 19 additions & 0 deletions config/crd/kustomizeconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file is for teaching kustomize how to substitute name and namespace reference in CRD
nameReference:
- kind: Service
version: v1
fieldSpecs:
- kind: CustomResourceDefinition
version: v1
group: apiextensions.k8s.io
path: spec/conversion/webhook/clientConfig/service/name

namespace:
- kind: CustomResourceDefinition
version: v1
group: apiextensions.k8s.io
path: spec/conversion/webhook/clientConfig/service/namespace
create: false

varReference:
- path: metadata/annotations
7 changes: 7 additions & 0 deletions config/crd/patches/cainjection_in_xgboostjobs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# The following patch adds a directive for certmanager to inject CA into the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: xgboostjobs.kubeflow.org
14 changes: 14 additions & 0 deletions config/crd/patches/webhook_in_xgboostjobs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# The following patch enables a conversion webhook for the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: xgboostjobs.kubeflow.org
spec:
conversion:
strategy: Webhook
webhook:
clientConfig:
service:
namespace: system
name: webhook-service
path: /convert
24 changes: 24 additions & 0 deletions config/rbac/xgboostjob_editor_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# permissions for end users to edit xgboostjobs.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: xgboostjob-editor-role
rules:
- apiGroups:
- kubeflow.org
resources:
- xgboostjobs
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- kubeflow.org
resources:
- xgboostjobs/status
verbs:
- get
20 changes: 20 additions & 0 deletions config/rbac/xgboostjob_viewer_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# permissions for end users to view xgboostjobs.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: xgboostjob-viewer-role
rules:
- apiGroups:
- kubeflow.org
resources:
- xgboostjobs
verbs:
- get
- list
- watch
- apiGroups:
- kubeflow.org
resources:
- xgboostjobs/status
verbs:
- get
7 changes: 7 additions & 0 deletions config/samples/kubeflow.org_v1_xgboostjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: kubeflow.org/v1
kind: XGBoostJob
metadata:
name: xgboostjob-sample
spec:
# Add fields here
foo: bar
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ module github.com/kubeflow/tf-operator
go 1.14

require (
github.com/coreos/go-etcd v2.0.0+incompatible // indirect
github.com/cpuguy83/go-md2man v1.0.10 // indirect
github.com/go-logr/logr v0.3.0
github.com/go-openapi/spec v0.19.3
github.com/kubeflow/common v0.3.3
github.com/onrik/logrus v0.2.2-0.20181225141908-a09d5cdcdc62
github.com/onsi/ginkgo v1.14.1
github.com/onsi/gomega v1.10.2
github.com/prometheus/client_golang v1.7.1
github.com/sirupsen/logrus v1.6.0
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8 // indirect
k8s.io/api v0.19.2
k8s.io/apiextensions-apiserver v0.19.2
k8s.io/apimachinery v0.19.2
Expand All @@ -19,6 +19,5 @@ require (
k8s.io/klog v1.0.0
k8s.io/kube-openapi v0.0.0-20200805222855-6aeccd4b50c6
sigs.k8s.io/controller-runtime v0.7.2
sigs.k8s.io/yaml v1.2.0 // indirect
volcano.sh/apis v1.2.0-k8s1.16.15
)
337 changes: 10 additions & 327 deletions go.sum

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

xgboostv1 "github.com/kubeflow/tf-operator/pkg/apis/xgboost/v1"
xgboostcontroller "github.com/kubeflow/tf-operator/pkg/controller.v1/xgboost"
//+kubebuilder:scaffold:imports
)

Expand All @@ -41,6 +44,7 @@ var (
func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))

utilruntime.Must(xgboostv1.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
}

Expand Down Expand Up @@ -74,6 +78,14 @@ func main() {
os.Exit(1)
}

if err = (&xgboostcontroller.XGBoostJobReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("XGBoostJob"),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "XGBoostJob")
os.Exit(1)
}
//+kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
Expand Down
9 changes: 3 additions & 6 deletions pkg/apis/tensorflow/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions pkg/apis/xgboost/v1/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

const (
// GroupName is the group name use in this package.
GroupName = "kubeflow.org"
// Kind is the kind name.
Kind = "XGBoostJob"
// GroupVersion is the version.
GroupVersion = "v1"
// Plural is the Plural for XGBoostJob.
Plural = "xgboostjobs"
// Singular is the singular for XGBoostJob.
Singular = "xgboostjob"
// XGBOOSTCRD is the CRD name for XGBoostJob.
XGBoostCRD = "xgboostjobs.kubeflow.org"

DefaultContainerName = "xgboostjob"
DefaultContainerPortName = "xgboostjob-port"
DefaultPort = 9999
)
34 changes: 34 additions & 0 deletions pkg/apis/xgboost/v1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright YEAR The Kubeflow Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package v1 contains API Schema definitions for the kubeflow.org v1 API group
//+kubebuilder:object:generate=true
//+groupName=kubeflow.org
package v1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "kubeflow.org", Version: "v1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
79 changes: 79 additions & 0 deletions pkg/apis/xgboost/v1/xgboostjob_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright YEAR The Kubeflow Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v1

import (
commonv1 "github.com/kubeflow/common/pkg/apis/common/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// XGBoostJobSpec defines the desired state of XGBoostJob
type XGBoostJobSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file
RunPolicy commonv1.RunPolicy `json:",inline"`

XGBReplicaSpecs map[commonv1.ReplicaType]*commonv1.ReplicaSpec `json:"xgbReplicaSpecs"`
}

// XGBoostJobStatus defines the observed state of XGBoostJob
type XGBoostJobStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
commonv1.JobStatus `json:",inline"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// XGBoostJob is the Schema for the xgboostjobs API
// +k8s:openapi-gen=true
type XGBoostJob struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec XGBoostJobSpec `json:"spec,omitempty"`
Status XGBoostJobStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// XGBoostJobList contains a list of XGBoostJob
type XGBoostJobList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []XGBoostJob `json:"items"`
}

// XGBoostJobReplicaType is the type for XGBoostJobReplica.
type XGBoostJobReplicaType commonv1.ReplicaType

const (
// XGBoostReplicaTypeMaster is the type for master replica.
XGBoostReplicaTypeMaster XGBoostJobReplicaType = "Master"

// XGBoostReplicaTypeWorker is the type for worker replicas.
XGBoostReplicaTypeWorker XGBoostJobReplicaType = "Worker"
)

func init() {
SchemeBuilder.Register(&XGBoostJob{}, &XGBoostJobList{})
}
Loading

0 comments on commit c153e32

Please sign in to comment.