model

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2016 License: Apache-2.0 Imports: 10 Imported by: 28

Documentation

Index

Constants

View Source
const (
	UserRoleAdmin = "admin"
	UserRoleUser  = "user"
)

Variables

This section is empty.

Functions

func RootFieldJSONNames added in v0.10.1

func RootFieldJSONNames(m Model) (fields []string)

func ZeroPrivateFields

func ZeroPrivateFields(r Model)

ZeroPrivateFields takes a Model with pointer, and zeroes any fields with the tag sg:"private".

func ZeroReadonlyFields

func ZeroReadonlyFields(r Model)

ZeroReadonlyFields takes a Model with pointer, and zeroes any fields with the tag sg:"readonly".

Types

type AWSKubeConfig

type AWSKubeConfig struct {
	Region              string `json:"region" validate:"nonzero,regexp=^[a-z]{2}-[a-z]+-[0-9]$"`
	AvailabilityZone    string `json:"availability_zone" validate:"nonzero,regexp=^[a-z]{2}-[a-z]+-[0-9][a-z]$"`
	VPCIPRange          string `json:"vpc_ip_range" validate:"nonzero" sg:"default=172.20.0.0/16"`
	PublicSubnetIPRange string `json:"public_subnet_ip_range" validate:"nonzero" sg:"default=172.20.0.0/24"`
	MasterPrivateIP     string `json:"master_private_ip" validate:"nonzero" sg:"default=172.20.0.9"`

	PrivateKey                    string `json:"private_key,omitempty" sg:"readonly,private"`
	VPCID                         string `json:"vpc_id" sg:"readonly"`
	InternetGatewayID             string `json:"internet_gateway_id" sg:"readonly"`
	PublicSubnetID                string `json:"public_subnet_id" sg:"readonly"`
	RouteTableID                  string `json:"route_table_id" sg:"readonly"`
	RouteTableSubnetAssociationID string `json:"route_table_subnet_association_id" sg:"readonly"`
	ELBSecurityGroupID            string `json:"elb_security_group_id" sg:"readonly"`
	NodeSecurityGroupID           string `json:"node_security_group_id" sg:"readonly"`
	MasterID                      string `json:"master_id" sg:"readonly"`
}

AWSKubeConfig holds aws specific information about AWS based KUbernetes clusters.

type ActionStatus

type ActionStatus struct {
	Description string `json:"description"`
	MaxRetries  int    `json:"max_retries"`
	Retries     int    `json:"retries"`
	Error       string `json:"error,omitempty"`
	Cancelled   bool   `json:"cancelled,omitempty"`
}

type BaseList added in v0.10.1

type BaseList struct {
	// Filters input looks like this:
	// {
	// 	"name": [
	// 		"this", "that"
	// 	],
	// 	"other_field": [
	// 		"thingy"
	// 	]
	// }
	// The values of each key are joined as OR queries.
	// Multiple keys are joined as AND queries.
	// The above translates to "(name=this OR name=that) AND (other_fied=thingy)".
	Filters map[string][]string `json:"filters"`

	// Pagination
	Offset int64 `json:"offset"`
	Limit  int64 `json:"limit"`
	Total  int64 `json:"total"`
}

func (BaseList) QueryValues added in v0.10.1

func (l BaseList) QueryValues() map[string][]string

type BaseModel

type BaseModel struct {
	ID        *int64        `gorm:"primary_key" json:"id,omitempty" sg:"readonly"`
	UUID      string        `json:"uuid,omitempty" sg:"readonly"`
	CreatedAt time.Time     `json:"created_at,omitempty" sg:"readonly"` // TODO won't be omitted cuz not *time.Time
	UpdatedAt time.Time     `json:"updated_at,omitempty" sg:"readonly"`
	Status    *ActionStatus `gorm:"-" json:"status,omitempty"`

	PassiveStatus     string `gorm:"-" json:"passive_status,omitempty"`
	PassiveStatusOkay bool   `gorm:"-" json:"passive_status_okay,omitempty"`
}

func (*BaseModel) GetID

func (m *BaseModel) GetID() interface{}

func (*BaseModel) GetUUID

func (m *BaseModel) GetUUID() string

func (*BaseModel) SetActionStatus

func (m *BaseModel) SetActionStatus(status *ActionStatus)

func (*BaseModel) SetPassiveStatus added in v0.11.0

func (m *BaseModel) SetPassiveStatus()

func (*BaseModel) SetUUID

func (m *BaseModel) SetUUID()

type BelongsToField

type BelongsToField struct {
	Field reflect.StructField
	Value reflect.Value
}

type CloudAccount

type CloudAccount struct {
	BaseModel

	// has_many Kubes
	Kubes []*Kube `json:"kubes,omitempty"`

	Name string `json:"name" validate:"nonzero" gorm:"not null;unique_index"`

	Provider string `json:"provider" validate:"regexp=^(aws|digitalocean)$" gorm:"not null"`

	// NOTE this is loose map to allow for multiple clouds (eventually)
	Credentials     map[string]string `json:"credentials,omitempty" validate:"nonzero" gorm:"-" sg:"store_as_json_in=CredentialsJSON,private"`
	CredentialsJSON []byte            `json:"-" gorm:"not null"`
}

type CloudAccountList added in v0.10.1

type CloudAccountList struct {
	BaseList
	Items []*CloudAccount `json:"items"`
}

type DOKubeConfig added in v0.10.0

type DOKubeConfig struct {
	Region            string `json:"region" validate:"nonzero"`
	SSHKeyFingerprint string `json:"ssh_key_fingerprint" validate:"nonzero"`

	MasterID int `json:"master_id" sg:"readonly"`
}

DOKubeConfig holds do specific information about DO based KUbernetes clusters.

type Entrypoint

type Entrypoint struct {
	BaseModel

	// belongs_to Kube
	Kube     *Kube  `json:"kube,omitempty" gorm:"ForeignKey:KubeName;AssociationForeignKey:Name"`
	KubeName string `json:"kube_name" gorm:"not null;index"`

	Name string `json:"name" validate:"nonzero,max=21,regexp=^[\\w-]+$" gorm:"not null;unique_index"`

	Listeners     []*EntrypointListener `json:"ports,omitempty" gorm:"-" sg:"store_as_json_in=ListenersJSON"`
	ListenersJSON []byte                `json:"-"`

	ProviderID string `json:"provider_id" sg:"readonly"`
	Address    string `json:"address,omitempty" sg:"readonly"`
}

func (*Entrypoint) BeforeCreate

func (m *Entrypoint) BeforeCreate() error

type EntrypointList added in v0.10.1

type EntrypointList struct {
	BaseList
	Items []*Entrypoint `json:"items"`
}

type EntrypointListener added in v0.11.0

type EntrypointListener struct {
	BaseModel

	// belongs_to Entrypoint
	Entrypoint     *Entrypoint `json:"entrypoint,omitempty" gorm:"ForeignKey:EntrypointName;AssociationForeignKey:Name"`
	EntrypointName string      `` /* 133-byte string literal not displayed */

	// belongs_to KubeResource (with this model, I don't think this should be allowed to change)
	KubeResource   *KubeResource `json:"kube_resource,omitempty"`
	KubeResourceID *int64        `json:"kube_resource_id" gorm:"index"`

	// Name is required to give the port identity
	Name string `` /* 136-byte string literal not displayed */

	// EntrypointPort is the external port the user connects to
	EntrypointPort     int64  `json:"entrypoint_port" validate:"nonzero" gorm:"not null;unique_index:entrypoint_port"`
	EntrypointProtocol string `json:"entrypoint_protocol" validate:"nonzero" sg:"default=TCP"`

	// NodePort is the target port, what EntrypointPort maps to
	NodePort     int64  `json:"node_port" validate:"nonzero"`
	NodeProtocol string `json:"node_protocol" validate:"nonzero" sg:"default=TCP"`
}

type EntrypointListenerList added in v0.11.0

type EntrypointListenerList struct {
	BaseList
	Items []*EntrypointListener `json:"items"`
}

type Error

type Error struct {
	Status  int    `json:"status"`
	Message string `json:"message"`
}

func (*Error) Error

func (e *Error) Error() string

type Kube

