core

package
v0.16.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultELBPlans = ResourcePlans{
	&ELBPlan{CPS: 100},
	&ELBPlan{CPS: 500},
	&ELBPlan{CPS: 1_000},
	&ELBPlan{CPS: 5_000},
	&ELBPlan{CPS: 10_000},
	&ELBPlan{CPS: 50_000},
	&ELBPlan{CPS: 100_000},
	&ELBPlan{CPS: 400_000},
}

DefaultELBPlans 各リソースで定義しなかった場合に利用されるデフォルトのプラン一覧

View Source
var DefaultRouterPlans = ResourcePlans{
	&RouterPlan{BandWidth: 100},
	&RouterPlan{BandWidth: 250},
	&RouterPlan{BandWidth: 500},
	&RouterPlan{BandWidth: 1000},
	&RouterPlan{BandWidth: 1500},
	&RouterPlan{BandWidth: 2000},
	&RouterPlan{BandWidth: 2500},
	&RouterPlan{BandWidth: 3000},
	&RouterPlan{BandWidth: 3500},
	&RouterPlan{BandWidth: 4000},
	&RouterPlan{BandWidth: 4500},
	&RouterPlan{BandWidth: 5000},
}

DefaultRouterPlans 各リソースで定義しなかった場合に利用されるデフォルトのプラン一覧

東京第2ゾーンでのみ利用可能なプランは定義されていないため、利用したい場合は各リソース定義内で個別に定義する

View Source
var DefaultServerPlans = ResourcePlans{
	&ServerPlan{Core: 2, Memory: 4},
	&ServerPlan{Core: 4, Memory: 8},
	&ServerPlan{Core: 4, Memory: 16},
	&ServerPlan{Core: 8, Memory: 16},
	&ServerPlan{Core: 10, Memory: 24},
	&ServerPlan{Core: 10, Memory: 32},
	&ServerPlan{Core: 10, Memory: 48},
}

DefaultServerPlans 各リソースで定義しなかった場合に利用されるデフォルトのプラン一覧

Functions

func ResourcesTree added in v0.0.2

func ResourcesTree(parentCtx context.Context, addr, configPath string, strictMode bool, logger *slog.Logger) (string, error)

Types

type AutoScalerConfig

type AutoScalerConfig struct {
	CoolDown               *CoolDown              `yaml:"cooldown"`              // 同一ジョブの連続実行を防ぐための冷却期間(単位:秒)
	ShutdownGracePeriodSec int                    `yaml:"shutdown_grace_period"` // SIGINTまたはSIGTERMをを受け取った際の処理完了待ち猶予時間(単位:秒)
	ExporterConfig         *config.ExporterConfig `yaml:"exporter_config"`       // Exporter設定
	HandlersConfig         *HandlersConfig        `yaml:"handlers_config"`       // ビルトインハンドラーの設定
}

AutoScalerConfig オートスケーラー自体の動作設定

func (*AutoScalerConfig) ExporterEnabled added in v0.1.0

func (c *AutoScalerConfig) ExporterEnabled() bool

func (*AutoScalerConfig) ShutdownGracePeriod added in v0.7.3

func (c *AutoScalerConfig) ShutdownGracePeriod() time.Duration

func (*AutoScalerConfig) Validate added in v0.1.0

func (c *AutoScalerConfig) Validate(ctx context.Context) []error

type ChildResource

type ChildResource interface {
	Parent() Resource
}

ChildResource 親Resourceを持つResourceを示すインターフェース

type Computed

type Computed interface {
	// Type このComputedが表すさくらのクラウド上のリソースの種別
	Type() ResourceTypes
	// ID このComputedが表すさくらのクラウド上のリソースのID、まだ存在しないリソースの場合は空文字を返す
	ID() string
	// Name このComputedが表すさくらのクラウド上のリソースのName、ログ出力用
	Name() string
	// Zone このComputedが表すさくらのクラウド上のリソースが属するゾーン名、グローバルリソースの場合は空文字を返す
	Zone() string

	// Instruction 現在のリソースの状態から算出されたハンドラーへの指示の種類
	Instruction() handler.ResourceInstructions
	// SetupGracePeriod セットアップのための猶予時間(秒数)
	//
	// Handleされた後、セットアップの完了を待つためにこの秒数分待つ
	SetupGracePeriod() int

	// Current ハンドラーに渡すパラメータ、現在の状態を示す 現在存在しないリソースの場合はnilを返す
	Current() *handler.Resource
	// Desired ハンドラーに渡すパラメータ、InstructionがNOOPやDELETEの場合はnilを返す
	Desired() *handler.Resource
}

Computed 各リソースが算出した希望する状態(Desired State)を示すインターフェース

1つのComputedに対し1つのさくらのクラウド上のリソースが対応する

type Config

type Config struct {
	SakuraCloud    *SakuraCloud        `yaml:"sakuracloud"`                   // さくらのクラウドAPIのクレデンシャル
	CustomHandlers Handlers            `yaml:"handlers"`                      // カスタムハンドラーの定義
	Resources      ResourceDefinitions `yaml:"resources" validate:"required"` // リソースの定義
	AutoScaler     AutoScalerConfig    `yaml:"autoscaler"`                    // オートスケーラー自体の動作設定
	// contains filtered or unexported fields
}

Config Coreの起動時に与えられるコンフィギュレーションを保持する

func LoadAndValidate added in v0.0.2

func LoadAndValidate(ctx context.Context, configPath string, strictMode bool, logger *slog.Logger) (*Config, error)

LoadAndValidate 指定のファイルパスからコンフィグを読み込み、バリデーションを行う

func NewConfigFromPath

func NewConfigFromPath(ctx context.Context, filePath string, strictMode bool, logger *slog.Logger) (*Config, error)

NewConfigFromPath 指定のファイルパスからコンフィギュレーションを読み取ってConfigを作成する

func (*Config) APIClient

func (c *Config) APIClient() iaas.APICaller

