model

package
v0.0.0-...-987ecbf Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Create     = Phase("create")     // signal to start provisioning process
	Creating   = Phase("creating")   // Cloud API has been called to create node, attach firewall and network, store SSH key - probe until SSH login works and cloud-init status --format=json has status: done then move to Installing
	Updating   = Phase("updating")   // have logged in, running apt update, apt upgrade, reboot, wait until it disconnects for reboot then go to installing phase
	Installing = Phase("installing") // probe until SSH login works, install K3s using secret, disconnect, wait for Node resource to appear
	Joining    = Phase("joining")    // wait for Node resource to reach Active state (is this step worth having separate from previous? might help with recovering from crash?)
	Active     = Phase("active")     // node is ready and working - this is the main lifecycle phase
	Replace    = Phase("replace")    // node needs to be replaced
	Delete     = Phase("delete")     // signal to start deletion process
	Draining   = Phase("draining")   // when repair sees unhealthy node, it tells K8s to drain and enters this state
	Deleting   = Phase("deleting")   // when node has been in draining state for 5 minutes, repair tells Hetzner to delete the server
	Deleted    = Phase("deleted")    // server has been deleted from cloud
)

Variables

This section is empty.

Functions

func NewHetzner

func NewHetzner(token string) *rest.Client

func NewK3s

func NewK3s() *rest.Client

func NewKubernetes

func NewKubernetes() *rest.Client

func VersionMax

func VersionMax(a, b *semver.Version) *semver.Version

func VersionMin

func VersionMin(a, b *semver.Version) *semver.Version

Types

type Actions

type Actions interface {
	GetBootstrapServer(name string, apiServer bool, kubernetesVersion *semver.Version) (*NodeStatus, error)
	GetReleaseChannels() (ReleaseChannelStatuses, error)
	CreateServer(name string, serverType string, image string, location string, privateNetworkId string, firewallIds []string, labels label.Labels, sshKeyIds []int, cloudInit string) (cloudId string, clusterIP string, err error)
	DeleteServer(node NodeStatus) (notFound bool)
	DrainNode(node NodeStatus) error
	GetKubernetesNode(node NodeStatus) (*NodeResource, error)
	DeleteNode(node NodeStatus) error
	SaveStatus(clusterName string, clusterStatus *ClusterStatus) error
	GetSshKeyIds() ([]int, error)
}

type Cluster

type Cluster struct {
	ApiVersion string         `json:"apiVersion,omitempty" yaml:"apiVersion"`
	Kind       string         `json:"kind,omitempty"`
	Metadata   *Metadata      `json:"metadata,omitempty"`
	Spec       *Spec          `json:"spec,omitempty"`
	Status     *ClusterStatus `json:"status,omitempty"`
}

func (*Cluster) Bootstrap

func (c *Cluster) Bootstrap(actions Actions) error

func (*Cluster) CreateNodeSetStatusesIfNecessary

func (c *Cluster) CreateNodeSetStatusesIfNecessary()

func (*Cluster) Repair

func (c *Cluster) Repair(actions Actions) error

type ClusterActions

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

func NewClusterClient

func NewClusterClient() *ClusterActions

func (ClusterActions) Await

func (c ClusterActions) Await(resourceType string, resourceId int) error

func (ClusterActions) CreateServer

func (c ClusterActions) CreateServer(name string, serverType string, image string, location string, privateNetworkId string, firewallIds []string, labels label.Labels, sshKeyIds []int, cloudInit string) (cloudId string, clusterIP string, err error)

func (ClusterActions) DeleteNode

func (c ClusterActions) DeleteNode(node NodeStatus) error

func (ClusterActions) DeleteServer

func (c ClusterActions) DeleteServer(node NodeStatus) (notFound bool)

func (ClusterActions) DrainNode

func (c ClusterActions) DrainNode(node NodeStatus) error

func (ClusterActions) GetBootstrapServer

func (c ClusterActions) GetBootstrapServer(name string, apiServer bool, kubernetesVersion *semver.Version) (*NodeStatus, error)

func (ClusterActions) GetClusterList

func (c ClusterActions) GetClusterList() (*ClusterList, error)

func (ClusterActions) GetKubernetesNode

