wasm

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPurgeInterval         = 1 * time.Hour
	DefaultModuleExpiry          = 24 * time.Hour
	DefaultHTTPRequestTimeout    = 15 * time.Second
	DefaultHTTPRequestMaxRetries = 5
	DefaultPullTimeout           = 5 * time.Minute
	DefaultMaxCacheSize          = 1024 * 1024 * 1024 // 1GB
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Get(downloadURL string, opts GetOptions) (url string, checksum string, err error)
	Start(ctx context.Context)
}

Cache models a Wasm module cache.

type CacheOptions

type CacheOptions struct {
	PurgeInterval time.Duration
	ModuleExpiry  time.Duration
	// InsecureRegistries is a set of registries that are allowed to be accessed without TLS.
	InsecureRegistries    sets.Set[string]
	HTTPRequestTimeout    time.Duration
	HTTPRequestMaxRetries int
	MaxCacheSize          int
	CacheDir              string
}

CacheOptions contains configurations to create a Cache instance.

type GetOptions

type GetOptions struct {
	Checksum        string
	ResourceName    string
	ResourceVersion string
	RequestTimeout  time.Duration
	PullSecret      []byte
	PullPolicy      PullPolicy
}

GetOptions is a struct for providing options to Get method of Cache.

type HTTPFetcher

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

HTTPFetcher fetches remote wasm module with HTTP get.

func NewHTTPFetcher

func NewHTTPFetcher(requestTimeout time.Duration, requestMaxRetry int, logger logging.Logger) *HTTPFetcher

NewHTTPFetcher create a new HTTP remote wasm module fetcher. requestTimeout is a timeout for each HTTP/HTTPS request. requestMaxRetry is # of maximum retries of HTTP/HTTPS requests.

func (*HTTPFetcher) Fetch

func (f *HTTPFetcher) Fetch(ctx context.Context, url string, allowInsecure bool) ([]byte, error)

Fetch downloads a wasm module with HTTP get.

type HTTPServer

type HTTPServer struct {
	SeverOptions
	sync.Mutex
	// contains filtered or unexported fields
}

HTTPServer wraps a local file cache and serves the Wasm modules over HTTP.

func NewHTTPServerWithFileCache

func NewHTTPServerWithFileCache(serverOptions SeverOptions, cacheOptions CacheOptions, logger logging.Logger) *HTTPServer

NewHTTPServerWithFileCache creates a HTTP server with a local file cache for Wasm modules. The local file cache is used to store the Wasm modules downloaded from the original URL. The HTTP server serves the cached Wasm modules over HTTP to the Envoy Proxies.

func (*HTTPServer) Get

func (s *HTTPServer) Get(originalURL string, opts GetOptions) (servingURL string, checksum string, err error)

Get returns the HTTP URL of the Wasm module serving by the EG HTTP Wasm server and the checksum of the Wasm module. EG downloads the Wasm module from its original URL, caches it locally in the file system, and serves it through an HTTP server.

func (*HTTPServer) ServeHTTP

func (s *HTTPServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*HTTPServer) Start

func (s *HTTPServer) Start(ctx context.Context)

type ImageFetcher

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

func NewImageFetcher

func NewImageFetcher(ctx context.Context, opt ImageFetcherOption, logger logging.Logger) *ImageFetcher

func (*ImageFetcher) PrepareFetch

func (o *ImageFetcher) PrepareFetch(url string) (binaryFetcher func() ([]byte, error), actualDigest string, err error)

PrepareFetch is the entrypoint for fetching Wasm binary from Wasm Image Specification compatible images. Wasm binary is not fetched immediately, but returned by `binaryFetcher` function, which is returned by PrepareFetch. By this way, we can have another chance to check cache with `actualDigest` without downloading the OCI image.

type ImageFetcherOption

type ImageFetcherOption struct {
	PullSecret []byte
	Insecure   bool
}

func (*ImageFetcherOption) String

func (o *ImageFetcherOption) String() string

type PullPolicy

type PullPolicy int32
const (
	Unspecified  PullPolicy = 0
	IfNotPresent PullPolicy = 1
	Always       PullPolicy = 2
)

type SeverOptions

type SeverOptions struct {
	// Salt is used as a hash salt to generate an unguessable path for the Wasm module.
	Salt []byte
	// TLSConfig is the TLS configuration for the HTTP server.
	TLSConfig                   *tls.Config
	MaxFailedAttempts           int
	FailedAttemptsResetInterval time.Duration
	FailedAttemptResetDelay     time.Duration
}

Jump to

Keyboard shortcuts

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