APIClient Configに保持しているCredentialからさくらのクラウドAPIクライアント(iaas.APICaller)を返す

シングルトンなインスタンスを返す

func (*Config) Handlers

func (c *Config) Handlers() Handlers

Handlers ビルトインハンドラ+カスタムハンドラのリストを返す

ビルトインハンドラはAPIクライアントが注入された状態で返される

func (*Config) Validate

func (c *Config) Validate(ctx context.Context) error

Validate 現在のConfig値のバリデーション

func (*Config) ValidateCustomHandler added in v0.2.0

func (c *Config) ValidateCustomHandler(ctx context.Context, handler *Handler) error

func (*Config) ValidateCustomHandlers added in v0.2.0

func (c *Config) ValidateCustomHandlers(ctx context.Context) []error

type CoolDown added in v0.13.0

type CoolDown struct {
	Up   int `yaml:"up"`
	Down int `yaml:"down"`
}

CoolDown スケール動作を繰り返し実行する際の冷却期間

func (*CoolDown) Duration added in v0.13.0

func (c *CoolDown) Duration(requestType RequestTypes) time.Duration

func (*CoolDown) UnmarshalYAML added in v0.13.0

func (c *CoolDown) UnmarshalYAML(ctx context.Context, data []byte) error

type Core

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

Core AutoScaler Coreのインスタンス

func New added in v0.7.3

func New(ctx context.Context, addr, configPath string, strictMode bool, logger *slog.Logger) (*Core, error)

New 指定のファイルパスからコンフィグを読み込み、Coreのインスタンスを生成して返すgRPCサーバとしてリッスンを開始する

func (*Core) Down

func (c *Core) Down(ctx *RequestContext) (*JobStatus, string, error)

func (*Core) ResourceName added in v0.1.0

func (c *Core) ResourceName(name string) (string, error)

func (*Core) Run added in v0.7.3

func (c *Core) Run(ctx context.Context) error

func (*Core) Stop added in v0.7.3

func (c *Core) Stop() error

Stop リクエストの新規受付を停止しつつ現在処理中のUp/Downがあれば終わるまでブロックする

func (*Core) Up

func (c *Core) Up(ctx *RequestContext) (*JobStatus, string, error)

type Credential

type Credential struct {
	Token  string `yaml:"token"`
	Secret string `yaml:"secret"`
}

Credential さくらのクラウドAPI トークン/シークレット

type ELBPlan

type ELBPlan struct {
	Name string `yaml:"name"`
	CPS  int    `yaml:"cps"`
}

func (*ELBPlan) Equals

func (p *ELBPlan) Equals(resource interface{}) bool

func (*ELBPlan) LessThan

func (p *ELBPlan) LessThan(resource interface{}) bool

func (*ELBPlan) LessThanPlan

func (p *ELBPlan) LessThanPlan(plan ResourcePlan) bool

func (*ELBPlan) PlanName

func (p *ELBPlan) PlanName() string

type Graph added in v0.0.2

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

func NewGraph added in v0.0.2

func NewGraph(resources ResourceDefinitions) *Graph

func (*Graph) Children added in v0.0.2

func (g *Graph) Children() []tree.Node

func (*Graph) Data added in v0.0.2

func (g *Graph) Data() interface{}

func (*Graph) Tree added in v0.0.2

func (g *Graph) Tree(ctx *RequestContext, apiClient iaas.APICaller) (string, error)

type GraphNode added in v0.0.2

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

func (*GraphNode) Children added in v0.0.2

func (n *GraphNode) Children() []tree.Node

func (*GraphNode) Data added in v0.0.2

func (n *GraphNode) Data() interface{}

type Handler

type Handler struct {
	Name           string               `yaml:"name"`     // ハンドラーを識別するための名称
	Endpoint       string               `yaml:"endpoint"` // カスタムハンドラーの場合にのみ指定
	BuiltinHandler handlers.HandlerMeta `yaml:"-"`        // ビルトインハンドラーの場合のみ指定
	Disabled       bool                 `yaml:"-"`        // ビルトインハンドラーの場合のみ指定
}

Handler カスタムハンドラーの定義

func (*Handler) Handle

func (h *Handler) Handle(ctx *HandlingContext, computed Computed) error

func (*Handler) PostHandle

func (h *Handler) PostHandle(ctx *HandlingContext, computed Computed) error

func (*Handler) PreHandle

func (h *Handler) PreHandle(ctx *HandlingContext, computed Computed) error

type HandlerConfig added in v0.2.0

type HandlerConfig struct {
	Disabled bool `yaml:"disabled"`
}

HandlerConfig ビルトインハンドラの設定

type Handlers

type Handlers []*Handler

Handlers Handlerのリスト

func BuiltinHandlers

func BuiltinHandlers() Handlers

BuiltinHandlers ビルトインハンドラのリスト

この段階では各ハンドラにAPIクライアントは注入されない Config.Handlersも参照

type HandlersConfig added in v0.2.0

type HandlersConfig struct {
	Disabled bool                      `yaml:"disabled"` // trueの場合ビルトインハンドラ全体を無効にする
	Handlers map[string]*HandlerConfig `yaml:"handlers"` // ハンドラごとの設定、ハンドラ名をキーにもつ
}

HandlersConfig ビルトインハンドラ全体の設定

func (*HandlersConfig) Validate added in v0.2.0

func (c *HandlersConfig) Validate(context.Context) []error

type HandlingContext

type HandlingContext struct {
	*RequestContext
	// contains filtered or unexported fields
}

HandlingContext 1リクエスト中の1リソースに対するハンドリングのスコープに対応するコンテキスト

context.Contextを実装し、core.Contextに加えて現在処理中のComputedを保持する

func NewHandlingContext

func NewHandlingContext(parent *RequestContext, computed Computed) *HandlingContext

func (*HandlingContext) ComputeResult

ComputeResult コンテキストに保持しているComputedと渡されたComputedを比較しHandleの結果を算出する

