server

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 24 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 server provides HTTP routes and webhook handlers.

Index

Constants

View Source
const ReconcileTimeout = 20 * time.Second

ReconcileTimeout caps the background work for a single reconcile, shared by every service it deploys or by its teardown.

Variables

This section is empty.

Functions

This section is empty.

Types

type DeployRequest

type DeployRequest struct {
	Service        string `json:"service"`
	HeadRef        string `json:"head_ref"`
	CommitSha      string `json:"commit_sha"`
	PRAuthor       string `json:"pr_author"`
	PRURL          string `json:"pr_url"`
	PRNumber       string `json:"pr_number"`
	WorkflowRunURL string `json:"workflow_run_url"`
}

DeployRequest is the body of POST /v1/deploy. All fields are required; the server stamps timestamp from time.Now() so retries don't drift.

type DeployResponse

type DeployResponse struct {
	PreviewSlug     string   `json:"preview_slug"`
	GitOpsCommitURL string   `json:"gitops_commit_url"`
	Warnings        []string `json:"warnings,omitempty"`
}

DeployResponse is the success body. Warnings is populated when the values write succeeded but the comment fan-out had partial failures.

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

ErrorResponse is the failure body for every non-2xx response.

type Option

type Option func(*Server)

Option configures a Server built by NewServer.

func WithMetrics

func WithMetrics(m *metrics.Metrics) Option

WithMetrics records webhook deliveries and lifecycle outcomes in m.

func WithNamespaces added in v0.28.0

func WithNamespaces(c namespace.Checker) Option

WithNamespaces checks the namespace of each new preview through c before it is written (namespace.Checker). Without it, no namespace is checked.

func WithPreviewTTL added in v0.26.0

func WithPreviewTTL(ttl time.Duration) Option

WithPreviewTTL sets the TTL of the in-server sweep, which a preview's expiresAt adds to its updatedAt; 0, the default, omits expiresAt.

func WithReadToken added in v0.26.0

func WithReadToken(token string) Option

WithReadToken enables the GET /v1 routes with the Bearer token, besides the deploy token. An empty token leaves them to the deploy token alone.

func WithStatus added in v0.26.0

func WithStatus(token string, st *status.Store) Option

WithStatus enables POST /webhooks/status, authenticated by the Bearer token, recording into st. An empty token leaves the route unregistered.

func WithWake added in v0.26.0

func WithWake(w *Wake) Option

WithWake has the wait routes block on w, which the caller also notifies on the changes the server does not see itself: a landed Apply (store.WithApplied) and a fetch that moved the gitops head (store.WithHeadMoved). Without it, the server makes its own.

type PRJSON added in v0.26.0

type PRJSON struct {
	Repo   string `json:"repo"`
	Number int    `json:"number"`
	URL    string `json:"url"`
}

PRJSON is a pull request: owner/repo, number and URL, from the pr-url of the entry.

type PinnedJSON added in v0.26.0

type PinnedJSON struct {
	SHA    string `json:"sha"`
	PR     PRJSON `json:"pr"`
	Author string `json:"author"`
}

PinnedJSON is the pin of a pinned entry: its commit and the PR that pinned it.

type PreviewEntryJSON added in v0.26.0

type PreviewEntryJSON struct {
	Name     string      `json:"name"`
	Kind     string      `json:"kind"`
	Pinned   *PinnedJSON `json:"pinned,omitempty"`
	Branch   string      `json:"branch,omitempty"`
	URL      string      `json:"url,omitempty"`
	Status   string      `json:"status"`
	Revision string      `json:"revision,omitempty"`
	StatusAt string      `json:"statusAt,omitempty"`
}

PreviewEntryJSON is a service or dependency entry of a preview.

type PreviewJSON added in v0.26.0

type PreviewJSON struct {
	Slug      string             `json:"slug"`
	CreatedAt string             `json:"createdAt,omitempty"`
	UpdatedAt string             `json:"updatedAt,omitempty"`
	ExpiresAt string             `json:"expiresAt,omitempty"`
	Services  []PreviewEntryJSON `json:"services"`
}

PreviewJSON is a preview in the read API: its file in the gitops clone and its status in memory. CreatedAt and UpdatedAt are the oldest created-at and the newest updated-at of its pinned entries, and ExpiresAt is UpdatedAt plus the in-server sweep's TTL; each is omitted when unknown.

type PreviewList added in v0.26.0

type PreviewList struct {
	Previews []PreviewJSON `json:"previews"`
}

