43 lines
1.0 KiB
Go
43 lines
1.0 KiB
Go
package application
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"k8s.io/klog/v2"
|
|
"sigs.k8s.io/controller-runtime/pkg/manager"
|
|
|
|
applicationv1 "code.gitea.io/gitea/modules/k8s/api/application/v1"
|
|
)
|
|
|
|
// Controller 实现 controller.Controller 接口
|
|
type Controller struct{}
|
|
|
|
// Name 返回控制器名称
|
|
func (c *Controller) Name() string {
|
|
return "application"
|
|
}
|
|
|
|
// Init 初始化控制器
|
|
func (c *Controller) Init(mgr manager.Manager) error {
|
|
// 添加 API 到 scheme
|
|
klog.InfoS("Adding Application API to scheme")
|
|
if err := applicationv1.AddToScheme(mgr.GetScheme()); err != nil {
|
|
return fmt.Errorf("unable to add Application API to scheme: %w", err)
|
|
}
|
|
|
|
// 创建 Application reconciler
|
|
klog.InfoS("Creating Application reconciler")
|
|
reconciler := &ApplicationReconciler{
|
|
Client: mgr.GetClient(),
|
|
Scheme: mgr.GetScheme(),
|
|
}
|
|
|
|
// 设置 reconciler 与 manager
|
|
klog.InfoS("Setting up Application with manager")
|
|
if err := reconciler.SetupWithManager(mgr); err != nil {
|
|
return fmt.Errorf("failed to setup Application controller: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|