func (c ClusterActions) GetKubernetesNode(node NodeStatus) (*NodeResource, error)

func (ClusterActions) GetReleaseChannels

func (c ClusterActions) GetReleaseChannels() (ReleaseChannelStatuses, error)

func (ClusterActions) GetSshKeyIds

func (c ClusterActions) GetSshKeyIds() (keyIds []int, err error)

func (ClusterActions) SaveStatus

func (c ClusterActions) SaveStatus(clusterName string, status *ClusterStatus) error

type ClusterList

type ClusterList struct {
	Items Clusters `json:"items"`
}

type ClusterNetworkStatus

type ClusterNetworkStatus struct {
	CloudId string `json:"cloudId,omitempty"`
	IpRange string `json:"ipRange"`
}

type ClusterStatus

type ClusterStatus struct {
	Versions        *VersionStatus       `json:"versions"`
	ClusterNetwork  ClusterNetworkStatus `json:"clusterNetwork"`
	NodeSetStatuses `json:"nodeSets,omitempty"`
}

func (*ClusterStatus) Find

func (c *ClusterStatus) Find(filters ...Filter) (nodes NodeStatusRefs)

func (*ClusterStatus) UpdateVersionRanges

func (c *ClusterStatus) UpdateVersionRanges()

type Clusters

type Clusters []*Cluster

type CreateHetznerServerRequest

type CreateHetznerServerRequest struct {
	Name       string               `json:"name"`
	ServerType string               `json:"server_type"`
	Image      string               `json:"image"`
	Location   string               `json:"location,omitempty"`
	Networks   []int                `json:"networks,omitempty"`
	Firewalls  []HetznerFirewallRef `json:"firewalls,omitempty"`
	Labels     map[string]string    `json:"labels,omitempty"`
	SshKeys    []int                `json:"ssh_keys,omitempty"`
	CloudInit  string               `json:"user_data,omitempty"`
}

type Filter

type Filter func(n NodeStatus) bool

func InPhase

func InPhase(phases ...Phase) Filter

func IsApiServer

func IsApiServer(t bool) Filter

func LongerThan

func LongerThan(d time.Duration) Filter

func PhaseUpTo

func PhaseUpTo(phase Phase) Filter

type HetznerAction

type HetznerAction struct {
	Command   string                  `json:"command"`
	Status    string                  `json:"status"`
	Error     HetznerActionError      `json:"error"`
	Started   time.Time               `json:"started"`
	Finished  time.Time               `json:"finished"`
	Resources []HetznerActionResource `json:"resources"`
}

type HetznerActionError

type HetznerActionError struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

type HetznerActionResource

type HetznerActionResource struct {
	Id   int    `json:"id"`
	Type string `json:"type"`
}

type HetznerActionsResponse

type HetznerActionsResponse struct {
	Actions []HetznerAction `json:"actions"`
}

type HetznerFirewallRef

type HetznerFirewallRef struct {
	Firewall int `json:"firewall"`
}

type HetznerNetwork

type HetznerNetwork struct {
	Network int    `json:"network"`
	IP      string `json:"ip"`
}

type HetznerServerRef

type HetznerServerRef struct {
	Id         int              `json:"id"`
	PrivateNet []HetznerNetwork `json:"private_net"`
}

type HetznerServerResponse

type HetznerServerResponse struct {
	Id         int       `json:"id"`
	Created    time.Time `json:"created"`
	Datacenter struct {
		Location struct {
			Name string `json:"name"`
		} `json:"location"`
	} `json:"datacenter"`
	Image struct {
		Name string `json:"name"`
	} `json:"image"`
	PrivateNets []HetznerNetwork `json:"private_net"`
	ServerType  struct {
		Name string `json:"name"`
	} `json:"server_type"`
}

type HetznerServerResult

type HetznerServerResult struct {
	Server HetznerServerRef `json:"server"`
}

type HetznerServersResponse

type HetznerServersResponse struct {
	Servers []HetznerServerResponse `json:"servers"`
}

type HetznerSshKey

type HetznerSshKey struct {
	Id        int    `json:"id"`
	Name      string `json:"name"`
	PublicKey string `json:"public_key,omitempty"`
}