type Kube struct {
	BaseModel

	// belongs_to CloudAccount
	CloudAccount     *CloudAccount `json:"cloud_account,omitempty" gorm:"ForeignKey:CloudAccountName;AssociationForeignKey:Name"`
	CloudAccountName string        `json:"cloud_account_name" validate:"nonzero" gorm:"not null;index"`

	// has_many Nodes
	Nodes []*Node `json:"nodes,omitempty" gorm:"ForeignKey:KubeName;AssociationForeignKey:Name"`

	// has_many Entrypoints
	Entrypoints []*Entrypoint `json:"entrypoints,omitempty" gorm:"ForeignKey:KubeName;AssociationForeignKey:Name"`

	// has_many Volumes
	Volumes []*Volume `json:"volumes,omitempty" gorm:"ForeignKey:KubeName;AssociationForeignKey:Name"`

	// has_many KubeResources
	KubeResources []*KubeResource `json:"kube_resources,omitempty" gorm:"ForeignKey:KubeName;AssociationForeignKey:Name"`

	Name string `json:"name" validate:"nonzero,max=12,regexp=^[a-z]([-a-z0-9]*[a-z0-9])?$" gorm:"not null;unique_index"`

	MasterNodeSize string `json:"master_node_size" validate:"nonzero"`

	NodeSizes     []string `json:"node_sizes" gorm:"-" validate:"min=1" sg:"store_as_json_in=NodeSizesJSON"`
	NodeSizesJSON []byte   `json:"-" gorm:"not null"`

	Username string `json:"username" validate:"nonzero"`
	Password string `json:"password" validate:"nonzero"`

	HeapsterVersion          string `json:"heapster_version" validate:"nonzero" sg:"default=v1.1.0"`
	HeapsterMetricResolution string `json:"heapster_metric_resolution" validate:"regexp=^([0-9]+[smhd])+$" sg:"default=20s"`

	// NOTE due to how we marshal this as JSON, it's difficult to have this stored
	// as an interface, because unmarshalling causes us to lose the underlying
	// type. So, this is kindof like a whacky form of single-table inheritance.
	AWSConfig     *AWSKubeConfig `json:"aws_config,omitempty" gorm:"-" sg:"store_as_json_in=AWSConfigJSON"`
	AWSConfigJSON []byte         `json:"-"`

	DigitalOceanConfig     *DOKubeConfig `json:"digitalocean_config,omitempty" gorm:"-" sg:"store_as_json_in=DigitalOceanConfigJSON"`
	DigitalOceanConfigJSON []byte        `json:"-"`

	MasterPublicIP string `json:"master_public_ip" sg:"readonly"`

	Ready bool `json:"ready" sg:"readonly" gorm:"index"`
}

Kube objects contains global info about kubernetes ckusters.

type KubeList added in v0.10.1

type KubeList struct {
	BaseList
	Items []*Kube `json:"items"`
}

type KubeResource added in v0.11.0

type KubeResource struct {
	BaseModel

	// belongs_to Kube
	Kube     *Kube  `json:"kube,omitempty" gorm:"ForeignKey:KubeName;AssociationForeignKey:Name"`
	KubeName string `json:"kube_name" validate:"nonzero" gorm:"not null;unique_index:kube_namespace_kind_name"`

	// Kind corresponds directly to the Kind of Kubernetes resource (e.g. Pod, Service, etc.)
	Kind string `json:"kind" validate:"nonzero" gorm:"not null;unique_index:kube_namespace_kind_name"`

	// Namespace corresponds directly to the name of the Kubernetes namespace.
	Namespace string `json:"namespace" validate:"nonzero,max=24" gorm:"not null;unique_index:kube_namespace_kind_name"`

	// Name corresponds directly to the name of the resource in Kubernetes.
	Name string `json:"name" validate:"nonzero,max=24" gorm:"not null;unique_index:kube_namespace_kind_name"`

	// Template is where Kubernetes resources can be defined with special
	// Supergiant "modifiers". If the User is wanting to use the Pod or Service
	// Provisioner (to have Supergiant resources created and applied), Template
	// must be defined in place of Definition.
	Template     *json.RawMessage `json:"template" gorm:"-" sg:"store_as_json_in=TemplateJSON"`
	TemplateJSON []byte           `json:"-"`

	// Definition is where the finalized Kubernetes resource is stored, used to
	// actually create the entity. The User can provide this directly, which will
	// use the DefaultProvisioner.
	Definition     *json.RawMessage `json:"definition" gorm:"-"` // We aren't actually storing this anymore
	DefinitionJSON []byte           `json:"-"`

	// Artifact is where the full resource response from Kubernetes is stored.
	Artifact     *json.RawMessage `json:"artifact" gorm:"-" sg:"store_as_json_in=ArtifactJSON,readonly"`
	ArtifactJSON []byte           `json:"-"`

	// Started represents whether the resource exists in Kubernetes or not. If it
	// is a Pod, it also means the Pod is running.
	Started bool `json:"started" sg:"readonly"`

	// This is used to store unstructured data such as metrics from Heapster.
	ExtraData     map[string]interface{} `json:"extra_data" gorm:"-" sg:"store_as_json_in=ExtraDataJSON,readonly"`
	ExtraDataJSON []byte                 `json:"-"`
}

func (*KubeResource) SetPassiveStatus added in v0.11.0

func (m *KubeResource) SetPassiveStatus()

type KubeResourceList added in v0.11.0

type KubeResourceList struct {
	BaseList
	Items []*KubeResource `json:"items"`
}

