controllercmd

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package controllercmd is the controller group: osapi controller start, which runs the REST API. The package is not named controller, which is the controller itself.

Index

Constants

This section is empty.

Variables

View Source
var Defaults = config.Controller{
	Client: config.Client{URL: "https://localhost:8080"},
	API: config.APIServer{
		Port:       8080,
		JobTimeout: "30s",

		TLS: config.ServerTLS{Enabled: true},
	},
	NATS: config.NATSConnection{
		Host:       "localhost",
		Port:       4222,
		ClientName: "osapi-controller",
		Namespace:  "osapi",
		Auth:       config.NATSAuth{Type: "none"},
		TLS:        config.ClientTLS{Enabled: true},
	},
	Metrics: config.MetricsServer{
		Enabled: true, Host: "0.0.0.0", Port: 9090, TLS: config.ServerTLS{Enabled: true},
	},
	Notifications: config.NotificationsConfig{
		Enabled:          true,
		Notifier:         "log",
		RenotifyInterval: "5m",
	},
	UI: config.UIConfig{Enabled: true},

	Join: config.ControllerJoin{
		Callout: config.JoinCallout{Auth: config.NATSAuth{Type: "none"}},
	},
	PKI: config.ControllerPKI{
		KeyDir:              "/etc/osapi/pki",
		RotationGracePeriod: "24h",
	},

	Secrets: config.ControllerSecrets{Vaults: []vault.Spec{{
		Name:    "default",
		Type:    "nats",
		KeyFile: config.DefaultVaultKeyFile,
	}}},
}

Defaults are the defaults of the controller section of the config, which controller start owns: a key that the config file and the environment do not set takes its value from here. osapi config default get prints them.

View Source
var Group = command.Register(command.Define(
	"controller", "Run the controller",
	command.Flat(),
	command.Under(command.ParentController),
	command.Uses[Deps](),
	command.Config("controller", Defaults),
	command.Process("start").
		Short("Start the controller").
		Long("The controller serves the REST API, writes its heartbeat, and watches\n"+
			"conditions to send notifications.").
		Example("").
		Logs(StartLogs...).
		Example("--controller-api-port 9000").
		Flag("controller.api.port").
		Setup(Start),
))

Group is the controller group's definition. It is flat, Under controller, so its method is osapi controller start.

View Source
var StartLogs = []command.LogLine{
	{
		Level: slog.LevelInfo,
		Msg:   "CORS not configured, cross-origin browser requests will be refused",
		Attrs: []slog.Attr{
			slog.String("component", "controller"),
			slog.String("subsystem", "controller.api"),
			slog.String("configure", "controller.api.security.cors.allow_origins"),
		},
	},
	{
		Level: slog.LevelInfo,
		Msg:   "metrics cache refresh started",
		Attrs: []slog.Attr{
			slog.String("component", "controller"),
			slog.String("subsystem", "controller.health"),
			slog.String("interval", "15s"),
		},
	},
	{
		Level: slog.LevelInfo,
		Msg:   "embedded UI enabled",
		Attrs: []slog.Attr{
			slog.String("component", "controller"),
			slog.String("path", "/"),
		},
	},
	{
		Level: slog.LevelInfo,
		Msg:   "condition watcher started",
		Attrs: []slog.Attr{
			slog.String("component", "controller"),
			slog.String("subsystem", "controller.notify"),
		},
	},
	{
		Level: slog.LevelInfo,
		Msg:   "metrics server started",
		Attrs: []slog.Attr{
			slog.String("component", "controller"),
			slog.String("subsystem", "metrics"),
			slog.String("addr", "0.0.0.0:9090"),
		},
	},
	{
		Level: slog.LevelInfo,
		Msg:   "http(s) server started",
		Attrs: []slog.Attr{
			slog.String("component", "controller"),
			slog.String("subsystem", "metrics"),
			slog.String("address", "[::]:9090"),
		},
	},
	{
		Level: slog.LevelInfo,
		Msg:   "starting server",
		Attrs: []slog.Attr{
			slog.String("component", "controller"),
			slog.String("subsystem", "controller.api"),
		},
	},
	{
		Level: slog.LevelInfo,
		Msg:   "http(s) server started",
		Attrs: []slog.Attr{
			slog.String("component", "controller"),
			slog.String("subsystem", "controller.api"),
			slog.String("address", "[::]:8080"),
		},
	},
	{
		Level: slog.LevelInfo,
		Msg:   "metrics cache initialized",
		Attrs: []slog.Attr{
			slog.String("component", "controller"),
			slog.String("subsystem", "controller.health"),
			slog.String("next_in", "15s"),
		},
	},
	{
		Level: slog.LevelInfo,
		Msg:   "registered in component registry",
		Attrs: []slog.Attr{
			slog.String("component", "controller"),
			slog.String("subsystem", "controller.heartbeat"),
			slog.String("hostname", "web-03"),
			slog.String("type", "controller"),
			slog.String("key", "controller.web-03"),
		},
	},
}

StartLogs are the lines that the controller writes at the info level when it starts with the default config, which the docs page of the command shows as the log handler writes them. osapi start writes them too.

Functions

func Components

func Components(
	ctx context.Context,
	d Deps,
) (command.Running, error)

Components makes the controller, and its metrics server when the config turns it on: the parts that osapi start runs too. The metrics server also serves the HTTP metrics of the API, so it is made first.

func Start

func Start(
	ctx context.Context,
	d Deps,
) (command.Running, error)

Start logs the config, with no secret in it, starts the tracer, sets the namespace of the job subjects, then makes the components. The tracer stops after them.

Types

type Controller

type Controller interface {
	command.Component
	CheckHealth(ctx context.Context) error
	SubComponents() map[string]job.SubComponentInfo
}

Controller is the controller, which controller.New makes.

type Deps

type Deps struct {
	Config     config.Config
	ConfigFile string
	Logger     *slog.Logger
	Version    string
	// Tracer starts the tracer of the service name, and returns what
	// flushes and stops it.
	Tracer        func(ctx context.Context, name string) (func(context.Context) error, error)
	NewController func(
		ctx context.Context,
		log *slog.Logger,
		cfg config.Config,
		opts ...controller.Option,
	) (Controller, error)
}

Deps is what start uses: the config, the log, the version of the binary, and what starts the tracer and makes the controller.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL