Skip to content

Commit

Permalink
chore: restruct workspace controller code - part 4 (#685)
Browse files Browse the repository at this point in the history
Split webhook.go for workspace and ragengine controller individually.
  • Loading branch information
Fei-Guo authored Nov 10, 2024
1 parent a057d70 commit fcd5d1c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 23 deletions.
2 changes: 1 addition & 1 deletion cmd/ragengine/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"

"github.com/kaito-project/kaito/pkg/ragengine/controllers"
"github.com/kaito-project/kaito/pkg/webhooks"
"github.com/kaito-project/kaito/pkg/ragengine/webhooks"
"k8s.io/api/apps/v1beta1"
"k8s.io/klog/v2"
"knative.dev/pkg/injection/sharedmain"
Expand Down
2 changes: 1 addition & 1 deletion cmd/workspace/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"sigs.k8s.io/karpenter/pkg/apis/v1beta1"

"github.com/aws/karpenter-core/pkg/apis/v1alpha5"
"github.com/kaito-project/kaito/pkg/webhooks"
"github.com/kaito-project/kaito/pkg/workspace/controllers"
"github.com/kaito-project/kaito/pkg/workspace/webhooks"
"k8s.io/klog/v2"
"knative.dev/pkg/injection/sharedmain"
"knative.dev/pkg/webhook"
Expand Down
21 changes: 0 additions & 21 deletions pkg/webhooks/webhooks.go → pkg/ragengine/webhooks/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,6 @@ import (
kaitov1alpha1 "github.com/kaito-project/kaito/api/v1alpha1"
)

func NewWorkspaceWebhooks() []knativeinjection.ControllerConstructor {
return []knativeinjection.ControllerConstructor{
certificates.NewController,
NewWorkspaceCRDValidationWebhook,
}
}

func NewWorkspaceCRDValidationWebhook(ctx context.Context, _ configmap.Watcher) *controller.Impl {
return validation.NewAdmissionController(ctx,
"validation.workspace.kaito.sh",
"/validate/workspace.kaito.sh",
WorkspaceResources,
func(ctx context.Context) context.Context { return ctx },
true,
)
}

var WorkspaceResources = map[schema.GroupVersionKind]resourcesemantics.GenericCRD{
kaitov1alpha1.GroupVersion.WithKind("Workspace"): &kaitov1alpha1.Workspace{},
}

func NewRAGEngineWebhooks() []knativeinjection.ControllerConstructor {
return []knativeinjection.ControllerConstructor{
certificates.NewController,
Expand Down
38 changes: 38 additions & 0 deletions pkg/workspace/webhooks/webhooks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
package webhooks

import (
"context"

"k8s.io/apimachinery/pkg/runtime/schema"
"knative.dev/pkg/configmap"
"knative.dev/pkg/controller"
knativeinjection "knative.dev/pkg/injection"
"knative.dev/pkg/webhook/certificates"
"knative.dev/pkg/webhook/resourcesemantics"
"knative.dev/pkg/webhook/resourcesemantics/validation"

kaitov1alpha1 "github.com/kaito-project/kaito/api/v1alpha1"
)

func NewWorkspaceWebhooks() []knativeinjection.ControllerConstructor {
return []knativeinjection.ControllerConstructor{
certificates.NewController,
NewWorkspaceCRDValidationWebhook,
}
}

func NewWorkspaceCRDValidationWebhook(ctx context.Context, _ configmap.Watcher) *controller.Impl {
return validation.NewAdmissionController(ctx,
"validation.workspace.kaito.sh",
"/validate/workspace.kaito.sh",
WorkspaceResources,
func(ctx context.Context) context.Context { return ctx },
true,
)
}

var WorkspaceResources = map[schema.GroupVersionKind]resourcesemantics.GenericCRD{
kaitov1alpha1.GroupVersion.WithKind("Workspace"): &kaitov1alpha1.Workspace{},
}

0 comments on commit fcd5d1c

Please sign in to comment.