type List added in v0.10.1

type List interface {
	QueryValues() map[string][]string
}

type Model

type Model interface {
	GetID() interface{}
	GetUUID() string
	SetUUID()
	SetActionStatus(*ActionStatus)
	SetPassiveStatus()
}

type Node

type Node struct {
	BaseModel

	// belongs_to Kube
	Kube     *Kube  `json:"kube,omitempty" gorm:"ForeignKey:KubeName;AssociationForeignKey:Name"`
	KubeName string `json:"kube_name" gorm:"not null;index"`

	// This is the only input for Node
	Size string `json:"size" validate:"nonzero"`

	ProviderID                string    `json:"provider_id" sg:"readonly" gorm:"index"`
	Name                      string    `json:"name" sg:"readonly" gorm:"index"`
	ExternalIP                string    `json:"external_ip" sg:"readonly"`
	ProviderCreationTimestamp time.Time `json:"provider_creation_timestamp" sg:"readonly"`

	OutOfDisk bool `json:"out_of_disk" sg:"readonly"`

	ResourceMetrics
}

type NodeList added in v0.10.1

type NodeList struct {
	BaseList
	Items []*Node `json:"items"`
}

type ResourceMetrics

type ResourceMetrics struct {
	CPUUsage int64 `json:"cpu_usage" sg:"readonly"`
	CPULimit int64 `json:"cpu_limit" sg:"readonly"`
	RAMUsage int64 `json:"ram_usage" sg:"readonly"`
	RAMLimit int64 `json:"ram_limit" sg:"readonly"`
}

type Session

type Session struct {
	ID        string    `json:"id"`
	UserID    *int64    `json:"user_id"`
	CreatedAt time.Time `json:"created_at"`

	User *User `json:"user"`
}

func (*Session) Description

func (m *Session) Description() string

func (*Session) GetID

func (m *Session) GetID() interface{}

func (*Session) GetUUID

func (m *Session) GetUUID() string

func (*Session) SetActionStatus

func (m *Session) SetActionStatus(status *ActionStatus)

func (*Session) SetPassiveStatus added in v0.11.0

func (m *Session) SetPassiveStatus()

func (*Session) SetUUID

func (m *Session) SetUUID()

type SessionList added in v0.10.1

type SessionList struct {
	BaseList
	Items []*Session `json:"items"`
}

type TaggedModelField

type TaggedModelField struct {
	Field         reflect.Value
	Readonly      bool
	Private       bool
	Default       interface{}
	StoreAsJsonIn *reflect.Value
	ForeignKeyOf  *BelongsToField
}

func TaggedModelFieldsOf

func TaggedModelFieldsOf(r Model) (taggedFields []*TaggedModelField)

type User

type User struct {
	BaseModel

	Username string `json:"username" validate:"nonzero,max=24,regexp=^[A-Za-z0-9_-]+$" gorm:"not null;unique_index"`
	Password string `json:"password,omitempty" validate:"nonzero,min=8,max=32" gorm:"-" sg:"private"`
	Role     string `json:"role" validate:"nonzero" gorm:"not null" sg:"default=user"`

	EncryptedPassword []byte `json:"-" gorm:"not null"`

	APIToken string `json:"api_token" gorm:"not null;index" sg:"readonly"`
}

func (*User) BeforeCreate

func (m *User) BeforeCreate() error

func (*User) BeforeSave

func (m *User) BeforeSave() error

func (*User) GenerateAPIToken

func (m *User) GenerateAPIToken()

type UserList added in v0.10.1

type UserList struct {
	BaseList
	Items []*User `json:"items"`
}

type Volume

type Volume struct {
	BaseModel

	// belongs_to Kube
	Kube     *Kube  `json:"kube,omitempty" gorm:"ForeignKey:KubeName;AssociationForeignKey:Name"`
	KubeName string `json:"kube_name" validate:"nonzero" gorm:"not null;index"`

	// belongs_to KubeResource (this can change, or even be temporarily nil)
	KubeResource   *KubeResource `json:"kube_resource,omitempty"`
	KubeResourceID *int64        `json:"kube_resource_id" gorm:"index"`

	Name string `json:"name" validate:"nonzero,max=24,regexp=^[\\w-]+$" gorm:"not null;unique_index"`
	Type string `json:"type"`
	Size int    `json:"size" validate:"nonzero"`

	ProviderID string `json:"provider_id" sg:"readonly"`
}

type VolumeList added in v0.10.1

type VolumeList struct {
	BaseList
	Items []*Volume `json:"items"`
}

Jump to

Keyboard shortcuts

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