providers

package
v0.0.0-...-60ce6a2 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2017 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NotFoundError = errgo.New("not-found")
)

Functions

func FetchSSHKeys

func FetchSSHKeys(githubAccount string) ([]string, error)

FetchSSHKeys uses a github account to fetch public SSH keys

func RegisterInstance

func RegisterInstance(logger *logging.Logger, dnsProvider DnsProvider, options CreateInstanceOptions, name string, registerInstance, registerCluster, registerPrivateCluster bool, publicIpv4, publicIpv6, privateIpv4 string) error

RegisterInstance creates DNS records for an instance

func UnRegisterInstance

func UnRegisterInstance(logger *logging.Logger, dnsProvider DnsProvider, instance ClusterInstance, domain string) error

UnRegisterInstance removes DNS records for an instance

func UpdateClusterMembers

func UpdateClusterMembers(log *logging.Logger, info ClusterInfo, rebootAfter bool, isEtcdProxy func(ClusterInstance) (bool, error), provider CloudProvider) error

UpdateClusterMembers updates /etc/cluster-members on all instances of the cluster

Types

type CloudConfigOptions

type CloudConfigOptions struct {
	ClusterID      string
	PrivateIPv4    string
	SshKeys        []string
	RebootStrategy string
}

Options for cloud-config files

type CloudProvider

type CloudProvider interface {
	ShowRegions() error
	ShowImages() error
	ShowKeys() error
	ShowInstanceTypes() error

	// Apply defaults for the given options
	ClusterDefaults(options ClusterInfo) ClusterInfo

	// Apply defaults for the given options
	CreateInstanceDefaults(options CreateInstanceOptions) CreateInstanceOptions

	// Apply defaults for the given options
	CreateClusterDefaults(options CreateClusterOptions) CreateClusterOptions

	// Create a machine instance
	CreateInstance(log *logging.Logger, options CreateInstanceOptions, dnsProvider DnsProvider) (ClusterInstance, error)

	// Create an entire cluster
	CreateCluster(log *logging.Logger, options CreateClusterOptions, dnsProvider DnsProvider) error

	// Get names of instances of a cluster
	GetInstances(info ClusterInfo) (ClusterInstanceList, error)

	// Remove all instances of a cluster
	DeleteCluster(info ClusterInfo, dnsProvider DnsProvider) error

	// Remove a single instance of a cluster
	DeleteInstance(info ClusterInstanceInfo, dnsProvider DnsProvider) error

	// Perform a reboot of the given instance
	RebootInstance(instance ClusterInstance) error

	// Update the instances of the cluster to all new services & formats
	UpdateCluster(log *logging.Logger, info ClusterInfo, dnsProvider DnsProvider) error

	ShowDomainRecords(domain string) error
}

CloudProvider holds all functions to be implemented by cloud providers

type ClusterInfo

type ClusterInfo struct {
	ID     string // /etc/pulcy/cluster-id, used for vault-monkey authentication
	Domain string // Domain postfix (e.g. pulcy.com)
	Name   string // Name of the cluster
}

ClusterInfo describes a cluster

func (ClusterInfo) String

func (ci ClusterInfo) String() string

type ClusterInstance

type ClusterInstance struct {
	ID               string // Provider specific ID of the server (only used by provider, can be empty)
	Name             string // Name of the instance as known by the provider
	ClusterIP        string // IPv4 address of the instance used for all private communication in the cluster
	LoadBalancerIPv4 string // IPv4 address of the instance on which the load-balancer is listening (can be empty)
	LoadBalancerIPv6 string // IPv6 address of the instance on which the load-balancer is listening (can be empty)
	IsGateway        bool   // If set, this instance can be used as a gateway by instances that have not direct IPv4 internet connection
	LoadBalancerDNS  string // Provider hosted public DNS name of the instance on which the load-balancer is listening (can be empty)
	ClusterDevice    string // Device name of the nic that is configured for the ClusterIP
	PrivateIP        string // IP address of the instance's private network (can be same as ClusterIP)
	PrivateNetwork   net.IPNet
	PrivateDNS       string   // Provider hosted private DNS name of the instance's private network
	UserName         string   // Account name used to SSH into this instance. (empty defaults to 'core')
	OS               OSName   // Name of the OS on the instance
	Extra            []string // Extra informational data
	EtcdProxy        *bool
}

