-
Notifications
You must be signed in to change notification settings - Fork 718
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
KEP-2170: Initial Implementations for v2 Manager #2236
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,46 @@ 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 TrainJobReconciler struct { | ||
log logr.Logger | ||
client client.Client | ||
recorder record.EventRecorder | ||
} | ||
|
||
func NewTrainJobReconciler(client client.Client, recorder record.EventRecorder) *TrainJobReconciler { | ||
return &TrainJobReconciler{ | ||
log: ctrl.Log.WithName("trainjob-controller"), | ||
client: client, | ||
recorder: recorder, | ||
} | ||
} | ||
|
||
func (r *TrainJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
var trainJob kubeflowv2.TrainJob | ||
if err := r.client.Get(ctx, req.NamespacedName, &trainJob); err != nil { | ||
return ctrl.Result{}, client.IgnoreNotFound(err) | ||
} | ||
log := ctrl.LoggerFrom(ctx).WithValues("trainJob", klog.KObj(&trainJob)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the value to configure controller runtime logger with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is not new logger, actually this logger is propagated from Reconciler and we reuse it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, we do not generate new logger, and not add a logger name ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, that makes sense! |
||
ctrl.LoggerInto(ctx, log) | ||
log.V(2).Info("Reconciling TrainJob") | ||
return ctrl.Result{}, nil | ||
} | ||
|
||
func (r *TrainJobReconciler) SetupWithManager(mgr ctrl.Manager) error { | ||
return ctrl.NewControllerManagedBy(mgr). | ||
For(&kubeflowv2.TrainJob{}). | ||
Complete(r) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
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 webhookv2 | ||
|
||
import ctrl "sigs.k8s.io/controller-runtime" | ||
|
||
func Setup(ctrl.Manager) (string, error) { | ||
return "", nil | ||
} |
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/integration/framework" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you see a value to separate framework logic into separate file ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is needed since we will add webhook server integration testing and we will use this framework to set up testing environment.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using integration testing framework would be better between testing for trainjob_controller, trainjob_wwbhook, trainingruntime_webhook, and clustertrainingruntime_webhook. |
||
) | ||
|
||
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") | ||
} |
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.
I think, we agree before to use controller-runtime logger everywhere to be consistent: #2048
Should we make that change @tenzen-y ?
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.
Actually, this is the controller-runtime logger. The controller-runtime logger implement this logr interface, so we need to import this library to use the controller-runtime logger. You can see the actual controller-runtime logger in the Reconcile function.