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

[jobframework] Deployment integration #2813

Merged
merged 7 commits into from
Aug 30, 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
1 change: 1 addition & 0 deletions apis/config/v1beta1/configuration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ type Integrations struct {
// - "kubeflow.org/tfjob"
// - "kubeflow.org/xgboostjob"
// - "pod"
// - "deployment"
Frameworks []string `json:"frameworks,omitempty"`
// List of GroupVersionKinds that are managed for Kueue by external controllers;
// the expected format is `Kind.version.group.com`.
Expand Down
39 changes: 39 additions & 0 deletions charts/kueue/templates/webhook/webhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,25 @@ webhooks:
resources:
- rayjobs
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: '{{ include "kueue.fullname" . }}-webhook-service'
namespace: '{{ .Release.Namespace }}'
path: /mutate-apps-v1-deployment
failurePolicy: Fail
name: mdeployment.kb.io
rules:
- apiGroups:
- apps
apiVersions:
- v1
operations:
- CREATE
resources:
- deployments
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
Expand Down Expand Up @@ -540,6 +559,26 @@ webhooks:
resources:
- rayjobs
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: '{{ include "kueue.fullname" . }}-webhook-service'
namespace: '{{ .Release.Namespace }}'
path: /validate-apps-v1-deployment
failurePolicy: Fail
name: vdeployment.kb.io
rules:
- apiGroups:
- apps
apiVersions:
- v1
operations:
- CREATE
- UPDATE
resources:
- deployments
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
Expand Down
39 changes: 39 additions & 0 deletions config/components/webhook/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,25 @@ webhooks:
resources:
- rayjobs
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: webhook-service
namespace: system
path: /mutate-apps-v1-deployment
failurePolicy: Fail
name: mdeployment.kb.io
rules:
- apiGroups:
- apps
apiVersions:
- v1
operations:
- CREATE
resources:
- deployments
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
Expand Down Expand Up @@ -496,6 +515,26 @@ webhooks:
resources:
- rayjobs
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: webhook-service
namespace: system
path: /validate-apps-v1-deployment
failurePolicy: Fail
name: vdeployment.kb.io
rules:
- apiGroups:
- apps
apiVersions:
- v1
operations:
- CREATE
- UPDATE
resources:
- deployments
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
Expand Down
50 changes: 50 additions & 0 deletions pkg/controller/jobframework/noop_controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Copyright 2024 The Kubernetes 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 jobframework

import (
"context"

"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/tools/record"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

var (
_ JobReconcilerInterface = (*NoopReconciler)(nil)
)

type NoopReconciler struct {
gvk schema.GroupVersionKind
}

func (r NoopReconciler) Reconcile(context.Context, reconcile.Request) (reconcile.Result, error) {
return ctrl.Result{}, nil
}

func (r NoopReconciler) SetupWithManager(ctrl.Manager) error {
ctrl.Log.V(3).Info("Skipped reconciler setup", "gvk", r.gvk)
return nil
}

func NewNoopReconcilerFactory(gvk schema.GroupVersionKind) ReconcilerFactory {
return func(client client.Client, record record.EventRecorder, opts ...Option) JobReconcilerInterface {
return &NoopReconciler{gvk: gvk}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package noop
package jobframework

import (
"context"
Expand All @@ -27,8 +27,7 @@ import (
type webhook struct {
}

// SetupWebhook configures the webhook for batchJob.
func SetupWebhook(mgr ctrl.Manager, apiType runtime.Object) error {
func setupNoopWebhook(mgr ctrl.Manager, apiType runtime.Object) error {
wh := &webhook{}
return ctrl.NewWebhookManagedBy(mgr).
For(apiType).
Expand All @@ -38,21 +37,21 @@ func SetupWebhook(mgr ctrl.Manager, apiType runtime.Object) error {
}

// Default implements webhook.CustomDefaulter so a webhook will be registered for the type
func (w *webhook) Default(_ context.Context, _ runtime.Object) error {
func (w *webhook) Default(context.Context, runtime.Object) error {
return nil
}

// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type
func (w *webhook) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
func (w *webhook) ValidateCreate(context.Context, runtime.Object) (admission.Warnings, error) {
return nil, nil
}

// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type
func (w *webhook) ValidateUpdate(_ context.Context, _, _ runtime.Object) (admission.Warnings, error) {
func (w *webhook) ValidateUpdate(context.Context, runtime.Object, runtime.Object) (admission.Warnings, error) {
return nil, nil
}

// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type
func (w *webhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
func (w *webhook) ValidateDelete(context.Context, runtime.Object) (admission.Warnings, error) {
return nil, nil
}
4 changes: 1 addition & 3 deletions pkg/controller/jobframework/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"

"sigs.k8s.io/kueue/pkg/controller/jobs/noop"
)

const (
Expand Down Expand Up @@ -100,7 +98,7 @@ func (m *integrationManager) setupControllers(ctx context.Context, mgr ctrl.Mana
}
}
}
if err := noop.SetupWebhook(mgr, cb.JobType); err != nil {
if err := setupNoopWebhook(mgr, cb.JobType); err != nil {
return fmt.Errorf("%s: unable to create noop webhook: %w", fwkNamePrefix, err)
}
return nil
Expand Down
66 changes: 66 additions & 0 deletions pkg/controller/jobs/deployment/deployment_controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
Copyright 2024 The Kubernetes 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 deployment

import (
"context"

appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

"sigs.k8s.io/kueue/pkg/controller/jobframework"
)

var (
gvk = appsv1.SchemeGroupVersion.WithKind("Deployment")
)

const (
FrameworkName = "deployment"
)

func init() {
utilruntime.Must(jobframework.RegisterIntegration(FrameworkName, jobframework.IntegrationCallbacks{
SetupIndexes: SetupIndexes,
NewReconciler: jobframework.NewNoopReconcilerFactory(gvk),
SetupWebhook: SetupWebhook,
JobType: &appsv1.Deployment{},
AddToScheme: appsv1.AddToScheme,
DependencyList: []string{"pod"},
}))
}

type Deployment appsv1.Deployment

func fromObject(o runtime.Object) *Deployment {
return (*Deployment)(o.(*appsv1.Deployment))
}

func (d *Deployment) Object() client.Object {
return (*appsv1.Deployment)(d)
}

func (d *Deployment) GVK() schema.GroupVersionKind {
return gvk
}

func SetupIndexes(context.Context, client.FieldIndexer) error {
return nil
}
Loading