ClusterInstance describes a single instance

func (ClusterInstance) AsClusterMember

func (i ClusterInstance) AsClusterMember(log *logging.Logger) (ClusterMember, error)

AsClusterMember fetches all data from the instance needed for a ClusterMember and returns that.

func (ClusterInstance) Connect

func (i ClusterInstance) Connect() (InstanceConnection, error)

Connect opens an SSH session to the instance. Make sure to close the session when done.

func (ClusterInstance) Equals

func (i ClusterInstance) Equals(other ClusterInstance) bool

Equals returns true of the given cluster instances refer to the same instance.

func (ClusterInstance) GetMachineID

func (i ClusterInstance) GetMachineID(log *logging.Logger) (string, error)

GetMachineID loads the machine specific unique ID of the instance.

func (ClusterInstance) Home

func (i ClusterInstance) Home() string

User returns the standard home directory instance

func (ClusterInstance) InitialSetup

func (i ClusterInstance) InitialSetup(log *logging.Logger, cio CreateInstanceOptions, iso InitialSetupOptions, provider CloudProvider) error

InitialSetup creates initial files and calls gluon for the first time

func (ClusterInstance) IsEtcdProxy

func (i ClusterInstance) IsEtcdProxy(log *logging.Logger) (bool, error)

IsEtcdProxy returns true if the instance in an ETCD proxy.

func (ClusterInstance) IsSSHPortOpen

func (i ClusterInstance) IsSSHPortOpen(log *logging.Logger) (bool, error)

IsSSHPortOpen checks if the SSH port on this instance is open for communications.

func (ClusterInstance) String

func (i ClusterInstance) String() string

String returns a human readable representation of the given instance

func (ClusterInstance) UpdateClusterMembers

func (i ClusterInstance) UpdateClusterMembers(log *logging.Logger, members ClusterMemberList) error

UpdateClusterMembers updates /etc/pulcy/cluster-members on the given instance

func (ClusterInstance) User

func (i ClusterInstance) User() string

User returns the standard username of this instance

type ClusterInstanceInfo

type ClusterInstanceInfo struct {
	ClusterInfo
	Prefix string // Prefix on the instance name
}

ClusterInstanceInfo describes a single instance of a cluster

func (ClusterInstanceInfo) String

func (cii ClusterInstanceInfo) String() string

type ClusterInstanceList

type ClusterInstanceList []ClusterInstance

func (ClusterInstanceList) AddEtcdMember

func (cil ClusterInstanceList) AddEtcdMember(log *logging.Logger, name, clusterIP string) error

AddEtcdMember calls etcdctl to add a member to ETCD on any of the instances in the given list

func (ClusterInstanceList) AsClusterMemberList

func (cil ClusterInstanceList) AsClusterMemberList(log *logging.Logger, isEtcdProxy func(ClusterInstance) (bool, error)) (ClusterMemberList, error)

func (ClusterInstanceList) Contains

func (cil ClusterInstanceList) Contains(i ClusterInstance) bool

Contains returns true if the given instance is an element of the given list, false otherwise.

func (ClusterInstanceList) CreateClusterIP

func (cil ClusterInstanceList) CreateClusterIP(cidr string) (net.IP, error)

CreateClusterIP returns an IP address in the given CIDR, not used by any of the instances.

func (ClusterInstanceList) Except

Except returns a copy of the given list except the given instance.

func (ClusterInstanceList) GetClusterID

func (cil ClusterInstanceList) GetClusterID(log *logging.Logger) (string, error)

GetClusterID loads the cluster ID from any of the instances in the given list

func (ClusterInstanceList) GetGluonEnv

func (cil ClusterInstanceList) GetGluonEnv(log *logging.Logger) (string, error)

func (ClusterInstanceList) GetVaultAddr