func (*HandlingContext) CurrentComputed

func (c *HandlingContext) CurrentComputed() Computed

CurrentComputed 現在処理中の[]Computedを返す

func (*HandlingContext) WithContext added in v0.16.0

func (c *HandlingContext) WithContext(parent context.Context) *HandlingContext

func (*HandlingContext) WithLogger

func (c *HandlingContext) WithLogger(keyvals ...interface{}) *HandlingContext

type IdOrNameOrSelector added in v0.9.0

type IdOrNameOrSelector struct {
	ResourceSelector
}

IdOrNameOrSelector ID、名前、またはResourceSelectorを表すstruct

func (*IdOrNameOrSelector) UnmarshalYAML added in v0.9.0

func (v *IdOrNameOrSelector) UnmarshalYAML(ctx context.Context, data []byte) error

type JobStatus

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

JobStatus スケールアウト/イン/アップ/ダウンなどの各種ジョブを表す

Inputsからのリクエストパラメータ ResourceNameごとに作成される

func NewJobStatus

func NewJobStatus(req *requestInfo, coolDown *CoolDown) *JobStatus

func (*JobStatus) Acceptable

func (j *JobStatus) Acceptable(requestType RequestTypes, lastModifiedAt time.Time) bool

Acceptable このジョブが新規に受け入れ可能(新たに起動できる)状態の場合true

func (*JobStatus) ID

func (j *JobStatus) ID() string

func (*JobStatus) SetStatus

func (j *JobStatus) SetStatus(status request.ScalingJobStatus)

func (*JobStatus) Status

func (j *JobStatus) Status() request.ScalingJobStatus

func (*JobStatus) String

func (j *JobStatus) String() string

type MultiZoneSelector added in v0.1.0

type MultiZoneSelector struct {
	*ResourceSelector `yaml:",inline" validate:"required"`
	Zones             []string `yaml:"zones" validate:"required,zones"`
}

func (*MultiZoneSelector) String added in v0.1.0

func (rs *MultiZoneSelector) String() string

func (*MultiZoneSelector) Validate added in v0.1.0

func (rs *MultiZoneSelector) Validate() error

type NameOrSelector added in v0.1.0

type NameOrSelector struct {
	ResourceSelector
}

NameOrSelector 名前(文字列)、もしくはResourceSelectorを表すstruct

func (*NameOrSelector) UnmarshalYAML added in v0.1.0

func (v *NameOrSelector) UnmarshalYAML(ctx context.Context, data []byte) error

type ParentResource added in v0.5.0

type ParentResource struct {
	*ResourceBase
	// contains filtered or unexported fields
}

func NewParentResource added in v0.5.0

func NewParentResource(ctx *RequestContext, apiClient iaas.APICaller, def *ParentResourceDef, resource SakuraCloudResource, zone string) (*ParentResource, error)

func (*ParentResource) Compute added in v0.5.0

func (r *ParentResource) Compute(ctx *RequestContext, refresh bool) (Computed, error)

func (*ParentResource) String added in v0.5.0

func (r *ParentResource) String() string

type ParentResourceDef added in v0.5.0

type ParentResourceDef struct {
	TypeName string          `yaml:"type" validate:"required,oneof=DNS EnhancedLoadBalancer ELB GSLB LoadBalancer"`
	Selector *NameOrSelector `yaml:"selector" validate:"required"`
}

ParentResourceDef サーバやサーバグループの親リソースを示すResourceDefinition実装

func (*ParentResourceDef) Compute added in v0.5.0

func (d *ParentResourceDef) Compute(ctx *RequestContext, apiClient iaas.APICaller) (Resources, error)

func (*ParentResourceDef) LastModifiedAt added in v0.14.0

func (d *ParentResourceDef) LastModifiedAt(ctx *RequestContext, apiClient iaas.APICaller) (time.Time, error)

LastModifiedAt この定義が対象とするリソース(群)の最終更新日時を返す

func (*ParentResourceDef) String added in v0.5.0

func (d *ParentResourceDef) String() string

func (*ParentResourceDef) Type added in v0.5.0

func (d *ParentResourceDef) Type() ResourceTypes

func (*ParentResourceDef) UnmarshalYAML added in v0.5.0

func (d *ParentResourceDef) UnmarshalYAML(ctx context.Context, data []byte) error

func (*ParentResourceDef) Validate added in v0.5.0

func (d *ParentResourceDef) Validate(ctx context.Context, apiClient iaas.APICaller, zone string) []error

type RequestContext

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

RequestContext 1リクエストのスコープに対応するコンテキスト、context.Contextを実装し、リクエスト情報や現在のジョブの情報を保持する

func NewRequestContext

func NewRequestContext(parent context.Context, request *requestInfo, logger *slog.Logger) *RequestContext

NewRequestContext 新しいリクエストコンテキストを生成する

func (*RequestContext) Deadline

func (c *RequestContext) Deadline() (deadline time.Time, ok bool)

Deadline context.Contextの実装、内部で保持しているcontextに処理を委譲している

func (*RequestContext) Done

func (c *RequestContext) Done() <-chan struct{}

Done context.Contextの実装、内部で保持しているcontextに処理を委譲している

func (*RequestContext) Err

func (c *RequestContext) Err() error

Err context.Contextの実装、内部で保持しているcontextに処理を委譲している

func (*RequestContext) Job

func (c *RequestContext) Job() *JobStatus

Job 現在のコンテキストで実行中のJobを返す

まだJobの実行決定が行われていない場合はnilを返す

func (*RequestContext) JobID

func (c *RequestContext) JobID() string

JobID 現在のコンテキストでのJobのIDを返す

まだJobの実行決定が行われていない場合でも値を返す

func (*RequestContext) Logger

func (c *RequestContext) Logger() *slog.Logger

Logger 現在のコンテキストのロガーを返す

func (*RequestContext) Request

func (c *RequestContext) Request() *requestInfo