type HetznerSshKeys

type HetznerSshKeys struct {
	SshKeys []HetznerSshKey `json:"ssh_keys,omitempty"`
}

type K3sReleaseChannelsResponse

type K3sReleaseChannelsResponse struct {
	Data ReleaseChannelStatuses `json:"data"`
}

type Metadata

type Metadata struct {
	Name string `json:"name,omitempty"`
}

type NodeResource

type NodeResource struct {
	Spec   *NodeResourceSpec   `json:"spec,omitempty"`
	Status *NodeResourceStatus `json:"status,omitempty"`
}

func (NodeResource) IsReady

func (n NodeResource) IsReady() bool

type NodeResourceCondition

type NodeResourceCondition struct {
	Status string `json:"status,omitempty"`
	Type   string `json:"type,omitempty"`
}

type NodeResourceSpec

type NodeResourceSpec struct {
	Unschedulable bool `json:"unschedulable,omitempty"`
}

type NodeResourceStatus

type NodeResourceStatus struct {
	Conditions []NodeResourceCondition `json:"conditions,omitempty"`
}

type NodeSetSpec

type NodeSetSpec struct {
	Name       string   `json:"name"`
	ApiServer  bool     `json:"apiServer" yaml:"apiServer"`
	Replicas   int      `json:"replicas"`
	ServerType string   `json:"serverType" yaml:"serverType"`
	Locations  []string `json:"locations,omitempty"`
}

func (*NodeSetSpec) ServerName

func (n *NodeSetSpec) ServerName(clusterName string, generation int) string

type NodeSetStatus

type NodeSetStatus struct {
	Name         string `json:"name"`
	Generation   int    `json:"generation"`
	NodeStatuses `json:"nodes,omitempty"`
}

func (*NodeSetStatus) Repair

func (n *NodeSetStatus) Repair(cluster *Cluster)

type NodeSetStatuses

type NodeSetStatuses []*NodeSetStatus

func (*NodeSetStatuses) CreateIfNecessary

func (n *NodeSetStatuses) CreateIfNecessary(spec *NodeSetSpec)

func (NodeSetStatuses) Named

func (n NodeSetStatuses) Named(name string) *NodeSetStatus

type NodeSetsSpec

type NodeSetsSpec []*NodeSetSpec

func (NodeSetsSpec) FirstApiServerNodeSet

func (n NodeSetsSpec) FirstApiServerNodeSet() *NodeSetSpec

func (NodeSetsSpec) Named

func (n NodeSetsSpec) Named(name string) NodeSetSpec

type NodeStatus

type NodeStatus struct {
	Name         string          `json:"name"`
	ServerType   string          `json:"serverType"`
	Location     string          `json:"location"`
	CloudId      string          `json:"cloudId,omitempty"`
	ClusterIP    string          `json:"clusterIP,omitempty"`
	BaseImage    string          `json:"baseImage,omitempty"`
	ApiServer    bool            `json:"apiServer,omitempty"`
	Version      *semver.Version `json:"version,omitempty"`
	JoinEndpoint string          `json:"joinEndpoint,omitempty"`
	Phases       PhaseChanges    `json:"phases,omitempty"`
}

func (*NodeStatus) MakeProgress

func (n *NodeStatus) MakeProgress(cluster *Cluster, actions Actions)

func (*NodeStatus) SetPhase

func (n *NodeStatus) SetPhase(phase Phase, reason string)

type NodeStatusRefs

type NodeStatusRefs []*NodeStatus

func (NodeStatusRefs) GetVersionRange

func (n NodeStatusRefs) GetVersionRange() (v VersionRange)

func (NodeStatusRefs) MakeProgress

func (n NodeStatusRefs) MakeProgress(cluster *Cluster, actions Actions)

func (NodeStatusRefs) SetPhase

func (n NodeStatusRefs) SetPhase(phase Phase, reason string)

func (NodeStatusRefs) SortByPhase

func (n NodeStatusRefs) SortByPhase()

func (NodeStatusRefs) SortByRecency

func (n NodeStatusRefs) SortByRecency()

SortByRecency returns most recent first

type NodeStatuses

type NodeStatuses []*NodeStatus