func (cil ClusterInstanceList) GetVaultAddr(log *logging.Logger) (string, error)

GetVaultAddr loads the vault address from any of the instances in the given list

func (ClusterInstanceList) GetVaultCrt

func (cil ClusterInstanceList) GetVaultCrt(log *logging.Logger) (string, error)

GetVaultCrt loads the vault certificate from any of the instances in the given list

func (ClusterInstanceList) GetWeaveEnv

func (cil ClusterInstanceList) GetWeaveEnv(log *logging.Logger) (string, error)

func (ClusterInstanceList) GetWeaveSeed

func (cil ClusterInstanceList) GetWeaveSeed(log *logging.Logger) (string, error)

func (ClusterInstanceList) InstanceByName

func (cil ClusterInstanceList) InstanceByName(name string) (ClusterInstance, error)

InstanceByName returns the instance (in the given list) with the given name.

func (ClusterInstanceList) IsFreeClusterIP

func (cil ClusterInstanceList) IsFreeClusterIP(ip net.IP) bool

IsFreeClusterIP returns true if the given IP address is not used as a cluster IP by any of the instances. false otherwise.

func (ClusterInstanceList) ReconfigureTincCluster

func (instances ClusterInstanceList) ReconfigureTincCluster(log *logging.Logger, newInstances ClusterInstanceList) error

ReconfigureTincCluster creates the tinc configuration on all given instances.

func (ClusterInstanceList) RemoveEtcdMember

func (cil ClusterInstanceList) RemoveEtcdMember(log *logging.Logger, name, clusterIP string) error

RemoveEtcdMember calls etcdctl to remove a member from ETCD on any of the instances in the given list

func (ClusterInstanceList) UpdateClusterMembers

func (instances ClusterInstanceList) UpdateClusterMembers(log *logging.Logger, clusterMembers ClusterMemberList, rebootAfter bool, provider CloudProvider) error

UpdateClusterMembers updates /etc/cluster-members on all instances of the cluster

type ClusterMember

type ClusterMember struct {
	ClusterID     string // ID of the cluster this is a member of (/etc/pulcu/cluster-id)
	MachineID     string // ID of the machine (/etc/machine-id)
	ClusterIP     string // IP address of the instance used for all private communication in the cluster
	PrivateHostIP string // IP address of the host on the private network (can be ClusterIP)
	EtcdProxy     bool   // If set, this member is an ETCD proxy
}

type ClusterMemberList

type ClusterMemberList []ClusterMember

func (ClusterMemberList) Find

func (cml ClusterMemberList) Find(instance ClusterInstance) (ClusterMember, error)

func (ClusterMemberList) Render

func (cml ClusterMemberList) Render() string

type CreateClusterOptions

type CreateClusterOptions struct {
	ClusterInfo
	InstanceConfig
	SSHKeyNames             []string // List of names of SSH keys to install on each instance
	SSHKeyGithubAccount     string   // Github account name used to fetch SSH keys
	RegisterInstance        bool     // If set, the instances will be registered with their instance name in DNS
	InstanceCount           int      // Number of instances to start
	GluonImage              string   // Docker image containing gluon
	RebootStrategy          string
	PrivateRegistryUrl      string // URL of private docker registry
	PrivateRegistryUserName string // Username of private docker registry
	PrivateRegistryPassword string // Password of private docker registry
	VaultAddress            string // URL of the vault
	VaultCertificatePath    string // Path of the vault ca-cert file
	VaultServerKeyPath      string // Path of the vault ca-cert key file
	VaultServerKeyCommand   string // Shell command that outputs a PEM-encoded CA key to use to as the Vault server SSL certificate key
	TincCIDR                string // CIDR for the TINC network inside the cluster (e.g. 192.168.35.0/24)
	HttpProxy               string // Address of the http proxy to use (if any)
	WeavePassword           string // Encryption password of weave network
	EnableFleet             bool   // Install fleet on the cluster
	EnableKubernetes        bool   // Install kubernetes on the cluster
	// contains filtered or unexported fields
}

