Documentation
¶
Overview ¶
Package server provides HTTP routes and webhook handlers.
Index ¶
- Constants
- type DeployRequest
- type DeployResponse
- type ErrorResponse
- type Option
- type PRJSON
- type PinnedJSON
- type PreviewEntryJSON
- type PreviewJSON
- type PreviewList
- type Server
- func (s *Server) EndWaits()
- func (s *Server) Go(f func())
- func (s *Server) Handler() http.Handler
- func (s *Server) QueueReconcile(ctx context.Context, ev lifecycle.Event, done func(lifecycle.ReconcileResult))
- func (s *Server) RecordCatchUpSkip(t lifecycle.Target, res lifecycle.ReconcileResult, listedAt time.Time)
- func (s *Server) RecordOutcome(t lifecycle.Target, res lifecycle.ReconcileResult)
- func (s *Server) WaitBackground(ctx context.Context) error
- type SyncRequest
- type SyncResponse
- type WaitEntryJSON
- type WaitResponse
- type Wake
Constants ¶
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 ¶
WithMetrics records webhook deliveries and lifecycle outcomes in m.
func WithNamespaces ¶ added in v0.28.0
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
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
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
WithStatus enables POST /webhooks/status, authenticated by the Bearer token, recording into st. An empty token leaves the route unregistered.
type PRJSON ¶ added in v0.26.0
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 ¶
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) 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.
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.