Request 現在のコンテキストで受けたリクエストの情報を返す

func (*RequestContext) Value

func (c *RequestContext) Value(key interface{}) interface{}

Value context.Contextの実装、内部で保持しているcontextに処理を委譲している

func (*RequestContext) WithContext added in v0.16.0

func (c *RequestContext) WithContext(parent context.Context) *RequestContext

func (*RequestContext) WithJobStatus

func (c *RequestContext) WithJobStatus(job *JobStatus) *RequestContext

WithJobStatus JobStatusを持つContextを現在のContextを元に作成して返す

現在のContextが親Contextとなる

func (*RequestContext) WithZone added in v0.5.0

func (c *RequestContext) WithZone(zone string) *RequestContext

WithZone Zoneを保持するContextを現在のContextを元に作成して返す

現在のContextが親Contextとなる

type RequestTypes

type RequestTypes int

func (RequestTypes) String

func (r RequestTypes) String() string

type Resource

type Resource interface {
	// Compute リクエストに沿った、希望する状態を算出する
	//
	// refreshがtrueの場合、さくらのクラウドAPIを用いて最新の状態を取得した上で処理を行う
	// falseの場合はキャッシュされている結果を元に処理を行う
	Compute(ctx *RequestContext, refresh bool) (Computed, error)

	// Type リソースの型
	Type() ResourceTypes

	// String Resourceの文字列表現
	String() string
}

Resource Definitionから作られるResource

type ResourceBase

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

ResourceBase 全てのリソースが所有すべきResourceの基本構造

func (*ResourceBase) Type

func (r *ResourceBase) Type() ResourceTypes

type ResourceDefBase added in v0.0.2

type ResourceDefBase struct {
	TypeName string `yaml:"type" validate:"required,oneof=EnhancedLoadBalancer ELB Router Server ServerGroup"`
	DefName  string `yaml:"name"`

	// セットアップのための猶予時間(秒数)
	// Handleされた後、セットアップの完了を待つためにこの秒数分待つ
	// 0の場合はTypeごとに定められたデフォルト値が用いられる。
	// デフォルト値:
	//    - Server: 60
	//    - 上記以外: 0
	SetupGracePeriodSec int `yaml:"setup_grace_period" validate:"omitempty,min=0,max=600"`
}

ResourceDefBase 全てのリソース定義が実装すべき基本プロパティ

Resourceの実装に埋め込む場合、Compute()でComputedCacheを設定すること

func (*ResourceDefBase) Name added in v0.1.0

func (r *ResourceDefBase) Name() string

func (*ResourceDefBase) SetupGracePeriod added in v0.6.0

func (r *ResourceDefBase) SetupGracePeriod() int

func (*ResourceDefBase) Type added in v0.0.2

func (r *ResourceDefBase) Type() ResourceTypes

type ResourceDefELB added in v0.0.2

type ResourceDefELB struct {
	*ResourceDefBase `yaml:",inline" validate:"required"`
	Selector         *ResourceSelector `yaml:"selector" validate:"required"`
	Plans            []*ELBPlan        `yaml:"plans"`
}

func (*ResourceDefELB) Compute added in v0.0.2

func (d *ResourceDefELB) Compute(ctx *RequestContext, apiClient iaas.APICaller) (Resources, error)

func (*ResourceDefELB) LastModifiedAt added in v0.14.0

func (d *ResourceDefELB) LastModifiedAt(ctx *RequestContext, apiClient iaas.APICaller) (time.Time, error)

LastModifiedAt この定義が対象とするリソース(群)の最終更新日時を返す

func (*ResourceDefELB) String added in v0.1.0

func (d *ResourceDefELB) String() string

func (*ResourceDefELB) Validate added in v0.0.2

func (d *ResourceDefELB) Validate(ctx context.Context, apiClient iaas.APICaller) []error

type ResourceDefRouter added in v0.0.2

type ResourceDefRouter struct {
	*ResourceDefBase `yaml:",inline" validate:"required"`
	Selector         *MultiZoneSelector `yaml:"selector" validate:"required"`

	Plans []*RouterPlan `yaml:"plans"`
}

func (*ResourceDefRouter) Compute added in v0.0.2

func (d *ResourceDefRouter) Compute(ctx *RequestContext, apiClient iaas.APICaller) (Resources, error)

func (*ResourceDefRouter) LastModifiedAt added in v0.14.0

func (d *ResourceDefRouter) LastModifiedAt(ctx *RequestContext, apiClient iaas.APICaller) (time.Time, error)

LastModifiedAt この定義が対象とするリソース(群)の最終更新日時を返す

func (*ResourceDefRouter) String added in v0.1.0

func (d *ResourceDefRouter) String() string

func (*ResourceDefRouter) Validate added in v0.0.2

func (d *ResourceDefRouter) Validate(ctx context.Context, apiClient iaas.APICaller) []error

type ResourceDefServer added in v0.0.2

type ResourceDefServer struct {
	*ResourceDefBase `yaml:",inline" validate:"required"`
	Selector         *MultiZoneSelector `yaml:"selector" validate:"required"`

	GPU           int           `yaml:"gpu"`
	CPUModel      string        `yaml:"cpu_model"`
	DedicatedCPU  bool          `yaml:"dedicated_cpu"`
	Plans         []*ServerPlan `yaml:"plans"`
	ShutdownForce bool          `yaml:"shutdown_force"`

	ParentDef *ParentResourceDef `yaml:"parent"`
}

func (*ResourceDefServer) Compute added in v0.0.2

func (d *ResourceDefServer) Compute(ctx *RequestContext, apiClient iaas.APICaller) (Resources, error)

func (*ResourceDefServer) LastModifiedAt added in v0.14.0

func (d *ResourceDefServer) LastModifiedAt(ctx *RequestContext, apiClient iaas.APICaller) (time.Time, error)

LastModifiedAt この定義が対象とするリソース(群)の最終更新日時を返す