Options for creating a cluster

func (*CreateClusterOptions) NewCreateInstanceOptions

func (o *CreateClusterOptions) NewCreateInstanceOptions(isCore, isLB bool, instanceIndex int) (CreateInstanceOptions, error)

NewCreateInstanceOptions creates a new CreateInstanceOptions instances with all values inherited from the given CreateClusterOptions

func (CreateClusterOptions) Validate

func (cco CreateClusterOptions) Validate() error

Validate the given options

type CreateInstanceOptions

type CreateInstanceOptions struct {
	ClusterInfo
	InstanceConfig
	ClusterName             string   // Full name of the cluster e.g. "dev1.example.com"
	InstanceName            string   // Name of the instance e.g. "abc123.dev1.example.com"
	InstanceIndex           int      // 0,... used for odd/even metadata
	RegisterInstance        bool     // If set, the instance will be register with its instance name in DNS
	RoleCore                bool     // If set, this instance will get `core=true` metadata
	RoleLoadBalancer        bool     // If set, this instance will get `lb=true` metadata and the instance will be registered under the cluster name in DNS
	RoleVault               bool     // If set, this instance will get `vault=true` metadata and a `vault` role.
	RoleWorker              bool     // If set, this instance will get `worker=true` metadata
	SSHKeyNames             []string // List of names of SSH keys to install
	SSHKeyGithubAccount     string   // Github account name used to fetch SSH keys
	GluonImage              string   // Docker image containing gluon
	GluonEnv                string   // Content of gluon.env
	RebootStrategy          string
	PrivateRegistryUrl      string // URL of private docker registry
	PrivateRegistryUserName string // Username of private docker registry
	PrivateRegistryPassword string // Password of private docker registry
	EtcdProxy               bool   // If set, this instance will be an ETCD proxy
	VaultAddress            string // URL of the vault
	VaultCertificatePath    string // Path of the vault ca-cert file

	VaultServerKeyPath    string // Path of the vault ca-cert key file
	VaultServerKeyCommand string // Shell command that outputs a PEM-encoded CA key to use to as the Vault server SSL certificate key

	TincCIDR  string // CIDR for the TINC network inside the cluster (e.g. 192.168.35.0/24)
	TincIpv4  string // IP addres of tun0 (tinc) on this instance
	HttpProxy string // Address of the http proxy to use (if any)
	WeaveEnv  string // Content of weave.env
	WeaveSeed string // Content of weave-seed
	// contains filtered or unexported fields
}

CreateInstanceOptions contains all options for creating an instance

func (*CreateInstanceOptions) CreateFleetMetadata

func (o *CreateInstanceOptions) CreateFleetMetadata(instanceIndex int) string

CreateFleetMetadata creates a valid fleet metadata string for use in cloud-config

func (*CreateInstanceOptions) NewCloudConfigOptions

func (o *CreateInstanceOptions) NewCloudConfigOptions() CloudConfigOptions

NewCloudConfigOptions creates a new CloudConfigOptions instances with all values inherited from the given CreateInstanceOptions

func (*CreateInstanceOptions) Roles

func (o *CreateInstanceOptions) Roles() string

Roles returns the roles that the instance is supposed to play.

func (*CreateInstanceOptions) SetVaultCertificate

func (o *CreateInstanceOptions) SetVaultCertificate(contents string)

SetVaultCertificate sets the content of the VaultCertificate

func (*CreateInstanceOptions) SetupNames

func (o *CreateInstanceOptions) SetupNames(prefix, clusterName, domain string)

SetupNames configured the ClusterName and InstanceName of the given options using the given cluster & domain name

func (CreateInstanceOptions) Validate

func (cio CreateInstanceOptions) Validate(validateVault, validateWeave bool) error

Validate the given options

func (*CreateInstanceOptions) VaultCertificate

func (o *CreateInstanceOptions) VaultCertificate() (string, error)

VaultCertificate reads the VaultCertificatePath and returns its content as a string

func (*CreateInstanceOptions) VaultServerKey

