Documentation
¶
Index ¶
- Constants
- func GenerateJSONConfig(containers []api.ServiceContainer, verifyResponse string) (*caddy.Config, error)
- type CaddyAdminClient
- func (c *CaddyAdminClient) Adapt(ctx context.Context, caddyfile string) (string, error)
- func (c *CaddyAdminClient) IsAvailable(ctx context.Context) bool
- func (c *CaddyAdminClient) Load(ctx context.Context, caddyfile string) error
- func (c *CaddyAdminClient) Validate(ctx context.Context, caddyfile string) error
- type CaddyfileGenerator
- type CaddyfileValidator
- type Controller
- type Server
- type Service
Constants ¶
const ( CaddyServiceName = "caddy" CaddyGroup = "uncloud" VerifyPath = "/.uncloud-verify" )
Variables ¶
This section is empty.
Functions ¶
func GenerateJSONConfig ¶ added in v0.11.1
Types ¶
type CaddyAdminClient ¶ added in v0.12.1
type CaddyAdminClient struct {
// contains filtered or unexported fields
}
CaddyAdminClient is a client for interacting with the Caddy admin API over a Unix socket.
func NewCaddyAdminClient ¶ added in v0.12.1
func NewCaddyAdminClient(socketPath string) *CaddyAdminClient
func (*CaddyAdminClient) Adapt ¶ added in v0.12.1
Adapt converts a Caddyfile to JSON configuration without loading or running it.
func (*CaddyAdminClient) IsAvailable ¶ added in v0.12.1
func (c *CaddyAdminClient) IsAvailable(ctx context.Context) bool
IsAvailable checks if the local Caddy instance is running and responding to admin API requests.
func (*CaddyAdminClient) Load ¶ added in v0.12.1
func (c *CaddyAdminClient) Load(ctx context.Context, caddyfile string) error
Load loads a Caddyfile configuration into the Caddy instance running on the machine. Due to a Caddy bug (https://github.com/caddyserver/caddy/issues/7246), we first adapt the Caddyfile to JSON and then load the JSON config to get proper error handling.
func (*CaddyAdminClient) Validate ¶ added in v0.12.1
func (c *CaddyAdminClient) Validate(ctx context.Context, caddyfile string) error
Validate checks if the provided Caddyfile can be adapted to Caddy JSON config using the running Caddy instance via its admin API. It doesn't guarantee that the Caddyfile is actually valid and can be loaded. For example, a tls directive with a missing certificate will pass the adaptation but will fail when Caddy tries to load it. But this is the best we can do over the admin API. TODO: run 'docker exec caddy-container caddy validate' to do proper validation or implement a Caddy module that exposes a validation endpoint.
type CaddyfileGenerator ¶ added in v0.12.0
type CaddyfileGenerator struct {
// contains filtered or unexported fields
}
CaddyfileGenerator generates a Caddyfile configuration for the Caddy reverse proxy.
func NewCaddyfileGenerator ¶ added in v0.12.0
func NewCaddyfileGenerator(machineID string, validator CaddyfileValidator, log *slog.Logger) *CaddyfileGenerator
func (*CaddyfileGenerator) Generate ¶ added in v0.12.0
func (g *CaddyfileGenerator) Generate( ctx context.Context, records []store.ContainerRecord, includeCustom bool, ) (string, error)
Generate creates a Caddyfile configuration based on the provided service containers. The Caddyfile is generated from the service ports of the healthy containers. If a 'caddy' service container is running on this machine and defines a custom Caddy config (x-caddy) in its service spec, it will be validated and prepended to the generated Caddyfile. Custom Caddy configs (x-caddy) defined in other service specs are validated and appended to the generated Caddyfile. Invalid configs are logged and skipped to ensure the generated Caddyfile remains valid.
The final Caddyfile structure includes:
[caddy x-caddy (global config)] [generated Caddyfile from all service ports] [service-a x-caddy] ... [service-z x-caddy]
If includeCustom is false, custom Caddy configs (x-caddy) are not included in the generated Caddyfile.
type CaddyfileValidator ¶ added in v0.12.0
CaddyfileValidator is an interface for validating Caddyfile configurations.
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller monitors container changes in the cluster store and generates a configuration file for Caddy reverse proxy. The generated configuration allows Caddy to route external traffic to service containers across the internal network.
func NewController ¶
func NewController(machineID, configDir, adminSock string, store *store.Store) (*Controller, error)
type Server ¶ added in v0.12.0
type Server struct {
pb.UnimplementedCaddyServer
// contains filtered or unexported fields
}
Server implements the gRPC Caddy service.
type Service ¶ added in v0.12.0
type Service struct {
// contains filtered or unexported fields
}
Service provides methods to interact with the Caddy configuration on the machine.
func NewService ¶ added in v0.12.0
NewService creates a new Service instance with the specified Caddy configuration directory.