ServerではModifiedAt or Instance.StatusChangedAtの最も遅い時刻を返す

func (*ResourceDefServer) String added in v0.1.0

func (d *ResourceDefServer) String() string

func (*ResourceDefServer) Validate added in v0.0.2

func (d *ResourceDefServer) Validate(ctx context.Context, apiClient iaas.APICaller) []error

type ResourceDefServerGroup added in v0.1.0

type ResourceDefServerGroup struct {
	*ResourceDefBase `yaml:",inline" validate:"required"`

	ServerNamePrefix string `yaml:"server_name_prefix"` // NameまたはServerNamePrefixが必須
	ServerNameFormat string `yaml:"server_name_format"`

	Zone  string   `yaml:"zone" validate:"required_without=Zones,omitempty,zone"`
	Zones []string `yaml:"zones" validate:"required_without=Zone,omitempty,unique,dive,required,zone"`

	MinSize int `yaml:"min_size" validate:"min=0,ltefield=MaxSize"`
	MaxSize int `yaml:"max_size" validate:"min=0,gtecsfield=MinSize"`

	Plans []*ServerGroupPlan `yaml:"plans"`

	Template      *ServerGroupInstanceTemplate `yaml:"template" validate:"required"`
	ShutdownForce bool                         `yaml:"shutdown_force"`

	ParentDef *ParentResourceDef `yaml:"parent"`
}

func (*ResourceDefServerGroup) Compute added in v0.1.0

func (d *ResourceDefServerGroup) Compute(ctx *RequestContext, apiClient iaas.APICaller) (Resources, error)

func (*ResourceDefServerGroup) LastModifiedAt added in v0.14.0

func (d *ResourceDefServerGroup) LastModifiedAt(ctx *RequestContext, apiClient iaas.APICaller) (time.Time, error)

LastModifiedAt この定義が対象とするリソース(群)の最終更新日時を返す

ServerGroupではModifiedAt or Instance.StatusChangedAtの最も遅い時刻を返す

func (*ResourceDefServerGroup) String added in v0.1.0

func (d *ResourceDefServerGroup) String() string

func (*ResourceDefServerGroup) Validate added in v0.1.0

func (d *ResourceDefServerGroup) Validate(ctx context.Context, apiClient iaas.APICaller) []error

type ResourceDefinition added in v0.0.2

type ResourceDefinition interface {
	Type() ResourceTypes // リソースの型
	Name() string
	String() string
	Validate(ctx context.Context, apiClient iaas.APICaller) []error

	// Compute 現在/あるべき姿を算出する
	//
	// TypeとSelectorを元にさくらのクラウドAPIを用いて実リソースを検索、Resourceを作成して返す
	Compute(ctx *RequestContext, apiClient iaas.APICaller) (Resources, error)

	// LastModifiedAt この定義が対象とするリソース(群)の最終更新を返す
	LastModifiedAt(ctx *RequestContext, apiClient iaas.APICaller) (time.Time, error)
}

ResourceDefinition Coreが扱うさくらのクラウド上のリソースを表す

Core起動時のコンフィギュレーションから形成される

type ResourceDefinitions added in v0.0.2

type ResourceDefinitions []ResourceDefinition

ResourceDefinitions リソースのリスト

func (*ResourceDefinitions) FilterByResourceName added in v0.1.0

func (rds *ResourceDefinitions) FilterByResourceName(name string) ResourceDefinitions

func (*ResourceDefinitions) HandleAll added in v0.0.2

func (rds *ResourceDefinitions) HandleAll(ctx *RequestContext, apiClient iaas.APICaller, handlers Handlers, cleanup func())

func (*ResourceDefinitions) LastModifiedAt added in v0.14.0

func (rds *ResourceDefinitions) LastModifiedAt(ctx *RequestContext, apiClient iaas.APICaller) (time.Time, error)

LastModifiedAt 内包する定義群が対象とするリソース(群)の更新日時のうち、最も新しい(時間が遅い)値を返す

func (*ResourceDefinitions) ResourceNames added in v0.2.0

func (rds *ResourceDefinitions) ResourceNames() []string

func (*ResourceDefinitions) UnmarshalYAML added in v0.1.0

func (rds *ResourceDefinitions) UnmarshalYAML(ctx context.Context, data []byte) error

func (*ResourceDefinitions) Validate added in v0.0.2

func (rds *ResourceDefinitions) Validate(ctx context.Context, apiClient iaas.APICaller) []error

type ResourceELB added in v0.0.2

type ResourceELB struct {
	*ResourceBase
	// contains filtered or unexported fields
}

func NewResourceELB added in v0.0.2

func NewResourceELB(ctx *RequestContext, apiClient iaas.APICaller, def *ResourceDefELB, elb *iaas.ProxyLB) (*ResourceELB, error)

func (*ResourceELB) Compute added in v0.0.2

func (r *ResourceELB) Compute(ctx *RequestContext, refresh bool) (Computed, error)

func (*ResourceELB) String added in v0.0.2

func (r *ResourceELB) String() string

type ResourcePlan

type ResourcePlan interface {
	// PlanName プラン名、Configurationで任意のプランに任意の名前をつけるために利用する
	PlanName() string
	// Equals 指定のリソースが該当プランと同じ値を持っているか判定する
	Equals(resource interface{}) bool
	// LessThan 指定のリソースが該当プランより小さい値であるかを判定する(境界は含めない)
	LessThan(resource interface{}) bool
	// LessThanPlan 指定のプランが該当プランより小さい値であるかを判定する(境界は含めない)
	LessThanPlan(plans ResourcePlan) bool
}

ResourcePlan オートスケールをサポートするリソースでのプランを表すインターフェース

type ResourcePlans

type ResourcePlans []ResourcePlan

ResourcePlans オートスケールをサポートするリソースでのプラン一覧を表すインターフェース

func (*ResourcePlans) Next

func (p *ResourcePlans) Next(resource interface{}) ResourcePlan