func (o *CreateInstanceOptions) VaultServerKey() (string, error)

VaultServerKey reads the VaultServerKeyPath or executes the VaultServerKeyCommand and returns its content as a string

type DnsProvider

type DnsProvider interface {
	ShowDomainRecords(domain string) error
	CreateDnsRecord(domain, recordTpe, name, data string) error
	DeleteDnsRecord(domain, recordType, name, data string) error
}

DnsProvider holds all functions to be implemented by DNS providers

type InitialSetupOptions

type InitialSetupOptions struct {
	ClusterMembers   ClusterMemberList
	FleetMetadata    string
	EtcdClusterState string
}

type InstanceConfig

type InstanceConfig struct {
	ImageID      string // ID of the image to install on each instance
	RegionID     string // ID of the region to run all instances in
	TypeID       string // ID of the type of each instance
	MinOSVersion string
	NoPublicIPv4 bool // If set, this instance will be created without a public IPv4 address
}

func (InstanceConfig) String

func (ic InstanceConfig) String() string

func (InstanceConfig) Validate

func (ic InstanceConfig) Validate() error

Validate the given options

type InstanceConnection

type InstanceConnection interface {
	SSHClient

	// Sync the filesystems on the instance
	Sync(log *logging.Logger) error

	// Exec executes a command on the instance
	Exec(log *logging.Logger, command string) (string, error)

	// EnableService calls `systemctl enable <name>`
	EnableService(log *logging.Logger, name string) error
	// RunScript uploads a script with given content and executes it
	RunScript(log *logging.Logger, scriptContent, scriptPath string) error

	GetClusterID(log *logging.Logger) (string, error)

	GetGluonEnv(log *logging.Logger) (string, error)

	GetMachineID(log *logging.Logger) (string, error)

	GetVaultCrt(log *logging.Logger) (string, error)

	GetVaultAddr(log *logging.Logger) (string, error)

	GetWeaveEnv(log *logging.Logger) (string, error)

	GetWeaveSeed(log *logging.Logger) (string, error)

	GetOSRelease(log *logging.Logger) (semver.Version, error)

	// IsEtcdProxyFromService queries the ETCD2 service on the instance to look for an ETCD_PROXY variable.
	IsEtcdProxyFromService(log *logging.Logger) (bool, error)

	// AddEtcdMember calls etcdctl to add a member to ETCD
	AddEtcdMember(log *logging.Logger, name, clusterIP string) error

	// RemoveEtcdMember calls etcdctl to remove a member from ETCD
	RemoveEtcdMember(log *logging.Logger, name, clusterIP string) error
}

func SSHConnect

func SSHConnect(userName, host string) (InstanceConnection, error)

SSHConnect creates a new SSH connection to the given user on the given host.

type OSName

type OSName string

OSName specifies a name of an OS

const (
	OSNameCoreOS OSName = "coreos"
	OSNameUbuntu OSName = "ubuntu"
)

type SSHClient

type SSHClient interface {
	io.Closer
	Run(log *logging.Logger, command, stdin string, quiet bool) (string, error)
}

func DialSSH

func DialSSH(userName, host string) (SSHClient, error)

DialSSH creates a new SSH connection to the given user on the given host.

type VaultProvider

type VaultProvider interface {
	AddMachine(clusterId, machineId string) error
	RemoveMachine(machineId string) error
}

func NewVaultProvider

func NewVaultProvider(log *logging.Logger, config VaultProviderConfig) (VaultProvider, error)

type VaultProviderConfig

type VaultProviderConfig struct {
	VaultAddr         string // URL of the vault
	VaultCACert       string // Path to a PEM-encoded CA cert file to use to verify the Vault server SSL certificate
	VaultCAKey        string // Path to a PEM-encoded CA key file to use to verify the Vault server SSL certificate (vault servers only)
	VaultCAKeyCommand string // Shell command that outputs a PEM-encoded CA key to use to as the Vault server SSL certificate key
	VaultCAPath       string // Path to a directory of PEM-encoded CA cert files to verify the Vault server SSL certificate
	GithubToken       string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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