server

package
v1.11.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: Apache-2.0 Imports: 80 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GroupByImageRepository = "image_repo"
	GroupByGitRepository   = "git_repo"
	GroupByChartRepository = "chart_repo"

	OrderByFirstSeen = "first_seen"
	OrderByTag       = "tag"
)
View Source
const CLIVersionHeader = "X-Kargo-CLI-Version"

CLIVersionHeader is the HTTP header used to convey the CLI version in requests to the API server.

TODO(krancour): Move this closer to CLI-version-checking middleware once it exists.

Variables

This section is empty.

Functions

func ConvertAndSendWatchEvent

func ConvertAndSendWatchEvent[T any](c *gin.Context, e watch.Event, target T) bool

ConvertAndSendWatchEvent converts a watch event's object to the target type and sends it as an SSE event. It handles both unstructured objects (from real clients) and typed objects (from fake clients in tests). Returns true if the caller should continue processing (including on conversion errors), false if the watch should be terminated (write failure or a watch.Error event).

func ConvertWatchEventObject

func ConvertWatchEventObject[T any](c *gin.Context, e watch.Event, _ T) (T, bool)

ConvertWatchEventObject converts a watch event's object to the target type. It handles both unstructured objects (from real clients) and typed objects (from fake clients in tests). Returns the converted object and true if successful, or the zero value and false if conversion failed.

func ErrorFromWatchEvent

func ErrorFromWatchEvent(e watch.Event) error

ErrorFromWatchEvent maps Kubernetes watch.Error events into client-visible errors that watch handlers can return or stream.

func FilteredWatchEventType

func FilteredWatchEventType(eventType watch.EventType, matches bool) (watch.EventType, bool)

FilteredWatchEventType returns the event type to send for a client-side filtered watch event. Kubernetes server-side selectors send a DELETED event when a previously matching object is modified so it no longer matches; this helper mirrors that behavior for filters we must evaluate in-process.

Because we hold no per-client matched set, we cannot tell whether a non-matching MODIFIED object previously matched, so we emit a synthetic DELETED for every non-matching MODIFIED event — including objects the client never received an ADDED for. This over-emits DELETEs relative to a real server-side selector, but a DELETE for an object the client is not tracking is a harmless no-op. Achieving exact fidelity would require tracking sent object identities per client, which is not worth the complexity here.

func NewAuthMiddleware

func NewAuthMiddleware(
	ctx context.Context,
	cfg config.ServerConfig,
	client libClient.Client,
	opts ...AuthMiddlewareOpt,
) gin.HandlerFunc

NewAuthMiddleware returns an initialized Gin middleware handler for authentication.

func NewHealthChecker

func NewHealthChecker() grpchealth.Checker

func SendSSEWatchError

func SendSSEWatchError(c *gin.Context, err error)

SendSSEWatchError sends a watch error as an SSE error event. Watch endpoints may have already sent response headers, so HTTP status codes are no longer a reliable way to report expired resource versions after streaming begins.

func SendSSEWatchEvent

func SendSSEWatchEvent[T any](c *gin.Context, eventType watch.EventType, obj T) bool

SendSSEWatchEvent sends an object as an SSE watch event. Returns true if the caller should continue processing, false if the watch should be terminated (write failure).

func SendSSEWatchStartError

func SendSSEWatchStartError(c *gin.Context, err error) bool

SendSSEWatchStartError sends startup watch errors that are part of the watch protocol as SSE error events. It returns true when the error was handled.

func SetSSEHeaders

func SetSSEHeaders(c *gin.Context)

SetSSEHeaders configures the standard headers for Server-Sent Events (SSE) streaming on a gin context.

func WriteSSEKeepalive

func WriteSSEKeepalive(c *gin.Context) bool

WriteSSEKeepalive writes a keepalive comment to keep the SSE connection alive. Returns true if successful, false if the write failed.

Types

type AuthMiddlewareOpt

type AuthMiddlewareOpt func(*authMiddleware)

AuthMiddlewareOpt is a functional option for configuring the auth middleware returned by NewAuthMiddleware.

func WithExemptPaths

func WithExemptPaths(paths []string) AuthMiddlewareOpt

WithExemptPaths adds additional exempt paths for the auth middleware. These are added to the default exempt paths, which are /v1beta1/system/public-server-config and /v1beta1/login.

type ImageStageMap added in v1.8.8

type ImageStageMap struct {
	Stages map[string]int32 `json:"stages"`

} // @name ImageStageMap

ImageStageMap represents the stages where an image is used

type RefreshResourceType added in v1.8.8

type RefreshResourceType string

RefreshResourceType represents the type of Kargo resource to refresh.

const (
	RefreshResourceTypeClusterConfig RefreshResourceType = "ClusterConfig"
	RefreshResourceTypeProjectConfig RefreshResourceType = "ProjectConfig"
	RefreshResourceTypeStage         RefreshResourceType = "Stage"
	RefreshResourceTypeWarehouse     RefreshResourceType = "Warehouse"
)

RefreshResourceType constants for supported resource types. They are PascalCase representations of the Kargo resource kinds for compatibility purposes with Kubernetes REST mappers.

func (RefreshResourceType) IsNamespaced added in v1.8.8

func (t RefreshResourceType) IsNamespaced() bool

IsNamespaced returns true if the resource type is namespaced.

func (RefreshResourceType) NameEqualsProject added in v1.8.8

func (t RefreshResourceType) NameEqualsProject() bool

NameEqualsProject returns true if the name of the resource should be the same as the project name. This is true for ProjectConfig resources.

func (RefreshResourceType) String added in v1.8.8

func (t RefreshResourceType) String() string

String returns the string representation of the RefreshResourceType.

type Server

type Server interface {
	Serve(ctx context.Context, l net.Listener) error
}

func NewServer

func NewServer(
	cfg config.ServerConfig,
	kubeClient kubernetes.Client,
	rolesDB rbac.RolesDatabase,
	sender event.Sender,
) Server

type TagMap added in v1.8.8

type TagMap struct {
	Tags map[string]*ImageStageMap `json:"tags"`

} // @name TagMap

TagMap represents the tags for a repository

type WatchEvent added in v1.8.8

type WatchEvent[T any] struct {
	Type   string `json:"type"`
	Object T      `json:"object"`
}

WatchEvent represents a watch event in an SSE stream. It contains the event type (ADDED, MODIFIED, DELETED) and the object that was affected.

Source Files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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