Skip to content

Commit

Permalink
merge kubeflow/common.v1 to mpi-operator
Browse files Browse the repository at this point in the history
Signed-off-by: lowang_bh <[email protected]>

java gen Python SDK

Signed-off-by: lowang_bh <[email protected]>
  • Loading branch information
lowang-bh committed Jun 22, 2023
1 parent 21f326d commit 3c5eb96
Show file tree
Hide file tree
Showing 26 changed files with 603 additions and 535 deletions.
2 changes: 1 addition & 1 deletion hack/python-sdk/gen-sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mv pkg/apis/kubeflow/v2beta1/openapi_generated.go pkg/apis/kubeflow/v2beta1/open
CODEGEN_VERSION=$(grep 'k8s.io/code-generator' go.sum | awk '{print $2}' | sed 's/\/go.mod//g' | head -1)
GOBIN="${PWD}/bin" go install "k8s.io/code-generator/cmd/openapi-gen@${CODEGEN_VERSION}"
echo "Generating V2 OpenAPI specification ..."
"${PWD}/bin/openapi-gen" --input-dirs github.com/kubeflow/mpi-operator/pkg/apis/kubeflow/v2beta1,github.com/kubeflow/common/pkg/apis/common/v1 --output-package github.com/kubeflow/mpi-operator/pkg/apis/kubeflow/v2beta1 --go-header-file hack/boilerplate/boilerplate.go.txt
"${PWD}/bin/openapi-gen" --input-dirs github.com/kubeflow/mpi-operator/pkg/apis/kubeflow/v2beta1 --output-package github.com/kubeflow/mpi-operator/pkg/apis/kubeflow/v2beta1 --go-header-file hack/boilerplate/boilerplate.go.txt

