Skip to content

Commit

Permalink
Implement evpa-controller
Browse files Browse the repository at this point in the history
  • Loading branch information
qmhu committed Mar 4, 2022
1 parent d4735d4 commit ea9d137
Show file tree
Hide file tree
Showing 11 changed files with 1,219 additions and 815 deletions.
81 changes: 45 additions & 36 deletions cmd/craned/app/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/gocrane/crane/pkg/controller/analytics"
"github.com/gocrane/crane/pkg/controller/cnp"
"github.com/gocrane/crane/pkg/controller/ehpa"
"github.com/gocrane/crane/pkg/controller/evpa"
"github.com/gocrane/crane/pkg/controller/noderesource"
"github.com/gocrane/crane/pkg/controller/recommendation"
"github.com/gocrane/crane/pkg/controller/timeseriesprediction"
Expand All @@ -53,7 +54,6 @@ var (
func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(predictionapi.AddToScheme(scheme))
utilruntime.Must(analysisapi.AddToScheme(scheme))
utilruntime.Must(ensuranceapi.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme

Expand Down Expand Up @@ -116,41 +116,8 @@ func Run(ctx context.Context, opts *options.Options) error {
initializationWebhooks(mgr)
}
initializationControllers(ctx, mgr, opts)
klog.Info("Starting crane manager")

// initialization custom collector metrics
initializationMetricCollector(mgr)

var eg errgroup.Group

eg.Go(func() error {
if err := mgr.Start(ctx); err != nil {
klog.Error(err, "problem running crane manager")
klog.Exit(err)
}
return nil
})

eg.Go(func() error {
// Start the craned web server
serverConfig := serverconfig.NewServerConfig()
if err := opts.ApplyTo(serverConfig); err != nil {
klog.Exit(err)
}
// use controller runtime rest config, we can not refer kubeconfig option directly because it is unexported variable in vendor/sigs.k8s.io/controller-runtime/pkg/client/config/config.go
serverConfig.KubeRestConfig = mgr.GetConfig()
craneServer, err := server.NewServer(serverConfig)
if err != nil {
klog.Exit(err)
}
craneServer.Run(ctx)
return nil
})

// wait for all components exit
if err := eg.Wait(); err != nil {
klog.Fatal(err)
}
runAll(ctx, mgr, opts)

return nil
}
Expand Down Expand Up @@ -221,6 +188,14 @@ func initializationControllers(ctx context.Context, mgr ctrl.Manager, opts *opti
}).SetupWithManager(mgr); err != nil {
klog.Exit(err, "unable to create controller", "controller", "HPAReplicasController")
}

if err := (&evpa.EffectiveVPAController{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("effective-vpa-controller"),
}).SetupWithManager(mgr); err != nil {
klog.Exit(err, "unable to create controller", "controller", "EffectiveVPAController")
}
}

var dataSource providers.Interface
Expand Down Expand Up @@ -271,10 +246,11 @@ func initializationControllers(ctx context.Context, mgr ctrl.Manager, opts *opti
if err := tspController.SetupWithManager(mgr); err != nil {
klog.Exit(err, "unable to create controller", "controller", "TspController")
}

}

if analysis {
utilruntime.Must(analysisapi.AddToScheme(scheme))

if err := (&analytics.Controller{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Expand Down Expand Up @@ -325,3 +301,36 @@ func initializationControllers(ctx context.Context, mgr ctrl.Manager, opts *opti
}
}
}

func runAll(ctx context.Context, mgr ctrl.Manager, opts *options.Options) {
var eg errgroup.Group

eg.Go(func() error {
if err := mgr.Start(ctx); err != nil {
klog.Error(err, "problem running crane manager")
klog.Exit(err)
}
return nil
})

eg.Go(func() error {
// Start the craned web server
serverConfig := serverconfig.NewServerConfig()
if err := opts.ApplyTo(serverConfig); err != nil {
klog.Exit(err)
}
// use controller runtime rest config, we can not refer kubeconfig option directly because it is unexported variable in vendor/sigs.k8s.io/controller-runtime/pkg/client/config/config.go
serverConfig.KubeRestConfig = mgr.GetConfig()
craneServer, err := server.NewServer(serverConfig)
if err != nil {
klog.Exit(err)
}
craneServer.Run(ctx)
return nil
})

// wait for all components exit
if err := eg.Wait(); err != nil {
klog.Fatal(err)
}
}
Loading

0 comments on commit ea9d137

Please sign in to comment.