mirror of
https://github.com/rancher/types.git
synced 2025-08-08 15:57:17 +00:00
Simplify startup
This commit is contained in:
parent
188326b31d
commit
6bef2175e1
@ -18,17 +18,35 @@ import (
|
||||
type ClusterContext struct {
|
||||
RESTConfig rest.Config
|
||||
UnversionedClient rest.Interface
|
||||
Cluster clusterv1.Interface
|
||||
Authorization authzv1.Interface
|
||||
|
||||
Cluster clusterv1.Interface
|
||||
Authorization authzv1.Interface
|
||||
}
|
||||
|
||||
func (c *ClusterContext) controllers() []controller.Starter {
|
||||
return []controller.Starter{
|
||||
c.Cluster,
|
||||
c.Authorization,
|
||||
}
|
||||
}
|
||||
|
||||
type WorkloadContext struct {
|
||||
Cluster *ClusterContext
|
||||
ClusterName string
|
||||
RESTConfig rest.Config
|
||||
UnversionedClient rest.Interface
|
||||
Apps appsv1beta2.Interface
|
||||
Workload workloadv1.Interface
|
||||
Core corev1.Interface
|
||||
|
||||
Apps appsv1beta2.Interface
|
||||
Workload workloadv1.Interface
|
||||
Core corev1.Interface
|
||||
}
|
||||
|
||||
func (w *WorkloadContext) controllers() []controller.Starter {
|
||||
return []controller.Starter{
|
||||
w.Apps,
|
||||
w.Workload,
|
||||
w.Core,
|
||||
}
|
||||
}
|
||||
|
||||
func NewClusterContext(config rest.Config) (*ClusterContext, error) {
|
||||
@ -63,25 +81,8 @@ func NewClusterContext(config rest.Config) (*ClusterContext, error) {
|
||||
}
|
||||
|
||||
func (c *ClusterContext) Start(ctx context.Context) error {
|
||||
logrus.Info("Syncing cluster controllers")
|
||||
err := controller.Sync(ctx,
|
||||
c.Cluster,
|
||||
c.Authorization)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Info("Starting cluster controllers")
|
||||
if err := c.Cluster.Start(ctx, 5); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := c.Authorization.Start(ctx, 5); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Info("Cluster context started")
|
||||
return nil
|
||||
return controller.SyncThenSync(ctx, 5, c.controllers()...)
|
||||
}
|
||||
|
||||
func (c *ClusterContext) StartAndWait() error {
|
||||
@ -91,7 +92,7 @@ func (c *ClusterContext) StartAndWait() error {
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
func NewWorkloadContext(clusterConfig, config rest.Config) (*WorkloadContext, error) {
|
||||
func NewWorkloadContext(clusterConfig, config rest.Config, clusterName string) (*WorkloadContext, error) {
|
||||
var err error
|
||||
context := &WorkloadContext{
|
||||
RESTConfig: config,
|
||||
@ -130,3 +131,17 @@ func NewWorkloadContext(clusterConfig, config rest.Config) (*WorkloadContext, er
|
||||
|
||||
return context, err
|
||||
}
|
||||
|
||||
func (w *WorkloadContext) Start(ctx context.Context) error {
|
||||
logrus.Info("Starting workload controllers")
|
||||
controllers := w.Cluster.controllers()
|
||||
controllers = append(controllers, w.controllers()...)
|
||||
return controller.SyncThenSync(ctx, 5, controllers...)
|
||||
}
|
||||
|
||||
func (w *WorkloadContext) StartAndWait() error {
|
||||
ctx := signal.SigTermCancelContext(context.Background())
|
||||
w.Start(ctx)
|
||||
<-ctx.Done()
|
||||
return ctx.Err()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user