v1

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BuiltinModulePrefix = "kam."
	ProbePrefix         = "v1.workload.container.probe."
	TypeHTTP            = BuiltinModulePrefix + ProbePrefix + "Http"
	TypeExec            = BuiltinModulePrefix + ProbePrefix + "Exec"
	TypeTCP             = BuiltinModulePrefix + ProbePrefix + "Tcp"
)
View Source
const (
	FieldLabels      = "labels"
	FieldAnnotations = "annotations"
	FieldReplicas    = "replicas"
)
View Source
const (
	ModuleService                 = "service"
	ModuleServiceType             = "type"
	Deployment        ServiceType = "Deployment"
	Collaset          ServiceType = "CollaSet"
)
View Source
const (
	TypeJob     = "kam.v1.workload.Job"
	TypeService = "kam.v1.workload.Service"
)
View Source
const (
	DefaultBackendName = "default"

	BackendCurrent            = "current"
	BackendType               = "type"
	BackendConfigItems        = "configs"
	BackendLocalPath          = "path"
	BackendMysqlDBName        = "dbName"
	BackendMysqlUser          = "user"
	BackendMysqlPassword      = "password"
	BackendMysqlHost          = "host"
	BackendMysqlPort          = "port"
	BackendGenericOssEndpoint = "endpoint"
	BackendGenericOssAK       = "accessKeyID"
	BackendGenericOssSK       = "accessKeySecret"
	BackendGenericOssBucket   = "bucket"
	BackendGenericOssPrefix   = "prefix"
	BackendS3Region           = "region"

	BackendTypeLocal = "local"
	BackendTypeMysql = "mysql"
	BackendTypeOss   = "oss"
	BackendTypeS3    = "s3"

	EnvBackendMysqlPassword = "KUSION_BACKEND_MYSQL_PASSWORD"
	EnvOssAccessKeyID       = "OSS_ACCESS_KEY_ID"
	EnvOssAccessKeySecret   = "OSS_ACCESS_KEY_SECRET"
	EnvAwsAccessKeyID       = "AWS_ACCESS_KEY_ID"
	EnvAwsSecretAccessKey   = "AWS_SECRET_ACCESS_KEY"
	EnvAwsDefaultRegion     = "AWS_DEFAULT_REGION"
	EnvAwsRegion            = "AWS_REGION"

	DefaultMysqlPort = 3306
)
View Source
const ConfigBackends = "backends"
View Source
const ModuleJob = "job"

Variables

This section is empty.

Functions

This section is empty.

Types

type Accessory

type Accessory map[string]interface{}

type AppConfiguration

type AppConfiguration struct {
	// Name of the target App.
	Name string `json:"name,omitempty" yaml:"name,omitempty"`
	// Workload defines how to run your application code.
	Workload *Workload `json:"workload" yaml:"workload"`
	// Accessories defines a collection of accessories that will be attached to the workload.
	// The key in this map represents the module source. e.g. kusionstack/mysql@v0.1
	Accessories map[string]Accessory `json:"accessories,omitempty" yaml:"accessories,omitempty"`
	// Labels and Annotations can be used to attach arbitrary metadata as key-value pairs to resources.
	Labels      map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
	Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"`
}

AppConfiguration is a developer-centric definition that describes how to run an App. The application model is built on a decade of experience from AntGroup in operating a large-scale internal developer platform and combines the best ideas and practices from the community.

Note: AppConfiguration per se is not a Kusion Module

Example: import models.schema.v1 as ac import models.schema.v1.workload as wl import models.schema.v1.workload.container as c import models.schema.v1.workload.container.probe as p import models.schema.v1.monitoring as m import models.schema.v1.database as d

	helloWorld: ac.AppConfiguration {
	   # Built-in module
	   workload: wl.Service {
	       containers: {
	           "main": c.Container {
	               image: "ghcr.io/kusion-stack/samples/helloworld:latest"
	               # Configure a HTTP readiness probe
	               readinessProbe: p.Probe {
	                   probeHandler: p.Http {
	                       url: "http://localhost:80"
	                   }
	               }
	           }
	       }
	   }

	   # extend accessories module base
       accessories: {
           # Built-in module, key represents the module source
           "kusionstack/mysql@v0.1" : d.MySQL {
               type: "cloud"
               version: "8.0"
           }
           # Built-in module, key represents the module source
           "kusionstack/prometheus@v0.1" : m.Prometheus {
               path: "/metrics"
           }
           # Customized module, key represents the module source
           "foo/customize": customizedModule {
               ...
           }
       }

	   # extend pipeline module base
	   pipeline: {
	       # Step is a module
	       "step" : Step {
	           use: "exec"
	           args: ["--test-all"]
	       }
	   }

	   # Dependent app list
	   dependency: {
	       dependentApps: ["init-kusion"]
	   }
	}