Next スケールアップ後のプランを取得する

該当プランが存在しない場合はnilを返す

func (*ResourcePlans) Prev

func (p *ResourcePlans) Prev(resource interface{}) ResourcePlan

Prev スケールダウン後のプランを取得する

該当プランが存在しない場合はnilを返す

func (*ResourcePlans) Sort

func (p *ResourcePlans) Sort()

Sort ResourcePlan.LessThanPlanを用いて昇順にソートする

type ResourceRouter added in v0.0.2

type ResourceRouter struct {
	*ResourceBase
	// contains filtered or unexported fields
}

func NewResourceRouter added in v0.0.2

func NewResourceRouter(ctx *RequestContext, apiClient iaas.APICaller, def *ResourceDefRouter, zone string, router *iaas.Internet) (*ResourceRouter, error)

func (*ResourceRouter) Compute added in v0.0.2

func (r *ResourceRouter) Compute(ctx *RequestContext, refresh bool) (Computed, error)

func (*ResourceRouter) String added in v0.0.2

func (r *ResourceRouter) String() string

type ResourceSelector

type ResourceSelector struct {
	ID    types.ID `yaml:"id" validate:"required_without_all=Tags Names"`
	Tags  []string `yaml:"tags" validate:"required_without_all=ID Names"`
	Names []string `yaml:"names" validate:"required_without_all=ID Tags"`
}

ResourceSelector さくらのクラウド上で対象リソースを特定するための情報を提供する

func (*ResourceSelector) String

func (rs *ResourceSelector) String() string

func (*ResourceSelector) Validate added in v0.0.2

func (rs *ResourceSelector) Validate() error

type ResourceServer added in v0.0.2

type ResourceServer struct {
	*ResourceBase
	// contains filtered or unexported fields
}

func NewResourceServer added in v0.0.2

func NewResourceServer(ctx *RequestContext, apiClient iaas.APICaller, def *ResourceDefServer, parent Resource, zone string, server *iaas.Server) (*ResourceServer, error)

func (*ResourceServer) Compute added in v0.0.2

func (r *ResourceServer) Compute(ctx *RequestContext, refresh bool) (Computed, error)

func (*ResourceServer) Parent added in v0.5.0

func (r *ResourceServer) Parent() Resource

func (*ResourceServer) String added in v0.0.2

func (r *ResourceServer) String() string

type ResourceServerGroupInstance added in v0.1.0

type ResourceServerGroupInstance struct {
	*ResourceBase
	// contains filtered or unexported fields
}

func (*ResourceServerGroupInstance) Compute added in v0.1.0

func (r *ResourceServerGroupInstance) Compute(ctx *RequestContext, refresh bool) (Computed, error)

func (*ResourceServerGroupInstance) Parent added in v0.5.0

func (*ResourceServerGroupInstance) String added in v0.1.0

func (r *ResourceServerGroupInstance) String() string

type ResourceTypes

type ResourceTypes int
const (
	ResourceTypeUnknown ResourceTypes = iota
	ResourceTypeServer
	ResourceTypeServerGroup
	ResourceTypeServerGroupInstance
	ResourceTypeELB
	ResourceTypeGSLB
	ResourceTypeDNS
	ResourceTypeRouter
	ResourceTypeLoadBalancer
)

func (ResourceTypes) String

func (rt ResourceTypes) String() string

type Resources

type Resources []Resource

Resources Resourceのスライス

func (*Resources) String added in v0.0.2

func (rs *Resources) String() string

type RouterPlan

type RouterPlan struct {
	Name      string `yaml:"name"`
	BandWidth int    `yaml:"band_width"`
}

func (*RouterPlan) Equals

func (p *RouterPlan) Equals(resource interface{}) bool

func (*RouterPlan) LessThan

func (p *RouterPlan) LessThan(resource interface{}) bool

func (*RouterPlan) LessThanPlan

func (p *RouterPlan) LessThanPlan(plan ResourcePlan) bool

func (*RouterPlan) PlanName

func (p *RouterPlan) PlanName() string

type SakuraCloud

type SakuraCloud struct {
	Credential `yaml:",inline"`
	Profile    string `yaml:"profile"`
	// contains filtered or unexported fields
}

func (*SakuraCloud) APIClient

func (sc *SakuraCloud) APIClient() iaas.APICaller

APIClient シングルトンなAPIクライアントを返す

func (*SakuraCloud) Validate

func (sc *SakuraCloud) Validate(ctx context.Context) error

Validate 有効なAPIキーが指定されており、必要なパーミッションが割り当てられていることを確認する

type SakuraCloudResource added in v0.5.0

type SakuraCloudResource interface {
	GetID() types.ID
	GetName() string
	GetModifiedAt() time.Time
}

type ScalingService

type ScalingService struct {
	request.UnimplementedScalingServiceServer
	// contains filtered or unexported fields
}

func NewScalingService

func NewScalingService(instance *Core) *ScalingService

func (*ScalingService) Check added in v0.1.0

Check gRPCヘルスチェックの実装

func (*ScalingService) Down

func (*ScalingService) Up

func (*ScalingService) Watch added in v0.1.0

Watch gRPCヘルスチェックの実装

type ServerGroupCloudConfig added in v0.3.0

type ServerGroupCloudConfig struct {
	CloudConfig config.StringOrFilePath `yaml:"cloud_config"`
}

func (ServerGroupCloudConfig) Empty added in v0.3.0

func (c ServerGroupCloudConfig) Empty() bool

func (ServerGroupCloudConfig) String added in v0.3.0

func (c ServerGroupCloudConfig) String() string

func (ServerGroupCloudConfig) Validate added in v0.3.0

func (c ServerGroupCloudConfig) Validate() []error

type ServerGroupDiskEditTemplate added in v0.1.0

