Ejemplo n.º 1
0
// Run launches a template router using the provided options. It never exits.
func (o *TemplateRouterOptions) Run() error {
	pluginCfg := templateplugin.TemplatePluginConfig{
		WorkingDir:         o.WorkingDir,
		TemplatePath:       o.TemplateFile,
		ReloadScriptPath:   o.ReloadScript,
		DefaultCertificate: o.DefaultCertificate,
		StatsPort:          o.StatsPort,
		StatsUsername:      o.StatsUsername,
		StatsPassword:      o.StatsPassword,
		PeerService:        o.RouterService,
		IncludeUDP:         o.RouterSelection.IncludeUDP,
	}

	templatePlugin, err := templateplugin.NewTemplatePlugin(pluginCfg)
	if err != nil {
		return err
	}

	plugin := controller.NewUniqueHost(templatePlugin, controller.HostForRoute)

	oc, kc, err := o.Config.Clients()
	if err != nil {
		return err
	}

	factory := o.RouterSelection.NewFactory(oc, kc)
	controller := factory.Create(plugin)
	controller.Run()

	proc.StartReaper()

	select {}
}
Ejemplo n.º 2
0
func makeTemplatePlugin(cfg *templateRouterConfig) (*templateplugin.TemplatePlugin, error) {
	if cfg.TemplateFile == "" {
		return nil, errors.New("Template file must be specified")
	}

	if cfg.ReloadScript == "" {
		return nil, errors.New("Reload script must be specified")
	}

	statsPort := 0
	var err error = nil
	if cfg.StatsPort != "" {
		statsPort, err = strconv.Atoi(cfg.StatsPort)
		if err != nil {
			return nil, errors.New("Invalid stats port")
		}
	}

	templatePluginCfg := templateplugin.TemplatePluginConfig{
		TemplatePath:       cfg.TemplateFile,
		ReloadScriptPath:   cfg.ReloadScript,
		DefaultCertificate: cfg.DefaultCertificate,
		StatsPort:          statsPort,
		StatsUsername:      cfg.StatsUsername,
		StatsPassword:      cfg.StatsPassword,
		PeerService:        cfg.RouterService,
	}
	return templateplugin.NewTemplatePlugin(templatePluginCfg)
}
Ejemplo n.º 3
0
// makeTemplatePlugin creates a template router plugin.
func makeTemplatePlugin(cfg *routerConfig) (*templateplugin.TemplatePlugin, error) {
	if cfg.TemplateRouterConfig.TemplateFile == "" {
		return nil, errors.New("Template file must be specified")
	}

	if cfg.TemplateRouterConfig.ReloadScript == "" {
		return nil, errors.New("Reload script must be specified")
	}

	statsPort := 0
	var err error = nil
	if cfg.TemplateRouterConfig.StatsPort != "" {
		statsPort, err = strconv.Atoi(cfg.TemplateRouterConfig.StatsPort)
		if err != nil {
			return nil, errors.New("Invalid stats port")
		}
	}

	routerSvcNamespace := util.Env("ROUTER_SERVICE_NAMESPACE", "")
	routerSvcName := util.Env("ROUTER_SERVICE_NAME", "")
	cfg.TemplateRouterConfig.RouterService = ktypes.NamespacedName{
		Namespace: routerSvcNamespace,
		Name:      routerSvcName,
	}

	templatePluginCfg := templateplugin.TemplatePluginConfig{
		TemplatePath:       cfg.TemplateRouterConfig.TemplateFile,
		ReloadScriptPath:   cfg.TemplateRouterConfig.ReloadScript,
		DefaultCertificate: cfg.DefaultCertificate,
		StatsPort:          statsPort,
		StatsUsername:      cfg.TemplateRouterConfig.StatsUsername,
		StatsPassword:      cfg.TemplateRouterConfig.StatsPassword,
		PeerService:        cfg.TemplateRouterConfig.RouterService,
	}
	return templateplugin.NewTemplatePlugin(templatePluginCfg)
}