type BackendConfig

type BackendConfig struct {
	// Type is the backend type, supports BackendTypeLocal, BackendTypeMysql, BackendTypeOss, BackendTypeS3.
	Type string `yaml:"type,omitempty" json:"type,omitempty"`

	// Configs contains config items of the backend, whose keys differ from different backend types.
	Configs map[string]any `yaml:"configs,omitempty" json:"configs,omitempty"`
}

BackendConfig contains the type and configs of a backend, which is used to store Spec, State and Workspace.

func (*BackendConfig) ToLocalBackend

func (b *BackendConfig) ToLocalBackend() *BackendLocalConfig

ToLocalBackend converts BackendConfig to structured BackendLocalConfig, works only when the Type is BackendTypeLocal, and the Configs are with correct type, or return nil.

func (*BackendConfig) ToMysqlBackend

func (b *BackendConfig) ToMysqlBackend() *BackendMysqlConfig

ToMysqlBackend converts BackendConfig to structured BackendMysqlConfig, works only when the Type is BackendTypeMysql, and the Configs are with correct type, or return nil.

func (*BackendConfig) ToOssBackend

func (b *BackendConfig) ToOssBackend() *BackendOssConfig

ToOssBackend converts BackendConfig to structured BackendOssConfig, works only when the Type is BackendTypeOss, and the Configs are with correct type, or return nil.

func (*BackendConfig) ToS3Backend

func (b *BackendConfig) ToS3Backend() *BackendS3Config

ToS3Backend converts BackendConfig to structured BackendS3Config, works only when the Type is BackendTypeS3, and the Configs are with correct type, or return nil.

type BackendConfigs

type BackendConfigs struct {
	// Current is the name of the current used backend.
	Current string `yaml:"current,omitempty" json:"current,omitempty"`

	// Backends contains the types and configs of multiple backends, whose key is the backend name.
	Backends map[string]*BackendConfig `yaml:",omitempty,inline" json:",omitempty,inline"`
}

BackendConfigs contains the configuration of multiple backends and the current backend.

type BackendLocalConfig

type BackendLocalConfig struct {
	// Path of the directory to store the files.
	Path string `yaml:"path,omitempty" json:"path,omitempty"`
}

BackendLocalConfig contains the config of using local file system as backend, which can be converted from BackendConfig if Type is BackendTypeLocal.

type BackendMysqlConfig

type BackendMysqlConfig struct {
	// DBName is the database name.
	DBName string `yaml:"dbName" json:"dbName"`

	// User of the database.
	User string `yaml:"user" json:"user"`

	// Password of the database.
	Password string `yaml:"password,omitempty" json:"password,omitempty"`

	// Host of the database.
	Host string `yaml:"host" json:"host"`

	// Port of the database. If not set, then it will be set to DeprecatedDefaultMysqlPort.
	Port int `yaml:"port,omitempty" json:"port,omitempty"`
}

BackendMysqlConfig contains the config of using mysql database as backend, which can be converted from BackendConfig if Type is BackendMysqlConfig.

type BackendOssConfig

type BackendOssConfig struct {
	*GenericBackendObjectStorageConfig `yaml:",inline" json:",inline"` // OSS asks for non-empty endpoint
}

BackendOssConfig contains the config of using OSS as backend, which can be converted from BackendConfig if Type is BackendOssConfig.

type BackendS3Config

type BackendS3Config struct {
	*GenericBackendObjectStorageConfig `yaml:",inline" json:",inline"`

	// Region of S3.
	Region string `yaml:"region,omitempty" json:"region,omitempty"`
}