echo "Generating V2 swagger file ..."
go run hack/python-sdk/main.go v2beta1 > ${SWAGGER_V2_CODEGEN_FILE}
Expand Down
1 change: 0 additions & 1 deletion hack/python-sdk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func main() {

func swaggify(name string) string {
name = strings.Replace(name, "github.com/kubeflow/mpi-operator/pkg/apis/kubeflow/", "", -1)
name = strings.Replace(name, "github.com/kubeflow/common/pkg/apis/common/", "", -1)
name = strings.Replace(name, "github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/", "", -1)
name = strings.Replace(name, "k8s.io/api/core/", "", -1)
name = strings.Replace(name, "k8s.io/apimachinery/pkg/apis/meta/", "", -1)
Expand Down
58 changes: 58 additions & 0 deletions pkg/apis/kubeflow/v2beta1/common_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2018 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 v2beta1

import (
v1 "k8s.io/api/core/v1"
)

// +k8s:openapi-gen=true
// +k8s:deepcopy-gen=true
// ReplicaSpec is a description of the replica
type ReplicaSpec struct {
// Replicas is the desired number of replicas of the given template.
// If unspecified, defaults to 1.
Replicas *int32 `json:"replicas,omitempty"`

// Template is the object that describes the pod that
// will be created for this replica. RestartPolicy in PodTemplateSpec
// will be overide by RestartPolicy in ReplicaSpec
Template v1.PodTemplateSpec `json:"template,omitempty"`

// Restart policy for all replicas within the job.
// One of Always, OnFailure, Never and ExitCode.
// Default to Never.
RestartPolicy RestartPolicy `json:"restartPolicy,omitempty"`
}

// +k8s:openapi-gen=true
// RestartPolicy describes how the replicas should be restarted.
// Only one of the following restart policies may be specified.
// If none of the following policies is specified, the default one
// is RestartPolicyAlways.
type RestartPolicy string

const (
RestartPolicyAlways RestartPolicy = "Always"
RestartPolicyOnFailure RestartPolicy = "OnFailure"
RestartPolicyNever RestartPolicy = "Never"

// RestartPolicyExitCode policy means that user should add exit code by themselves,
// The job operator will check these exit codes to
// determine the behavior when an error occurs:
// - 1-127: permanent error, do not restart.
// - 128-255: retryable error, will restart the pod.
RestartPolicyExitCode RestartPolicy = "ExitCode"
)
25 changes: 21 additions & 4 deletions pkg/apis/kubeflow/v2beta1/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,32 @@

package v2beta1

import common "github.com/kubeflow/common/pkg/apis/common/v1"

const (
// EnvKubeflowNamespace is ENV for kubeflow namespace specified by user.
EnvKubeflowNamespace = "KUBEFLOW_NAMESPACE"
// DefaultRestartPolicy is default RestartPolicy for ReplicaSpec.
DefaultRestartPolicy = common.RestartPolicyNever
DefaultRestartPolicy = RestartPolicyNever
// DefaultLauncherRestartPolicy is default RestartPolicy for Launcher Job.
DefaultLauncherRestartPolicy = common.RestartPolicyOnFailure
DefaultLauncherRestartPolicy = RestartPolicyOnFailure
// OperatorName is the name of the operator used as value to the label common.OperatorLabelName
OperatorName = "mpi-operator"
)

// merge from common.v1
const (

// ReplicaIndexLabel represents the label key for the replica-index, e.g. 0, 1, 2.. etc
ReplicaIndexLabel = "training.kubeflow.org/replica-index"

// ReplicaTypeLabel represents the label key for the replica-type, e.g. ps, worker etc.
ReplicaTypeLabel = "training.kubeflow.org/replica-type"

// OperatorNameLabel represents the label key for the operator name, e.g. tf-operator, mpi-operator, etc.
OperatorNameLabel = "training.kubeflow.org/operator-name"

// JobNameLabel represents the label key for the job name, the value is the job name.
JobNameLabel = "training.kubeflow.org/job-name"

// JobRoleLabel represents the label key for the job role, e.g. master.
JobRoleLabel = "training.kubeflow.org/job-role"
)
5 changes: 2 additions & 3 deletions pkg/apis/kubeflow/v2beta1/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package v2beta1

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

Expand All @@ -24,7 +23,7 @@ func addDefaultingFuncs(scheme *runtime.Scheme) error {
}

// setDefaultsTypeLauncher sets the default value to launcher.
func setDefaultsTypeLauncher(spec *common.ReplicaSpec) {
func setDefaultsTypeLauncher(spec *ReplicaSpec) {
if spec == nil {
return
}
Expand All @@ -37,7 +36,7 @@ func setDefaultsTypeLauncher(spec *common.ReplicaSpec) {
}

// setDefaultsTypeWorker sets the default value to worker.
func setDefaultsTypeWorker(spec *common.ReplicaSpec) {
func setDefaultsTypeWorker(spec *ReplicaSpec) {
if spec == nil {
return
}
Expand Down
9 changes: 4 additions & 5 deletions pkg/apis/kubeflow/v2beta1/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
common "github.com/kubeflow/common/pkg/apis/common/v1"
)

func TestSetDefaults_MPIJob(t *testing.T) {
Expand Down Expand Up @@ -97,7 +96,7 @@ func TestSetDefaults_MPIJob(t *testing.T) {
"launcher defaults": {
job: MPIJob{
Spec: MPIJobSpec{
MPIReplicaSpecs: map[MPIReplicaType]*common.ReplicaSpec{
MPIReplicaSpecs: map[MPIReplicaType]*ReplicaSpec{
MPIReplicaTypeLauncher: {},
},
},
Expand All @@ -110,7 +109,7 @@ func TestSetDefaults_MPIJob(t *testing.T) {
},
SSHAuthMountPath: "/root/.ssh",
MPIImplementation: MPIImplementationOpenMPI,
MPIReplicaSpecs: map[MPIReplicaType]*common.ReplicaSpec{
MPIReplicaSpecs: map[MPIReplicaType]*ReplicaSpec{
MPIReplicaTypeLauncher: {
Replicas: newInt32(1),
RestartPolicy: DefaultLauncherRestartPolicy,
Expand All @@ -122,7 +121,7 @@ func TestSetDefaults_MPIJob(t *testing.T) {
"worker defaults": {
job: MPIJob{
Spec: MPIJobSpec{
MPIReplicaSpecs: map[MPIReplicaType]*common.ReplicaSpec{
MPIReplicaSpecs: map[MPIReplicaType]*ReplicaSpec{
MPIReplicaTypeWorker: {},
},
},
Expand All @@ -135,7 +134,7 @@ func TestSetDefaults_MPIJob(t *testing.T) {
},
SSHAuthMountPath: "/root/.ssh",
MPIImplementation: MPIImplementationOpenMPI,
MPIReplicaSpecs: map[MPIReplicaType]*common.ReplicaSpec{
MPIReplicaSpecs: map[MPIReplicaType]*ReplicaSpec{
MPIReplicaTypeWorker: {
Replicas: newInt32(0),
RestartPolicy: DefaultRestartPolicy,
Expand Down
Loading

0 comments on commit 3c5eb96

Please sign in to comment.