Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace original pointer methods with ptr libs #635

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions pkg/apis/kubeflow/v2beta1/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package v2beta1

import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/utils/ptr"
)

func addDefaultingFuncs(scheme *runtime.Scheme) error {
Expand All @@ -31,7 +32,7 @@ func setDefaultsTypeLauncher(spec *ReplicaSpec) {
spec.RestartPolicy = DefaultLauncherRestartPolicy
}
if spec.Replicas == nil {
spec.Replicas = newInt32(1)
spec.Replicas = ptr.To[int32](1)
}
}

Expand All @@ -44,13 +45,13 @@ func setDefaultsTypeWorker(spec *ReplicaSpec) {
spec.RestartPolicy = DefaultRestartPolicy
}
if spec.Replicas == nil {
spec.Replicas = newInt32(0)
spec.Replicas = ptr.To[int32](0)
}
}

func setDefaultsRunPolicy(policy *RunPolicy) {
if policy.CleanPodPolicy == nil {
policy.CleanPodPolicy = NewCleanPodPolicy(CleanPodPolicyNone)
policy.CleanPodPolicy = ptr.To(CleanPodPolicyNone)
}
// The remaining fields are passed as-is to the k8s Job API, which does its
// own defaulting.
Expand All @@ -59,7 +60,7 @@ func setDefaultsRunPolicy(policy *RunPolicy) {
func SetDefaults_MPIJob(mpiJob *MPIJob) {
setDefaultsRunPolicy(&mpiJob.Spec.RunPolicy)
if mpiJob.Spec.SlotsPerWorker == nil {
mpiJob.Spec.SlotsPerWorker = newInt32(1)
mpiJob.Spec.SlotsPerWorker = ptr.To[int32](1)
}
if mpiJob.Spec.SSHAuthMountPath == "" {
mpiJob.Spec.SSHAuthMountPath = "/root/.ssh"
Expand All @@ -77,11 +78,3 @@ func SetDefaults_MPIJob(mpiJob *MPIJob) {
// set default to Worker
setDefaultsTypeWorker(mpiJob.Spec.MPIReplicaSpecs[MPIReplicaTypeWorker])
}

func newInt32(v int32) *int32 {
return &v
}

func NewCleanPodPolicy(policy CleanPodPolicy) *CleanPodPolicy {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💣

return &policy
}
61 changes: 29 additions & 32 deletions pkg/apis/kubeflow/v2beta1/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"k8s.io/utils/ptr"
)

func TestSetDefaults_MPIJob(t *testing.T) {
Expand All @@ -28,9 +29,9 @@ func TestSetDefaults_MPIJob(t *testing.T) {
"base defaults": {
want: MPIJob{
Spec: MPIJobSpec{
SlotsPerWorker: newInt32(1),
SlotsPerWorker: ptr.To[int32](1),
RunPolicy: RunPolicy{
CleanPodPolicy: NewCleanPodPolicy(CleanPodPolicyNone),
CleanPodPolicy: ptr.To(CleanPodPolicyNone),
},
SSHAuthMountPath: "/root/.ssh",
MPIImplementation: MPIImplementationOpenMPI,
Expand All @@ -41,12 +42,12 @@ func TestSetDefaults_MPIJob(t *testing.T) {
"base defaults overridden (intel)": {
job: MPIJob{
Spec: MPIJobSpec{
SlotsPerWorker: newInt32(10),
SlotsPerWorker: ptr.To[int32](10),
RunPolicy: RunPolicy{
CleanPodPolicy: NewCleanPodPolicy(CleanPodPolicyRunning),
TTLSecondsAfterFinished: newInt32(2),
ActiveDeadlineSeconds: newInt64(3),
BackoffLimit: newInt32(4),
CleanPodPolicy: ptr.To(CleanPodPolicyRunning),
TTLSecondsAfterFinished: ptr.To[int32](2),
ActiveDeadlineSeconds: ptr.To[int64](3),
BackoffLimit: ptr.To[int32](4),
},
SSHAuthMountPath: "/home/mpiuser/.ssh",
MPIImplementation: MPIImplementationIntel,
Expand All @@ -55,12 +56,12 @@ func TestSetDefaults_MPIJob(t *testing.T) {
},
want: MPIJob{
Spec: MPIJobSpec{
SlotsPerWorker: newInt32(10),
SlotsPerWorker: ptr.To[int32](10),
RunPolicy: RunPolicy{
CleanPodPolicy: NewCleanPodPolicy(CleanPodPolicyRunning),
TTLSecondsAfterFinished: newInt32(2),
ActiveDeadlineSeconds: newInt64(3),
BackoffLimit: newInt32(4),
CleanPodPolicy: ptr.To(CleanPodPolicyRunning),
TTLSecondsAfterFinished: ptr.To[int32](2),
ActiveDeadlineSeconds: ptr.To[int64](3),
BackoffLimit: ptr.To[int32](4),
},
SSHAuthMountPath: "/home/mpiuser/.ssh",
MPIImplementation: MPIImplementationIntel,
Expand All @@ -71,12 +72,12 @@ func TestSetDefaults_MPIJob(t *testing.T) {
"base defaults overridden (mpich)": {
job: MPIJob{
Spec: MPIJobSpec{
SlotsPerWorker: newInt32(10),
SlotsPerWorker: ptr.To[int32](10),
RunPolicy: RunPolicy{
CleanPodPolicy: NewCleanPodPolicy(CleanPodPolicyRunning),
TTLSecondsAfterFinished: newInt32(2),
ActiveDeadlineSeconds: newInt64(3),
BackoffLimit: newInt32(4),
CleanPodPolicy: ptr.To(CleanPodPolicyRunning),
TTLSecondsAfterFinished: ptr.To[int32](2),
ActiveDeadlineSeconds: ptr.To[int64](3),
BackoffLimit: ptr.To[int32](4),
},
SSHAuthMountPath: "/home/mpiuser/.ssh",
MPIImplementation: MPIImplementationMPICH,
Expand All @@ -85,12 +86,12 @@ func TestSetDefaults_MPIJob(t *testing.T) {
},
want: MPIJob{
Spec: MPIJobSpec{
SlotsPerWorker: newInt32(10),
SlotsPerWorker: ptr.To[int32](10),
RunPolicy: RunPolicy{
CleanPodPolicy: NewCleanPodPolicy(CleanPodPolicyRunning),
TTLSecondsAfterFinished: newInt32(2),
ActiveDeadlineSeconds: newInt64(3),
BackoffLimit: newInt32(4),
CleanPodPolicy: ptr.To(CleanPodPolicyRunning),
TTLSecondsAfterFinished: ptr.To[int32](2),
ActiveDeadlineSeconds: ptr.To[int64](3),
BackoffLimit: ptr.To[int32](4),
},
SSHAuthMountPath: "/home/mpiuser/.ssh",
MPIImplementation: MPIImplementationMPICH,
Expand All @@ -108,16 +109,16 @@ func TestSetDefaults_MPIJob(t *testing.T) {
},
want: MPIJob{
Spec: MPIJobSpec{
SlotsPerWorker: newInt32(1),
SlotsPerWorker: ptr.To[int32](1),
RunPolicy: RunPolicy{
CleanPodPolicy: NewCleanPodPolicy(CleanPodPolicyNone),
CleanPodPolicy: ptr.To(CleanPodPolicyNone),
},
SSHAuthMountPath: "/root/.ssh",
MPIImplementation: MPIImplementationOpenMPI,
LauncherCreationPolicy: "AtStartup",
MPIReplicaSpecs: map[MPIReplicaType]*ReplicaSpec{
MPIReplicaTypeLauncher: {
Replicas: newInt32(1),
Replicas: ptr.To[int32](1),
RestartPolicy: DefaultLauncherRestartPolicy,
},
},
Expand All @@ -134,16 +135,16 @@ func TestSetDefaults_MPIJob(t *testing.T) {
},
want: MPIJob{
Spec: MPIJobSpec{
SlotsPerWorker: newInt32(1),
SlotsPerWorker: ptr.To[int32](1),
RunPolicy: RunPolicy{
CleanPodPolicy: NewCleanPodPolicy(CleanPodPolicyNone),
CleanPodPolicy: ptr.To(CleanPodPolicyNone),
},
SSHAuthMountPath: "/root/.ssh",
MPIImplementation: MPIImplementationOpenMPI,
LauncherCreationPolicy: "AtStartup",
MPIReplicaSpecs: map[MPIReplicaType]*ReplicaSpec{
MPIReplicaTypeWorker: {
Replicas: newInt32(0),
Replicas: ptr.To[int32](0),
RestartPolicy: DefaultRestartPolicy,
},
},
Expand All @@ -161,7 +162,3 @@ func TestSetDefaults_MPIJob(t *testing.T) {
})
}
}

func newInt64(v int64) *int64 {
return &v
}
Loading
Loading