BackendS3Config contains the config of using S3 as backend, which can be converted from BackendConfig if Type is BackendS3Config.

type Base

type Base struct {
	// The templates of containers to be run.
	Containers map[string]Container `yaml:"containers,omitempty" json:"containers,omitempty"`
	// The number of containers that should be run.
	Replicas *int32 `yaml:"replicas,omitempty" json:"replicas,omitempty"`
	// Secret
	Secrets map[string]Secret `json:"secrets,omitempty" yaml:"secrets,omitempty"`
	// Dirs configures one or more volumes to be mounted to the specified folder.
	Dirs map[string]string `json:"dirs,omitempty" yaml:"dirs,omitempty"`
	// Labels and Annotations can be used to attach arbitrary metadata as key-value pairs to resources.
	Labels      map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
	Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"`
}

Base defines set of attributes shared by different workload profile, e.g. Service and Job.

type Config

type Config struct {
	// Backends contains the configurations for multiple backends.
	Backends *BackendConfigs `yaml:"backends,omitempty" json:"backends,omitempty"`
}

Config contains configurations for kusion cli, which stores in ${KUSION_HOME}/config.yaml.

type Container

type Container struct {
	// Image to run for this container
	Image string `yaml:"image" json:"image"`
	// Entrypoint array.
	// The image's ENTRYPOINT is used if this is not provided.
	Command []string `yaml:"command,omitempty" json:"command,omitempty"`
	// Arguments to the entrypoint.
	// The image's CMD is used if this is not provided.
	Args []string `yaml:"args,omitempty" json:"args,omitempty"`
	// Collection of environment variables to set in the container.
	// The value of environment variable may be static text or a value from a secret.
	Env yaml.MapSlice `yaml:"env,omitempty" json:"env,omitempty"`
	// The current working directory of the running process defined in entrypoint.
	WorkingDir string `yaml:"workingDir,omitempty" json:"workingDir,omitempty"`
	// Resource requirements for this container.
	Resources map[string]string `yaml:"resources,omitempty" json:"resources,omitempty"`
	// Files configures one or more files to be created in the container.
	Files map[string]FileSpec `yaml:"files,omitempty" json:"files,omitempty"`
	// Dirs configures one or more volumes to be mounted to the specified folder.
	Dirs map[string]string `yaml:"dirs,omitempty" json:"dirs,omitempty"`
	// Periodic probe of container liveness.
	LivenessProbe *Probe `yaml:"livenessProbe,omitempty" json:"livenessProbe,omitempty"`
	// Periodic probe of container service readiness.
	ReadinessProbe *Probe `yaml:"readinessProbe,omitempty" json:"readinessProbe,omitempty"`
	// StartupProbe indicates that the Pod has successfully initialized.
	StartupProbe *Probe `yaml:"startupProbe,omitempty" json:"startupProbe,omitempty"`
	// Actions that the management system should take in response to container lifecycle events.
	Lifecycle *Lifecycle `yaml:"lifecycle,omitempty" json:"lifecycle,omitempty"`
}

Container describes how the App's tasks are expected to be run.

type ExecAction

type ExecAction struct {
	// Command is the command line to execute inside the container, the working directory for the
	// command  is root ('/') in the container's filesystem.
	// Exit status of 0 is treated as live/healthy and non-zero is unhealthy.
	Command []string `yaml:"command,omitempty" json:"command,omitempty"`
}

ExecAction describes a "run in container" action.

type FileSpec

type FileSpec struct {
	// The content of target file in plain text.
	Content string `yaml:"content,omitempty" json:"content,omitempty"`
	// Source for the file content, might be a reference to a secret value.
	ContentFrom string `yaml:"contentFrom,omitempty" json:"contentFrom,omitempty"`
	// Mode bits used to set permissions on this file.
	Mode string `yaml:"mode" json:"mode"`
}

FileSpec defines the target file in a Container

type GenericBackendObjectStorageConfig