PreviewList is the body of GET /v1/previews.

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(
	f forge.Forge,
	st storeAPI,
	deployToken string,
	opts ...Option,
) *Server

NewServer returns the server of the webhooks of f, over the gitops repo st, configured by opts. The deploy API is served only when deployToken is set, and the read API when deployToken or the read token is.

func (*Server) EndWaits added in v0.26.0

func (s *Server) EndWaits()

EndWaits ends every blocked wait, which answers its current state at once, and every later one after its first evaluation. It is registered with http.Server.RegisterOnShutdown, so shutdown does not wait for long polls.

func (*Server) Go

func (s *Server) Go(f func())

Go runs f in the background, tracked by WaitBackground. Unlike reconciles, f does not wait for other background jobs.

func (*Server) Handler

func (s *Server) Handler() http.Handler

func (*Server) QueueReconcile added in v0.26.0

func (s *Server) QueueReconcile(ctx context.Context, ev lifecycle.Event, done func(lifecycle.ReconcileResult))

QueueReconcile reconciles ev in a background job (runJob), as a pull_request delivery does: after the jobs before it, alone, and capped at the job timeout. done gets ReconcilePR's result once it completes, or the failed outcome at ev's head SHA when it panics; that result is first recorded as the PR's latest outcome (RecordOutcome). It is a lifecycle.ReconcileFunc.

func (*Server) RecordCatchUpSkip added in v0.26.0

func (s *Server) RecordCatchUpSkip(t lifecycle.Target, res lifecycle.ReconcileResult, listedAt time.Time)

RecordCatchUpSkip records res, the skip catch-up gives a PR it filters out, as the latest outcome of the PR of t, and wakes the waits, only when the PR's stored outcome was recorded before listedAt, the time catch-up started listing the PR's repo. A stale listing then never replaces an outcome a reconcile recorded after it.

func (*Server) RecordOutcome added in v0.26.0

func (s *Server) RecordOutcome(t lifecycle.Target, res lifecycle.ReconcileResult)

RecordOutcome records res as the latest reconcile outcome of the PR of t, replacing the one before, and wakes the waits. A skip for a label that is not a preview label (lifecycle.OtherLabelReason) is not recorded: the event did not concern the PR's preview.

func (*Server) WaitBackground

func (s *Server) WaitBackground(ctx context.Context) error

WaitBackground blocks until every background job has finished. It returns nil once they are done, or ctx.Err() when ctx expires first.

type SyncRequest added in v0.21.0

type SyncRequest struct {
	Slug *string `json:"slug"`
}

SyncRequest is the optional body of POST /v1/sync. Without a slug, every preview is synced.

type SyncResponse added in v0.21.0

type SyncResponse struct {
	Synced    []string `json:"synced"`
	Unchanged int      `json:"unchanged"`
	Failed    []string `json:"failed"`
}

SyncResponse is the success body of POST /v1/sync: the slugs rewritten, the number of previews left unchanged and the slugs that failed.

type WaitEntryJSON added in v0.26.0

type WaitEntryJSON struct {
	Name     string `json:"name"`
	Kind     string `json:"kind"`
	Status   string `json:"status"`
	Revision string `json:"revision,omitempty"`
	Ready    bool   `json:"ready"`
	URL      string `json:"url,omitempty"`
}

WaitEntryJSON is an entry of a wait set: its latest status ("unknown" when none) and revision, whether it is ready, and its URL.

type WaitResponse added in v0.26.0

type WaitResponse struct {
	State    string            `json:"state"`
	Reason   string            `json:"reason,omitempty"`
	Slug     string            `json:"slug,omitempty"`
	SHA      string            `json:"sha,omitempty"`
	Services []WaitEntryJSON   `json:"services"`
	URLs     map[string]string `json:"urls"`
}

WaitResponse is the body of a wait's answer: its state, the reason of a failed, refused or skipped state, the preview and the SHA waited for when known, and the wait set's entries with the URLs of those that have one.

type Wake added in v0.26.0

type Wake struct {
	// contains filtered or unexported fields
}

Wake is a broadcast signal: each Notify wakes every goroutine blocked on the channel wait returned before it. Its methods are safe for concurrent use, and Notify never blocks.

func NewWake added in v0.26.0

func NewWake() *Wake

NewWake returns a Wake no one waits on yet.

func (*Wake) Notify added in v0.26.0

func (w *Wake) Notify()

Notify wakes every waiter: it closes the current channel and replaces it.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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