type ServerGroupDiskEditTemplate struct {
	Disabled bool `yaml:"disabled"` // ディスクの修正を行わない場合にtrue

	HostNamePrefix string `yaml:"host_name_prefix"` // からの場合は{{ .ServerName }} 、そうでなければ {{ .HostNamePrefix }}{{ .Number }}
	HostNameFormat string `yaml:"host_name_format"`

	Password            string                    `yaml:"password"` // グループ内のサーバは全部一緒になるが良いか??
	DisablePasswordAuth bool                      `yaml:"disable_pw_auth"`
	EnableDHCP          bool                      `yaml:"enable_dhcp"`
	ChangePartitionUUID bool                      `yaml:"change_partition_uuid"`
	StartupScripts      []config.StringOrFilePath `yaml:"startup_scripts"`

	SSHKeys []config.StringOrFilePath `yaml:"ssh_keys"`
}

func (*ServerGroupDiskEditTemplate) HostName added in v0.1.0

func (t *ServerGroupDiskEditTemplate) HostName(serverName string, index int) string

HostName HostNamePrefixとindexからホスト名を算出する

HostNamePrefixが空の場合はserverNameをそのまま返す

func (*ServerGroupDiskEditTemplate) Validate added in v0.1.0

func (t *ServerGroupDiskEditTemplate) Validate() []error

type ServerGroupDiskTemplate added in v0.1.0

type ServerGroupDiskTemplate struct {
	NamePrefix  string   `yaml:"name_prefix"` // {{.ServerName}}{{.Name}}{{.Number}}
	NameFormat  string   `yaml:"name_format"`
	Tags        []string `yaml:"tags" validate:"unique,max=10,dive,max=32"`
	Description string   `yaml:"description" validate:"max=512"`

	IconId string              `yaml:"icon_id"`
	Icon   *IdOrNameOrSelector `yaml:"icon"`

	// ブランクディスクの場合は以下3つをゼロ値にする
	SourceArchiveSelector *NameOrSelector `yaml:"source_archive"`
	SourceDiskSelector    *NameOrSelector `yaml:"source_disk"`
	OSType                string          `yaml:"os_type"`

	Plan       string `yaml:"plan" validate:"omitempty,oneof=ssd hdd"`
	Connection string `yaml:"connection" validate:"omitempty,oneof=virtio ide"`
	Size       int    `yaml:"size"`
}

func (*ServerGroupDiskTemplate) DiskName added in v0.1.0

func (t *ServerGroupDiskTemplate) DiskName(serverName string, index int) string

func (*ServerGroupDiskTemplate) FindDiskSource added in v0.1.0

func (t *ServerGroupDiskTemplate) FindDiskSource(ctx context.Context, apiClient iaas.APICaller, zone string) (sourceArchiveID, sourceDiskID string, retErr error)

func (*ServerGroupDiskTemplate) FindIconID added in v0.9.0

func (t *ServerGroupDiskTemplate) FindIconID(ctx context.Context, apiClient iaas.APICaller) (string, error)

func (*ServerGroupDiskTemplate) Validate added in v0.1.0

func (t *ServerGroupDiskTemplate) Validate(ctx context.Context, apiClient iaas.APICaller, zone string) []error

type ServerGroupInstancePlan added in v0.1.0

type ServerGroupInstancePlan struct {
	Core         int    `yaml:"core"`
	Memory       int    `yaml:"memory"`
	GPU          int    `yaml:"gpu"`
	CPUModel     string `yaml:"cpu_model"`
	DedicatedCPU bool   `yaml:"dedicated_cpu"`
}

func (*ServerGroupInstancePlan) String added in v0.1.0

func (p *ServerGroupInstancePlan) String() string

func (*ServerGroupInstancePlan) Validate added in v0.1.0

func (p *ServerGroupInstancePlan) Validate(ctx context.Context, apiClient iaas.APICaller, zone string) error

type ServerGroupInstanceTemplate added in v0.1.0

type ServerGroupInstanceTemplate struct {
	Tags        []string `yaml:"tags" validate:"unique,max=10,dive,max=32"`
	UseGroupTag bool     `yaml:"use_group_tag"`

	Description string `yaml:"description" validate:"max=512"`

	IconId string              `yaml:"icon_id"`
	Icon   *IdOrNameOrSelector `yaml:"icon"`

	CDROMId string              `yaml:"cdrom_id"`
	CDROM   *IdOrNameOrSelector `yaml:"cdrom"`

	PrivateHostId string              `yaml:"private_host_id"`
	PrivateHost   *IdOrNameOrSelector `yaml:"private_host"`

	InterfaceDriver types.EInterfaceDriver `yaml:"interface_driver" validate:"omitempty,oneof=virtio e1000"`

	Plan              *ServerGroupInstancePlan     `yaml:"plan" validate:"required"`
	Disks             []*ServerGroupDiskTemplate   `yaml:"disks" validate:"max=4"`
	EditParameter     *ServerGroupDiskEditTemplate `yaml:"edit_parameter"`
	CloudConfig       ServerGroupCloudConfig       `yaml:",inline"`
	NetworkInterfaces []*ServerGroupNICTemplate    `yaml:"network_interfaces" validate:"max=10"`
}

func (*ServerGroupInstanceTemplate) CalculateTagsByIndex added in v0.10.0

func (s *ServerGroupInstanceTemplate) CalculateTagsByIndex(serverIndexWithinGroup int, zoneLength int) []string

func (*ServerGroupInstanceTemplate) FindCDROMId added in v0.9.0

func (s *ServerGroupInstanceTemplate) FindCDROMId(ctx context.Context, apiClient iaas.APICaller, zone string) (string, error)

func (*ServerGroupInstanceTemplate) FindIconId added in v0.9.0

func (s *ServerGroupInstanceTemplate) FindIconId(ctx context.Context, apiClient iaas.APICaller) (string, error)

func (*ServerGroupInstanceTemplate) FindPrivateHostId added in v0.9.0

func (s *ServerGroupInstanceTemplate) FindPrivateHostId(ctx context.Context, apiClient iaas.APICaller, zone string) (string, error)