type GenericBackendObjectStorageConfig struct {
	// Endpoint of the object storage service.
	Endpoint string `yaml:"endpoint,omitempty" json:"endpoint,omitempty"`

	// AccessKeyID of the object storage service.
	AccessKeyID string `yaml:"accessKeyID,omitempty" json:"accessKeyID,omitempty"`

	// AccessKeySecret of the object storage service.
	AccessKeySecret string `yaml:"accessKeySecret,omitempty" json:"accessKeySecret,omitempty"`

	// Bucket of the object storage service.
	Bucket string `yaml:"bucket" json:"bucket"`

	// Prefix of the key to store the files.
	Prefix string `yaml:"prefix,omitempty" json:"prefix,omitempty"`
}

GenericBackendObjectStorageConfig contains generic configs which can be reused by BackendOssConfig and BackendS3Config.

type HTTPGetAction

type HTTPGetAction struct {
	// URL is the full qualified url location to send HTTP requests.
	URL string `yaml:"url,omitempty" json:"url,omitempty"`
	// Custom headers to set in the request. HTTP allows repeated headers.
	Headers map[string]string `yaml:"headers,omitempty" json:"headers,omitempty"`
}

HTTPGetAction describes an action based on HTTP Get requests.

type Header struct {
	Type string `yaml:"_type" json:"_type"`
}

type Job

type Job struct {
	Base `yaml:",inline" json:",inline"`
	// The scheduling strategy in Cron format: https://en.wikipedia.org/wiki/Cron.
	Schedule string `yaml:"schedule,omitempty" json:"schedule,omitempty"`
}

Job is a kind of workload profile that describes how to run your application code. This is typically used for tasks that take from a few seconds to a few days to complete.

type Lifecycle

type Lifecycle struct {
	// PreStop is called immediately before a container is terminated due to an
	// API request or management event such as liveness/startup probe failure,
	// preemption, resource contention, etc.
	PreStop *LifecycleHandler `yaml:"preStop,omitempty" json:"preStop,omitempty"`
	// PostStart is called immediately after a container is created.
	PostStart *LifecycleHandler `yaml:"postStart,omitempty" json:"postStart,omitempty"`
}

Lifecycle describes actions that the management system should take in response to container lifecycle events.

type LifecycleHandler

type LifecycleHandler struct {
	// Type of action to be taken.
	TypeWrapper `yaml:"_type" json:"_type"`
	// Exec specifies the action to take.
	// +optional
	*ExecAction `yaml:",inline" json:",inline"`
	// HTTPGet specifies the http request to perform.
	// +optional
	*HTTPGetAction `yaml:",inline" json:",inline"`
}

LifecycleHandler defines a specific action that should be taken in a lifecycle hook. One and only one of the fields, except TCPSocket must be specified.

func (*LifecycleHandler) MarshalJSON

func (l *LifecycleHandler) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for LifecycleHandler.

func (*LifecycleHandler) MarshalYAML

func (l *LifecycleHandler) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface for LifecycleHandler.

func (*LifecycleHandler) UnmarshalJSON

func (l *LifecycleHandler) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for LifecycleHandler.

func (*LifecycleHandler) UnmarshalYAML

func (l *LifecycleHandler) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface for LifecycleHandler.

type Patcher

type Patcher struct {
	// Environments represent the environment variables patched to all containers in the workload.
	Environments []v1.EnvVar `json:"environments" yaml:"environments"`
	// Labels represent the labels patched to both the workload and pod.
	Labels map[string]string `json:"labels" yaml:"labels"`
	// Annotations represent the annotations patched to both the workload and pod.
	Annotations map[string]string `json:"annotations" yaml:"annotations"`
}

Patcher contains fields should be patched into the workload corresponding fields

type Port

type Port struct {
	// Port is the exposed port of the Service.
	Port int `yaml:"port,omitempty" json:"port,omitempty"`
	// TargetPort is the backend .Container port.
	TargetPort int `yaml:"targetPort,omitempty" json:"targetPort,omitempty"`
	// Protocol is protocol used to expose the port, support ProtocolTCP and ProtocolUDP.
	Protocol Protocol `yaml:"protocol,omitempty" json:"protocol,omitempty"`
}

Port defines the exposed port of Service.

type Probe