func (*NodeStatuses) AddNode

func (n *NodeStatuses) AddNode(node *NodeStatus)

func (*NodeStatuses) Find

func (n *NodeStatuses) Find(filters ...Filter) (nodes NodeStatusRefs)

type Phase

type Phase string

func (Phase) Compare

func (p Phase) Compare(other Phase) int

type PhaseChange

type PhaseChange struct {
	Phase  Phase     `json:"phase"`
	Time   time.Time `json:"time"`
	Reason string    `json:"reason,omitempty"`
}

type PhaseChanges

type PhaseChanges []PhaseChange

func (PhaseChanges) Current

func (p PhaseChanges) Current() PhaseChange

type PodEviction

type PodEviction struct {
	ApiVersion string              `json:"apiVersion"`
	Kind       string              `json:"kind"`
	Metadata   PodEvictionMetadata `json:"metadata,omitempty"`
}

type PodEvictionMetadata

type PodEvictionMetadata struct {
	Name      string `json:"name"`
	Namespace string `json:"namespace"`
}

type PodMetadata

type PodMetadata struct {
	Name            string               `json:"name,omitempty"`
	Namespace       string               `json:"namespace,omitempty"`
	OwnerReferences []*PodOwnerReference `json:"ownerReferences,omitempty"`
}

type PodOwnerReference

type PodOwnerReference struct {
	ApiVersion string `json:"apiVersion,omitempty"`
	Kind       string `json:"kind,omitempty"`
	Name       string `json:"name,omitempty"`
}

type PodResource

type PodResource struct {
	Metadata *PodMetadata `json:"metadata,omitempty"`
}

type PodResourceList

type PodResourceList struct {
	Items []PodResource `json:"items"`
}

type ReleaseChannelStatus

type ReleaseChannelStatus struct {
	Name   string          `json:"name"`
	Latest *semver.Version `json:"latest"`
}

type ReleaseChannelStatuses

type ReleaseChannelStatuses []*ReleaseChannelStatus

func (ReleaseChannelStatuses) Named

type Spec

type Spec struct {
	Versions VersionsSpec `json:"versions,omitempty"`
	NodeSets NodeSetsSpec `json:"nodeSets,omitempty" yaml:"nodeSets"`
}

type VersionRange

type VersionRange struct {
	Min *semver.Version `json:"min,omitempty"`
	Max *semver.Version `json:"max,omitempty"`
}

func (VersionRange) MergeRange

func (v VersionRange) MergeRange(other VersionRange) VersionRange

func (VersionRange) MergeVersion

func (v VersionRange) MergeVersion(other *semver.Version) VersionRange

func (VersionRange) Same

func (v VersionRange) Same() bool

type VersionStatus

type VersionStatus struct {
	Target   *semver.Version        `json:"target,omitempty"`
	Nodes    VersionRange           `json:"nodes"`
	Api      VersionRange           `json:"api"`
	Workers  VersionRange           `json:"workers"`
	Channels ReleaseChannelStatuses `json:"channels,omitempty"`
}

func (VersionStatus) NewApiNodeVersion

func (v VersionStatus) NewApiNodeVersion() *semver.Version

func (VersionStatus) NewNodeVersion

func (v VersionStatus) NewNodeVersion(apiServer bool) *semver.Version

func (VersionStatus) NewWorkerNodeVersion

func (v VersionStatus) NewWorkerNodeVersion() *semver.Version

func (*VersionStatus) UpdateReleaseChannels

func (v *VersionStatus) UpdateReleaseChannels(releaseChannel string, actions Actions) error

type VersionsSpec

type VersionsSpec struct {
	BaseImage  string `json:"baseImage,omitempty" yaml:"baseImage"`
	Kubernetes string `json:"kubernetes,omitempty"`
	Hetzanetes string `json:"hetzanetes,omitempty"`
}

func (*VersionsSpec) GetBaseImage

func (v *VersionsSpec) GetBaseImage() string

func (VersionsSpec) GetHetzanetes

func (v VersionsSpec) GetHetzanetes() string

func (VersionsSpec) GetKubernetes

func (v VersionsSpec) GetKubernetes() string

Jump to

Keyboard shortcuts

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