-
Notifications
You must be signed in to change notification settings - Fork 698
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KEP-2170: Initial Implementations for v2 Manager
Signed-off-by: Yuki Iwai <[email protected]>
- Loading branch information
Showing
10 changed files
with
650 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
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 controllerv2 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/go-logr/logr" | ||
"k8s.io/client-go/tools/record" | ||
"k8s.io/klog/v2" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
kubeflowv2 "github.com/kubeflow/training-operator/pkg/apis/kubeflow.org/v2alpha1" | ||
) | ||
|
||
type ClusterTrainingRuntimeReconciler struct { | ||
log logr.Logger | ||
client client.Client | ||
recorder record.EventRecorder | ||
} | ||
|
||
func NewClusterTrainingRuntimeReconciler(client client.Client, recorder record.EventRecorder) *ClusterTrainingRuntimeReconciler { | ||
return &ClusterTrainingRuntimeReconciler{ | ||
log: ctrl.Log.WithName("clustertrainingruntime-controller"), | ||
client: client, | ||
recorder: recorder, | ||
} | ||
} | ||
|
||
func (r *ClusterTrainingRuntimeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
var clRuntime kubeflowv2.ClusterTrainingRuntime | ||
if err := r.client.Get(ctx, req.NamespacedName, &clRuntime); err != nil { | ||
return ctrl.Result{}, client.IgnoreNotFound(err) | ||
} | ||
log := ctrl.LoggerFrom(ctx).WithValues("clusterTrainingRuntime", klog.KObj(&clRuntime)) | ||
ctrl.LoggerInto(ctx, log) | ||
log.V(2).Info("Reconciling ClusterTrainingRuntime") | ||
return ctrl.Result{}, nil | ||
} | ||
|
||
func (r *ClusterTrainingRuntimeReconciler) SetupWithManager(mgr ctrl.Manager) error { | ||
return ctrl.NewControllerManagedBy(mgr). | ||
For(&kubeflowv2.ClusterTrainingRuntime{}). | ||
Complete(r) | ||
} |
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,29 @@ | ||
/* | ||
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 controllerv2 | ||
|
||
import ctrl "sigs.k8s.io/controller-runtime" | ||
|
||
func SetupControllers(mgr ctrl.Manager) (string, error) { | ||
if err := NewTrainJobReconciler( | ||
mgr.GetClient(), | ||
mgr.GetEventRecorderFor("training-operator-trainjob-controller"), | ||
).SetupWithManager(mgr); err != nil { | ||
return "TrainJob", err | ||
} | ||
return "", nil | ||
} |
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,59 @@ | ||
/* | ||
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 controllerv2 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/go-logr/logr" | ||
"k8s.io/client-go/tools/record" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
kubeflowv2 "github.com/kubeflow/training-operator/pkg/apis/kubeflow.org/v2alpha1" | ||
) | ||
|
||
type TrainingRuntimeReconciler struct { | ||
log logr.Logger | ||
client client.Client | ||
recorder record.EventRecorder | ||
} | ||
|
||
func NewTrainingRuntimeReconciler(client client.Client, recorder record.EventRecorder) *TrainingRuntimeReconciler { | ||
return &TrainingRuntimeReconciler{ | ||
log: ctrl.Log.WithName("trainingruntime-controller"), | ||
client: client, | ||
recorder: recorder, | ||
} | ||
} | ||
|
||
func (r *TrainingRuntimeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
var runtime kubeflowv2.TrainingRuntime | ||
if err := r.client.Get(ctx, req.NamespacedName, &runtime); err != nil { | ||
return ctrl.Result{}, client.IgnoreNotFound(err) | ||
} | ||
log := ctrl.LoggerFrom(ctx).WithValues("trainingRuntime", runtime) | ||
ctrl.LoggerInto(ctx, log) | ||
log.V(2).Info("Reconciling TrainingRuntime") | ||
return ctrl.Result{}, nil | ||
} | ||
|
||
func (r *TrainingRuntimeReconciler) SetupWithManager(mgr ctrl.Manager) error { | ||
return ctrl.NewControllerManagedBy(mgr). | ||
For(&kubeflowv2.TrainingRuntime{}). | ||
Complete(r) | ||
} |
72 changes: 72 additions & 0 deletions
72
test/controller.v2/clustertrainingruntime_controller_test.go
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,72 @@ | ||
/* | ||
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 controllerv2 | ||
|
||
import ( | ||
"github.com/onsi/ginkgo/v2" | ||
"github.com/onsi/gomega" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
kubeflowv2 "github.com/kubeflow/training-operator/pkg/apis/kubeflow.org/v2alpha1" | ||
"github.com/kubeflow/training-operator/test/framework" | ||
) | ||
|
||
var _ = ginkgo.Describe("ClusterTrainingRuntime controller", ginkgo.Ordered, func() { | ||
var ns *corev1.Namespace | ||
|
||
ginkgo.BeforeAll(func() { | ||
fwk = &framework.Framework{} | ||
cfg = fwk.Init() | ||
ctx, k8sClient = fwk.RunManager(cfg) | ||
}) | ||
ginkgo.AfterAll(func() { | ||
fwk.Teardown() | ||
}) | ||
|
||
ginkgo.BeforeEach(func() { | ||
ns = &corev1.Namespace{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: corev1.SchemeGroupVersion.String(), | ||
Kind: "Namespace", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
GenerateName: "clustertrainingruntime-", | ||
}, | ||
} | ||
gomega.Expect(k8sClient.Create(ctx, ns)).To(gomega.Succeed()) | ||
}) | ||
|
||
ginkgo.When("Reconciling ClusterTrainingRuntime", func() { | ||
ginkgo.AfterEach(func() { | ||
gomega.Expect(k8sClient.DeleteAllOf(ctx, &kubeflowv2.ClusterTrainingRuntime{})).Should(gomega.Succeed()) | ||
}) | ||
|
||
ginkgo.It("Should succeed to create ClusterTrainingRuntime", func() { | ||
clRuntime := &kubeflowv2.ClusterTrainingRuntime{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: kubeflowv2.SchemeGroupVersion.String(), | ||
Kind: "ClusterTrainingRuntime", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "alpha", | ||
}, | ||
} | ||
gomega.Expect(k8sClient.Create(ctx, clRuntime)).Should(gomega.Succeed()) | ||
}) | ||
}) | ||
}) |
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,42 @@ | ||
/* | ||
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 controllerv2 | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/onsi/ginkgo/v2" | ||
"github.com/onsi/gomega" | ||
"k8s.io/client-go/rest" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
"github.com/kubeflow/training-operator/test/framework" | ||
) | ||
|
||
var ( | ||
cfg *rest.Config | ||
k8sClient client.Client | ||
ctx context.Context | ||
fwk *framework.Framework | ||
) | ||
|
||
func TestAPIs(t *testing.T) { | ||
gomega.RegisterFailHandler(ginkgo.Fail) | ||
|
||
ginkgo.RunSpecs(t, "v2 Controllers Suite") | ||
} |
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,74 @@ | ||
/* | ||
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 controllerv2 | ||
|
||
import ( | ||
"github.com/onsi/ginkgo/v2" | ||
"github.com/onsi/gomega" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
kubeflowv2 "github.com/kubeflow/training-operator/pkg/apis/kubeflow.org/v2alpha1" | ||
"github.com/kubeflow/training-operator/test/framework" | ||
) | ||
|
||
var _ = ginkgo.Describe("TrainingRuntime controller", ginkgo.Ordered, func() { | ||
var ns *corev1.Namespace | ||
|
||
ginkgo.BeforeAll(func() { | ||
fwk = &framework.Framework{} | ||
cfg = fwk.Init() | ||
ctx, k8sClient = fwk.RunManager(cfg) | ||
}) | ||
ginkgo.AfterAll(func() { | ||
fwk.Teardown() | ||
}) | ||
|
||
ginkgo.BeforeEach(func() { | ||
ns = &corev1.Namespace{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: corev1.SchemeGroupVersion.String(), | ||
Kind: "Namespace", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
GenerateName: "trainingruntime-", | ||
}, | ||
} | ||
gomega.Expect(k8sClient.Create(ctx, ns)).To(gomega.Succeed()) | ||
}) | ||
|
||
ginkgo.When("Reconciling TrainingRuntime", func() { | ||
ginkgo.AfterEach(func() { | ||
gomega.Expect(k8sClient.DeleteAllOf(ctx, &kubeflowv2.TrainingRuntime{}, client.InNamespace(ns.Name))) | ||
}) | ||
|
||
ginkgo.It("Should succeed to create TrainingRuntime", func() { | ||
runtime := &kubeflowv2.TrainingRuntime{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: kubeflowv2.SchemeGroupVersion.String(), | ||
Kind: "TrainingRuntime", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "alpha", | ||
Namespace: ns.Name, | ||
}, | ||
} | ||
gomega.Expect(k8sClient.Create(ctx, runtime)).Should(gomega.Succeed()) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.