func (*ServerGroupInstanceTemplate) Validate added in v0.1.0

func (s *ServerGroupInstanceTemplate) Validate(ctx context.Context, apiClient iaas.APICaller, def *ResourceDefServerGroup) []error

Validate .

type ServerGroupNICMetadata added in v0.1.0

type ServerGroupNICMetadata struct {
	// Ports 公開するポート
	Ports []int `yaml:"ports" validate:"unique,dive,min=1,max=65535"`

	// ServerGroupName ELBの実サーバとして登録する場合のサーバグループ名
	ServerGroupName string `yaml:"server_group_name"`

	// Weight GSLBに実サーバとして登録する場合の重み値
	Weight int `yaml:"weight"`

	// VIP LBに実サーバとして登録する場合の対象VIPリスト
	//
	// 省略した場合はこのメタデータがつけられたNICと同じネットワーク内に存在するVIP全てが対象となる
	VIPs []string `yaml:"vips" validate:"omitempty,dive,ipv4"`

	// HealthCheck LBに実サーバとして登録する場合のヘルスチェック
	HealthCheck *ServerGroupNICMetadataHealthCheck `yaml:"health_check"`

	// RecordName DNSにレコード登録する場合のレコード名
	RecordName string `yaml:"record_name"`

	// RecordTTL DNSにレコード登録する場合のTTL
	RecordTTL int `yaml:"record_ttl" validate:"omitempty,min=10,max=3600000"`
}

ServerGroupNICMetadata 上流リソースの操作時に参照されるメタデータ

func (*ServerGroupNICMetadata) ToExposeInfo added in v0.1.0

func (*ServerGroupNICMetadata) Validate added in v0.1.0

func (m *ServerGroupNICMetadata) Validate(parent *ParentResourceDef, nicIndex int) []error

type ServerGroupNICMetadataHealthCheck added in v0.1.0

type ServerGroupNICMetadataHealthCheck struct {
	Protocol   string `yaml:"protocol" validate:"required,oneof=http https ping tcp"`
	Path       string `yaml:"path"`
	StatusCode int    `yaml:"status_code"`
}

func (*ServerGroupNICMetadataHealthCheck) Validate added in v0.1.0

func (h *ServerGroupNICMetadataHealthCheck) Validate() []error

type ServerGroupNICTemplate added in v0.1.0

type ServerGroupNICTemplate struct {
	Upstream         *ServerGroupNICUpstream `yaml:"upstream" validate:"required"`                         // "shared" or *ResourceSelector
	AssignCidrBlock  string                  `yaml:"assign_cidr_block" validate:"omitempty,cidrv4"`        // 上流がスイッチの場合(ルータ含む)に割り当てるIPアドレスのCIDRブロック
	AssignNetMaskLen int                     `yaml:"assign_netmask_len" validate:"omitempty,min=1,max=32"` // 上流がスイッチの場合(ルータ含む)に割り当てるサブネットマスク長
	DefaultRoute     string                  `yaml:"default_route" validate:"omitempty,ipv4"`

	PacketFilterId string              `yaml:"packet_filter_id"`
	PacketFilter   *IdOrNameOrSelector `yaml:"packet_filter"`

	ExposeInfo *ServerGroupNICMetadata `yaml:"expose"`
}

func (*ServerGroupNICTemplate) FindPacketFilterId added in v0.9.0

func (t *ServerGroupNICTemplate) FindPacketFilterId(ctx context.Context, apiClient iaas.APICaller, zone string) (string, error)

func (*ServerGroupNICTemplate) IPAddressByIndexFromCidrBlock added in v0.1.0

func (t *ServerGroupNICTemplate) IPAddressByIndexFromCidrBlock(index int) (string, int, error)

IPAddressByIndexFromCidrBlock AssignCidrBlockからindexに対応するIPアドレスを返す

戻り値: IPアドレス, マスク長, エラー

func (*ServerGroupNICTemplate) Validate added in v0.1.0

func (t *ServerGroupNICTemplate) Validate(ctx context.Context, parent *ParentResourceDef, maxServerNum, nicIndex int) []error

type ServerGroupNICUpstream added in v0.1.0

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

func (*ServerGroupNICUpstream) Selector added in v0.1.0

func (*ServerGroupNICUpstream) UnmarshalYAML added in v0.1.0

func (s *ServerGroupNICUpstream) UnmarshalYAML(ctx context.Context, data []byte) error

func (*ServerGroupNICUpstream) UpstreamShared added in v0.1.0

func (s *ServerGroupNICUpstream) UpstreamShared() bool

type ServerGroupPlan added in v0.1.0

type ServerGroupPlan struct {
	Name string `yaml:"name"`
	Size int    `yaml:"size"`
}

func (*ServerGroupPlan) Equals added in v0.1.0

func (p *ServerGroupPlan) Equals(resource interface{}) bool

func (*ServerGroupPlan) LessThan added in v0.1.0

func (p *ServerGroupPlan) LessThan(resource interface{}) bool

func (*ServerGroupPlan) LessThanPlan added in v0.1.0

func (p *ServerGroupPlan) LessThanPlan(plan ResourcePlan) bool

func (*ServerGroupPlan) PlanName added in v0.1.0

func (p *ServerGroupPlan) PlanName() string

type ServerPlan

type ServerPlan struct {
	Name   string `yaml:"name"`
	Core   int    `yaml:"core"`   // コア数
	Memory int    `yaml:"memory"` // メモリサイズ(GiB)
}

func (*ServerPlan) Equals

func (p *ServerPlan) Equals(resource interface{}) bool

func (*ServerPlan) LessThan

func (p *ServerPlan) LessThan(resource interface{}) bool

func (*ServerPlan) LessThanPlan

func (p *ServerPlan) LessThanPlan(plan ResourcePlan) bool

func (*ServerPlan) PlanName

func (p *ServerPlan) PlanName() string

Jump to

Keyboard shortcuts

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