Skip to content

Commit

Permalink
Register APIs with scheme
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Velichkevich <[email protected]>
  • Loading branch information
andreyvelich committed Aug 16, 2024
1 parent ed830c8 commit 66e7049
Show file tree
Hide file tree
Showing 4 changed files with 804 additions and 18 deletions.
36 changes: 36 additions & 0 deletions pkg/apis/kubeflow.org/v2alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2024 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 v2alpha1 contains API Schema definitions for the kubeflow.org v2alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=kubeflow.org
package v2alpha1

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: "v2alpha1"}

// 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
)
16 changes: 12 additions & 4 deletions pkg/apis/kubeflow.org/v2alpha1/trainingruntime_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
jobsetv1alpha2 "sigs.k8s.io/jobset/api/jobset/v1alpha2"
)

// +kubebuilder:object:root=true

// ClusterTrainingRuntime represents a training runtime which can be referenced as part of
// `trainingRuntimeRef` API in TrainJob. This resource is a cluster-scoped and can be referenced
// by TrainJob that created in *any* namespace.
Expand All @@ -35,6 +37,8 @@ type ClusterTrainingRuntime struct {
Spec TrainingRuntimeSpec `json:"spec,omitempty"`
}

// +kubebuilder:object:root=true

// ClusterTrainingRuntimeList is a collection of cluster training runtimes.
type ClusterTrainingRuntimeList struct {
metav1.TypeMeta `json:",inline"`
Expand All @@ -46,6 +50,8 @@ type ClusterTrainingRuntimeList struct {
Items []ClusterTrainingRuntime `json:"items"`
}

// +kubebuilder:object:root=true

// TrainingRuntime represents a training runtime which can be referenced as part of
// `trainingRuntimeRef` API in TrainJob. This resource is a namespaced-scoped and can be referenced
// by TrainJob that created in the *same* namespace as the TrainingRuntime.
Expand All @@ -59,6 +65,8 @@ type TrainingRuntime struct {
Spec TrainingRuntimeSpec `json:"spec"`
}

// +kubebuilder:object:root=true

// TrainingRuntimeList is a collection of training runtimes.
type TrainingRuntimeList struct {
metav1.TypeMeta `json:",inline"`
Expand Down Expand Up @@ -121,6 +129,7 @@ type TorchSpec struct {
// Number of processes per node.
// This value is inserted into the `--nproc-per-node` argument of the `torchrun` CLI.
// Supported values: `auto`, `cpu`, `gpu`, or int value.
// TODO (andreyvelich): Add kubebuilder validation.
// Defaults to `auto`.
NumProcPerNode *string `json:"numProcPerNode,omitempty"`

Expand Down Expand Up @@ -181,7 +190,6 @@ const (
MPIImplementationMPICH MPIImplementation = "MPICH"
)

// TODO: Enable this after controller implementation.
// func init() {
// SchemeBuilder.Register(&ClusterTrainingRuntime{}, &ClusterTrainingRuntimeList{}, &TrainingRuntime{}, &TrainingRuntimeList{})
// }
func init() {
SchemeBuilder.Register(&ClusterTrainingRuntime{}, &ClusterTrainingRuntimeList{}, &TrainingRuntime{}, &TrainingRuntimeList{})
}
34 changes: 20 additions & 14 deletions pkg/apis/kubeflow.org/v2alpha1/trainjob_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ import (
jobsetv1alpha2 "sigs.k8s.io/jobset/api/jobset/v1alpha2"
)

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="State",type=string,JSONPath=`.status.conditions[-1:].type`
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`

// TrainJob represents configuration of a training job.
type TrainJob struct {
metav1.TypeMeta `json:",inline"`
Expand All @@ -36,6 +41,19 @@ type TrainJob struct {
Status TrainJobStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// TrainJobList is a collection of training jobs.
type TrainJobList struct {
metav1.TypeMeta `json:",inline"`

// Standard list metadata.
metav1.ListMeta `json:"metadata,omitempty"`

// List of TrainJobs.
Items []TrainJob `json:"items"`
}

// TrainJobSpec represents specification of the desired TrainJob.
type TrainJobSpec struct {
// Reference to the training runtime.
Expand Down Expand Up @@ -226,18 +244,6 @@ type TrainJobStatus struct {
ReplicatedJobsStatus []jobsetv1alpha2.ReplicatedJobStatus `json:"replicatedJobsStatus,omitempty"`
}

// TrainJobList is a collection of training jobs.
type TrainJobList struct {
metav1.TypeMeta `json:",inline"`

// Standard list metadata.
metav1.ListMeta `json:"metadata,omitempty"`

// List of TrainJobs.
Items []TrainJob `json:"items"`
func init() {
SchemeBuilder.Register(&TrainJob{}, &TrainJobList{})
}

// TODO: Enable this after controller implementation.
// func init() {
// SchemeBuilder.Register(&TrainJob{}, &TrainJobList{})
// }
Loading

0 comments on commit 66e7049

Please sign in to comment.