type Probe struct {
	// The action taken to determine the health of a container.
	ProbeHandler *ProbeHandler `yaml:"probeHandler" json:"probeHandler"`
	// Number of seconds after the container has started before liveness probes are initiated.
	InitialDelaySeconds int32 `yaml:"initialDelaySeconds,omitempty" json:"initialDelaySeconds,omitempty"`
	// Number of seconds after which the probe times out.
	TimeoutSeconds int32 `yaml:"timeoutSeconds,omitempty" json:"timeoutSeconds,omitempty"`
	// How often (in seconds) to perform the probe.
	PeriodSeconds int32 `yaml:"periodSeconds,omitempty" json:"periodSeconds,omitempty"`
	// Minimum consecutive successes for the probe to be considered successful after having failed.
	SuccessThreshold int32 `yaml:"successThreshold,omitempty" json:"successThreshold,omitempty"`
	// Minimum consecutive failures for the probe to be considered failed after having succeeded.
	FailureThreshold int32 `yaml:"failureThreshold,omitempty" json:"failureThreshold,omitempty"`
}

Probe describes a health check to be performed against a container to determine whether it is alive or ready to receive traffic.

type ProbeHandler

type ProbeHandler struct {
	// Type of action to be taken.
	TypeWrapper `yaml:"_type" json:"_type"`
	// Exec specifies the action to take.
	// +optional
	*ExecAction `yaml:",inline" json:",inline"`
	// HTTPGet specifies the http request to perform.
	// +optional
	*HTTPGetAction `yaml:",inline" json:",inline"`
	// TCPSocket specifies an action involving a TCP port.
	// +optional
	*TCPSocketAction `yaml:",inline" json:",inline"`
}

ProbeHandler defines a specific action that should be taken in a probe. One and only one of the fields must be specified.

func (*ProbeHandler) MarshalJSON

func (p *ProbeHandler) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for ProbeHandler.

func (*ProbeHandler) MarshalYAML

func (p *ProbeHandler) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface for ProbeHandler.

func (*ProbeHandler) UnmarshalJSON

func (p *ProbeHandler) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for ProbeHandler.

func (*ProbeHandler) UnmarshalYAML

func (p *ProbeHandler) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface for ProbeHandler.

type Protocol

type Protocol string
const (
	TCP Protocol = "TCP"
	UDP Protocol = "UDP"
)

type Secret

type Secret struct {
	Type      string            `yaml:"type" json:"type"`
	Params    map[string]string `yaml:"params,omitempty" json:"params,omitempty"`
	Data      map[string]string `yaml:"data,omitempty" json:"data,omitempty"`
	Immutable bool              `yaml:"immutable,omitempty" json:"immutable,omitempty"`
}

type Service

type Service struct {
	Base `yaml:",inline" json:",inline"`
	// Type represents the type of workload.Service, support Deployment and CollaSet.
	Type ServiceType `yaml:"type" json:"type"`
	// Ports describe the list of ports need getting exposed.
	Ports []Port `yaml:"ports,omitempty" json:"ports,omitempty"`
}

Service is a kind of workload profile that describes how to run your application code. This is typically used for long-running web applications that should "never" go down, and handle short-lived latency-sensitive web requests, or events.

type ServiceType

type ServiceType string

type TCPSocketAction

type TCPSocketAction struct {
	// URL is the full qualified url location to open a socket.
	URL string `yaml:"url,omitempty" json:"url,omitempty"`
}

TCPSocketAction describes an action based on opening a socket.

type Type

type Type string

type TypeWrapper

type TypeWrapper struct {
	// Type of action to be taken.
	Type string `yaml:"_type" json:"_type"`
}

TypeWrapper is a thin wrapper to make YAML decoder happy.

type Workload

type Workload struct {
	Header   `yaml:",inline" json:",inline"`
	*Service `yaml:",inline" json:",inline"`
	*Job     `yaml:",inline" json:",inline"`
}

func (*Workload) MarshalJSON

func (w *Workload) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for Workload.

func (*Workload) MarshalYAML

func (w *Workload) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface for Workload.

func (*Workload) UnmarshalJSON

func (w *Workload) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for Workload.

func (*Workload) UnmarshalYAML

func (w *Workload) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface for Workload.

Jump to

Keyboard shortcuts

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