-
Notifications
You must be signed in to change notification settings - Fork 706
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: Implement skeleton webhook servers #2251
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,2 @@ | ||
resources: | ||
- manifests.yaml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--- | ||
apiVersion: admissionregistration.k8s.io/v1 | ||
kind: ValidatingWebhookConfiguration | ||
metadata: | ||
name: validating-webhook-configuration | ||
webhooks: | ||
- admissionReviewVersions: | ||
- v1 | ||
clientConfig: | ||
service: | ||
name: webhook-service | ||
namespace: system | ||
path: /validate-kubeflow-org-v2alpha1-clustertrainingruntime | ||
failurePolicy: Fail | ||
name: validator.clustertrainingruntime.kubeflow.org | ||
rules: | ||
- apiGroups: | ||
- kubeflow.org | ||
apiVersions: | ||
- v2alpha1 | ||
operations: | ||
- CREATE | ||
- UPDATE | ||
resources: | ||
- clustertrainingruntimes | ||
sideEffects: None | ||
- admissionReviewVersions: | ||
- v1 | ||
clientConfig: | ||
service: | ||
name: webhook-service | ||
namespace: system | ||
path: /validate-kubeflow-org-v2alpha1-trainingruntime | ||
failurePolicy: Fail | ||
name: validator.trainingruntime.kubeflow.org | ||
rules: | ||
- apiGroups: | ||
- kubeflow.org | ||
apiVersions: | ||
- v2alpha1 | ||
operations: | ||
- CREATE | ||
- UPDATE | ||
resources: | ||
- trainingruntimes | ||
sideEffects: None | ||
- admissionReviewVersions: | ||
- v1 | ||
clientConfig: | ||
service: | ||
name: webhook-service | ||
namespace: system | ||
path: /validate-kubeflow-org-v2alpha1-trainjob | ||
failurePolicy: Fail | ||
name: validator.trainjob.kubeflow.org | ||
rules: | ||
- apiGroups: | ||
- kubeflow.org | ||
apiVersions: | ||
- v2alpha1 | ||
operations: | ||
- CREATE | ||
- UPDATE | ||
resources: | ||
- trainjobs | ||
sideEffects: None |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
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 ( | ||
"context" | ||
|
||
"k8s.io/apimachinery/pkg/runtime" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook/admission" | ||
|
||
kubeflowv2 "github.com/kubeflow/training-operator/pkg/apis/kubeflow.org/v2alpha1" | ||
) | ||
|
||
type ClusterTrainingRuntimeWebhook struct{} | ||
|
||
func setupWebhookForClusterTrainingRuntime(mgr ctrl.Manager) error { | ||
return ctrl.NewWebhookManagedBy(mgr). | ||
For(&kubeflowv2.ClusterTrainingRuntime{}). | ||
WithValidator(&ClusterTrainingRuntimeWebhook{}). | ||
Complete() | ||
} | ||
|
||
// +kubebuilder:webhook:path=/validate-kubeflow-org-v2alpha1-clustertrainingruntime,mutating=false,failurePolicy=fail,sideEffects=None,groups=kubeflow.org,resources=clustertrainingruntimes,verbs=create;update,versions=v2alpha1,name=validator.clustertrainingruntime.kubeflow.org,admissionReviewVersions=v1 | ||
|
||
var _ webhook.CustomValidator = (*ClusterTrainingRuntimeWebhook)(nil) | ||
|
||
func (w *ClusterTrainingRuntimeWebhook) ValidateCreate(context.Context, runtime.Object) (admission.Warnings, error) { | ||
return nil, nil | ||
} | ||
|
||
func (w *ClusterTrainingRuntimeWebhook) ValidateUpdate(context.Context, runtime.Object, runtime.Object) (admission.Warnings, error) { | ||
return nil, nil | ||
} | ||
|
||
func (w *ClusterTrainingRuntimeWebhook) ValidateDelete(context.Context, runtime.Object) (admission.Warnings, error) { | ||
return nil, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,15 @@ package webhookv2 | |
|
||
import ctrl "sigs.k8s.io/controller-runtime" | ||
|
||
func Setup(ctrl.Manager) (string, error) { | ||
func Setup(mgr ctrl.Manager) (string, error) { | ||
if err := setupWebhookForClusterTrainingRuntime(mgr); err != nil { | ||
return "ClusterTrainingRuntime", err | ||
} | ||
if err := setupWebhookForTrainingRuntime(mgr); err != nil { | ||
return "TrainingRuntime", err | ||
} | ||
if err := setupWebhookForTrainJob(mgr); err != nil { | ||
return "TrainJob", err | ||
} | ||
Comment on lines
+23
to
+30
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. @tenzen-y Do you return these names only to handle this error: https://github.com/kubeflow/training-operator/blob/master/cmd/training-operator.v2alpha1/main.go#L150C5-L152 ? 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. Yes, I believe that this name is helpful because this is not for validation error, this is for set up error. 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. That's right, but without this name, can we see the file traceback of this error during the webhook setup ? 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 guess that the traceback will show the path where the error occurs. However, I still believe this helps understand the components in which failure occurs since this component name (ex. TrainJob) can be shown as a top-level log, and this top-level log allows us to avoid digging into nested traceback logs. 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. Alright, sounds good! |
||
return "", nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
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 ( | ||
"context" | ||
|
||
"k8s.io/apimachinery/pkg/runtime" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook/admission" | ||
|
||
kubeflowv2 "github.com/kubeflow/training-operator/pkg/apis/kubeflow.org/v2alpha1" | ||
) | ||
|
||
type TrainingRuntimeWebhook struct{} | ||
|
||
func setupWebhookForTrainingRuntime(mgr ctrl.Manager) error { | ||
return ctrl.NewWebhookManagedBy(mgr). | ||
For(&kubeflowv2.TrainingRuntime{}). | ||
WithValidator(&TrainingRuntimeWebhook{}). | ||
Complete() | ||
} | ||
|
||
// +kubebuilder:webhook:path=/validate-kubeflow-org-v2alpha1-trainingruntime,mutating=false,failurePolicy=fail,sideEffects=None,groups=kubeflow.org,resources=trainingruntimes,verbs=create;update,versions=v2alpha1,name=validator.trainingruntime.kubeflow.org,admissionReviewVersions=v1 | ||
|
||
var _ webhook.CustomValidator = (*TrainingRuntimeWebhook)(nil) | ||
|
||
func (w *TrainingRuntimeWebhook) ValidateCreate(context.Context, runtime.Object) (admission.Warnings, error) { | ||
return nil, nil | ||
} | ||
|
||
func (w *TrainingRuntimeWebhook) ValidateUpdate(context.Context, runtime.Object, runtime.Object) (admission.Warnings, error) { | ||
return nil, nil | ||
} | ||
|
||
func (w *TrainingRuntimeWebhook) ValidateDelete(context.Context, runtime.Object) (admission.Warnings, error) { | ||
return nil, nil | ||
} | ||
andreyvelich marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
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 ( | ||
"github.com/onsi/ginkgo/v2" | ||
"github.com/onsi/gomega" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
"github.com/kubeflow/training-operator/test/integration/framework" | ||
) | ||
|
||
var _ = ginkgo.Describe("ClusterTrainingRuntime Webhook", 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-webhook-", | ||
}, | ||
} | ||
gomega.Expect(k8sClient.Create(ctx, ns)).To(gomega.Succeed()) | ||
}) | ||
}) |
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.
Can we call it similar to Katib webhooks ?
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.
This is auto-generated name by controller-gen.
So, we can not change this name.
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 remember that we discussed before that we can rename it via Kustomize patch: https://github.com/kubeflow/training-operator/blob/master/manifests/base/webhook/patch.yaml.
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.
Yes, that's right. But we do not add any manifests in this PR because I added only manifests generated by controller-gen so that we can start up the webhook servers during envtest.
In other words, these manifests are at least manifests to launch webhook servers during integration testing.
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.
So, I think #2208 has the responsibility to add manifests not generated by controller-tools. Any thoughts?
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.
Sounds good. @tenzen-y Please can you add the comment in #2208 that we should add the Kustomize
patch
to update those names ?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.
Sure. I will describe the detailed task in #2208.