This repository has been archived by the owner on Feb 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
Add v1 controller/APIs and support multi-version #82
Merged
+1,836
−5
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
|
||
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 xgboostjob v1 API group | ||
// +k8s:openapi-gen=true | ||
// +k8s:deepcopy-gen=package,register | ||
// +k8s:conversion-gen=github.com/kubeflow/xgboost-operator/pkg/apis/xgboostjob | ||
// +k8s:defaulter-gen=TypeMeta | ||
// +groupName=xgboostjob.kubeflow.org | ||
package v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
|
||
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. | ||
*/ | ||
|
||
// NOTE: Boilerplate only. Ignore this file. | ||
|
||
// Package v1 contains API Schema definitions for the xgboostjob v1 API group | ||
// +k8s:openapi-gen=true | ||
// +k8s:deepcopy-gen=package,register | ||
// +k8s:conversion-gen=github.com/kubeflow/xgboost-operator/pkg/apis/xgboostjob | ||
// +k8s:defaulter-gen=TypeMeta | ||
// +groupName=xgboostjob.kubeflow.org | ||
package v1 | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"sigs.k8s.io/controller-runtime/pkg/runtime/scheme" | ||
) | ||
|
||
var ( | ||
// SchemeGroupVersion is group version used to register these objects | ||
SchemeGroupVersion = schema.GroupVersion{Group: "xgboostjob.kubeflow.org", Version: "v1"} | ||
|
||
// SchemeBuilder is used to add go types to the GroupVersionKind scheme | ||
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} | ||
|
||
// SchemeGroupVersionKind is the GroupVersionKind of the resource. | ||
SchemeGroupVersionKind = SchemeGroupVersion.WithKind(Kind) | ||
|
||
// AddToScheme is required by pkg/client/... | ||
AddToScheme = SchemeBuilder.AddToScheme | ||
) | ||
|
||
// Resource is required by pkg/client/listers/... | ||
func Resource(resource string) schema.GroupResource { | ||
return SchemeGroupVersion.WithResource(resource).GroupResource() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
|
||
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 ( | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"k8s.io/client-go/kubernetes/scheme" | ||
"k8s.io/client-go/rest" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/envtest" | ||
) | ||
|
||
var cfg *rest.Config | ||
var c client.Client | ||
|
||
func TestMain(m *testing.M) { | ||
t := &envtest.Environment{ | ||
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "config", "crds")}, | ||
} | ||
|
||
err := SchemeBuilder.AddToScheme(scheme.Scheme) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if cfg, err = t.Start(); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if c, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
code := m.Run() | ||
t.Stop() | ||
os.Exit(code) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
|
||
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 ( | ||
common "github.com/kubeflow/common/job_controller/api/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 common.RunPolicy `json:",inline"` | ||
|
||
XGBReplicaSpecs map[common.ReplicaType]*common.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 | ||
common.JobStatus `json:",inline"` | ||
} | ||
|
||
// +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"` | ||
} | ||
|
||
// +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 common.ReplicaType | ||
|
||
const ( | ||
// XGBoostReplicaTypeMaster is the type of Master of distributed PyTorch | ||
XGBoostReplicaTypeMaster XGBoostJobReplicaType = "Master" | ||
|
||
// XGBoostReplicaTypeWorker is the type for workers of distributed PyTorch. | ||
XGBoostReplicaTypeWorker XGBoostJobReplicaType = "Worker" | ||
) | ||
|
||
func init() { | ||
SchemeBuilder.Register(&XGBoostJob{}, &XGBoostJobList{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
|
||
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 ( | ||
"testing" | ||
|
||
"github.com/onsi/gomega" | ||
"golang.org/x/net/context" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
func TestStorageXGBoostJob(t *testing.T) { | ||
key := types.NamespacedName{ | ||
Name: "foo", | ||
Namespace: "default", | ||
} | ||
created := &XGBoostJob{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "foo", | ||
Namespace: "default", | ||
}} | ||
g := gomega.NewGomegaWithT(t) | ||
|
||
// Test Create | ||
fetched := &XGBoostJob{} | ||
g.Expect(c.Create(context.TODO(), created)).NotTo(gomega.HaveOccurred()) | ||
|
||
g.Expect(c.Get(context.TODO(), key, fetched)).NotTo(gomega.HaveOccurred()) | ||
g.Expect(fetched).To(gomega.Equal(created)) | ||
|
||
// Test Updating the Labels | ||
updated := fetched.DeepCopy() | ||
updated.Labels = map[string]string{"hello": "world"} | ||
g.Expect(c.Update(context.TODO(), updated)).NotTo(gomega.HaveOccurred()) | ||
|
||
g.Expect(c.Get(context.TODO(), key, fetched)).NotTo(gomega.HaveOccurred()) | ||
g.Expect(fetched).To(gomega.Equal(updated)) | ||
|
||
// Test Delete | ||
g.Expect(c.Delete(context.TODO(), fetched)).NotTo(gomega.HaveOccurred()) | ||
g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.HaveOccurred()) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means the master will point to v1 changes. This is expected, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. This is intended so more users would start testing v1 by default.