cloudruntime

package
v0.60.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package cloudruntime provides primitives for loading data from the cloud runtime.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Configuration

func Configuration() (string, bool)

Configuration returns the service configuration of the current runtime.

func Execution added in v0.45.0

func Execution() (string, bool)

Execution returns the name of the Cloud Run job execution being run.

func Job added in v0.45.0

func Job() (string, bool)

Job returns the name of the Cloud Run job being run.

func Port

func Port() (int, bool)

Port returns the service port of the current runtime.

func ProjectID

func ProjectID() (string, bool)

ProjectID returns the Google Cloud Project ID of the current runtime.

func Revision

func Revision() (string, bool)

Revision returns the service revision of the current runtime.

func Service

func Service() (string, bool)

Service returns the service name of the current runtime.

func ServiceAccount

func ServiceAccount() (string, bool)

ServiceAccount returns the default service account of the current runtime.

func ServiceVersion

func ServiceVersion() (string, bool)

ServiceVersion returns the service version of the current runtime. The service version is taken from, in order of precedence: - the "SERVICE_VERSION" environment variable - the go.einride.tech/cloudrunner/cloudruntime.serviceVersion variable (must be set at build-time) - the "K_REVISION" environment variable - no version.

func ServiceVersionFromBuildInfo added in v0.23.0

func ServiceVersionFromBuildInfo() (string, bool)

ServiceVersionFromBuildInfo returns the VCS revision from the embedded build info.

func ServiceVersionFromLinkerFlags

func ServiceVersionFromLinkerFlags() string

ServiceVersionFromLinkerFlags returns the exact value of the variable:

go.einride.tech/cloudrunner/cloudruntime.serviceVersion

This variable can be set during build-time to provide a default value for the service version.

Example:

go build -ldflags="-X 'go.einride.tech/cloudrunner/cloudruntime.serviceVersion=v1.0.0'"

func TaskAttempt added in v0.45.0

func TaskAttempt() (int, bool)

TaskAttempt returns the number of time this Cloud Run job task tas been retried. Starts at 0 for the first attempt and increments by 1 for every successive retry, up to the maximum retries value.

func TaskCount added in v0.45.0

func TaskCount() (int, bool)

TaskCount returns the number of tasks in the current Cloud Run job.

func TaskIndex added in v0.45.0

func TaskIndex() (int, bool)

TaskIndex returns the index of the Cloud Run job task being run. Starts at 0 for the first task and increments by 1 for every successive task, up to the maximum number of tasks minus 1.

func WithConfig

func WithConfig(ctx context.Context, config Config) context.Context

WithConfig adds the provided runtime Config to the current context.

Types

type Config

type Config struct {
	// Port is the port the service is listening on.
	Port int `env:"PORT" default:"8080"`
	// Service is the name of the service.
	Service string `env:"K_SERVICE"`
	// Revision of the service, as assigned by a Knative runtime.
	Revision string `env:"K_REVISION"`
	// Configuration of the service, as assigned by a Knative runtime.
	Configuration string `env:"K_CONFIGURATION"`
	// Job name, if running as a Cloud Run job.
	Job string `env:"CLOUD_RUN_JOB"`
	// Execution name, if running as a Cloud Run job.
	Execution string `env:"CLOUD_RUN_EXECUTION"`
	// TaskIndex of the current task, if running as a Cloud Run job.
	TaskIndex int `env:"CLOUD_RUN_TASK_INDEX"`
	// TaskAttempt of the current task, if running as a Cloud Run job.
	TaskAttempt int `env:"CLOUD_RUN_TASK_ATTEMPT"`
	// TaskCount of the job, if running as a Cloud Run job.
	TaskCount int `env:"CLOUD_RUN_TASK_COUNT"`
	// ProjectID is the GCP project ID the service is running in.
	// In production, defaults to the project where the service is deployed.
	ProjectID string `env:"GOOGLE_CLOUD_PROJECT"`
	// ServiceAccount is the service account used by the service.
	// In production, defaults to the default service account of the running service.
	ServiceAccount string
	// ServiceVersion is the version of the service.
	ServiceVersion string `env:"SERVICE_VERSION"`
}

Config is the runtime config for the service.

func GetConfig

func GetConfig(ctx context.Context) (Config, bool)

GetConfig gets the runtime Config from the current context.

func (*Config) Autodetect

func (c *Config) Autodetect() error

Autodetect the runtime config.

Jump to

Keyboard shortcuts

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