cloud

package
v0.0.0-...-7759ae7 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2018 License: Apache-2.0 Imports: 58 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RetryInterval = 5 * time.Second
	RetryTimeout  = 15 * time.Minute
)

Variables

View Source
var (
	ErrNotFound       = errors.New("node not found")
	ErrNotImplemented = errors.New("not implemented")
	ErrNoMasterNG     = errors.New("cluster has no master NodeGroup")
)
View Source
var (
	// TokenIDRegexpString defines token's id regular expression pattern
	TokenIDRegexpString = "^([a-z0-9]{6})$"
	// TokenIDRegexp is a compiled regular expression of TokenIDRegexpString
	TokenIDRegexp = regexp.MustCompile(TokenIDRegexpString)
	// TokenRegexpString defines id.secret regular expression pattern
	TokenRegexpString = "^([a-z0-9]{6})\\.([a-z0-9]{16})$"
	// TokenRegexp is a compiled regular expression of TokenRegexpString
	TokenRegexp = regexp.MustCompile(TokenRegexpString)
)
View Source
var DefaultWriter = &StringWriter{
	data: make([]byte, 0),
}
View Source
var (
	StartupScriptTemplate = template.Must(template.New(api.RoleMaster).Parse(`
{{- template "init-script" }}

# kill apt processes (E: Unable to lock directory /var/lib/apt/lists/)
kill $(ps aux | grep '[a]pt' | awk '{print $2}') || true

{{ template "init-os" . }}

# https://major.io/2016/05/05/preventing-ubuntu-16-04-starting-daemons-package-installed/
echo -e '#!/bin/bash\nexit 101' > /usr/sbin/policy-rc.d
chmod +x /usr/sbin/policy-rc.d

apt-get update -y
apt-get install -y apt-transport-https curl ca-certificates software-properties-common tzdata
curl -fsSL --retry 5 https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
echo 'deb http://apt.kubernetes.io/ kubernetes-xenial main' > /etc/apt/sources.list.d/kubernetes.list
exec_until_success 'add-apt-repository -y ppa:gluster/glusterfs-3.10'
apt-get update -y
exec_until_success 'apt-get install -y {{ .PackageList }}'
{{ if .UseForkedKubeadm_1_8_3 }}
curl -fsSL --retry 5 -o kubeadm	https://github.com/appscode/kubernetes/releases/download/v1.8.3/kubeadm \
	&& chmod +x kubeadm \
	&& mv kubeadm /usr/bin/
{{ end }}

curl -fsSL --retry 5 -o pre-k https://cdn.appscode.com/binaries/pre-k/{{ .PrekVersion }}/pre-k-linux-amd64 \
	&& chmod +x pre-k \
	&& mv pre-k /usr/bin/

timedatectl set-timezone Etc/UTC
{{ template "prepare-host" . }}
{{ template "mount-master-pd" . }}


rm -rf /usr/sbin/policy-rc.d
systemctl enable docker kubelet nfs-utils
systemctl start docker kubelet nfs-utils

kubeadm reset {{ .ForceKubeadmResetFlag }}

{{ template "setup-certs" . }}

mkdir -p /etc/kubernetes/ccm
{{ if .CloudConfig }}
cat > /etc/kubernetes/ccm/cloud-config <<EOF
{{ .CloudConfig }}
EOF
{{ end }}

mkdir -p /etc/kubernetes/kubeadm



{{ template "pre-k" . }}

kubeadm init --config=/etc/kubernetes/kubeadm/config.yaml --skip-token-print

{{ if .UseKubeProxy1_11_0 }}
kubectl apply -f https://raw.githubusercontent.com/pharmer/addons/release-1.11/kube-proxy/v1.11.0/kube-proxy.yaml \
  --kubeconfig /etc/kubernetes/admin.conf
{{ end }}

{{ if eq .NetworkProvider "flannel" }}
{{ template "flannel" . }}
{{ else if eq .NetworkProvider "calico" }}
{{ template "calico" . }}
{{ else if eq .NetworkProvider "weavenet" }}
{{ template "weavenet" . }}
{{ end }}

kubectl apply \
  -f https://raw.githubusercontent.com/pharmer/addons/release-1.11/kubeadm-probe/installer.yaml \
  --kubeconfig /etc/kubernetes/admin.conf

mkdir -p ~/.kube
sudo cp -i /etc/kubernetes/admin.conf ~/.kube/config
sudo chown $(id -u):$(id -g) ~/.kube/config


{{ if .ExternalProvider }}
{{ template "ccm" . }}
{{ template "install-storage-plugin" . }}
{{end}}

{{ template "prepare-cluster" . }}
`))
)

Functions

func Apply

func Apply(ctx context.Context, opts *options.ApplyConfig) ([]api.Action, error)

func CACert

func CACert(ctx context.Context) *x509.Certificate

func CAKey

func CAKey(ctx context.Context) *rsa.PrivateKey

func CheckForUpdates

func CheckForUpdates(ctx context.Context, name string) (string, error)

func CloudManagers

func CloudManagers() []string

CloudManagers returns the name of all registered cloud providers in a string slice

func ConvertClusterConfigFromV1beta1ToV1alpha3

func ConvertClusterConfigFromV1beta1ToV1alpha3(conf *v1beta1.ClusterConfiguration) *v1alpha3.ClusterConfiguration

func ConvertInitConfigFromV1bet1ToV1alpha3

func ConvertInitConfigFromV1bet1ToV1alpha3(conf *v1beta1.InitConfiguration) *v1alpha3.InitConfiguration

func ConvertJoinConfigFromV1beta1ToV1alpha3

func ConvertJoinConfigFromV1beta1ToV1alpha3(conf *v1beta1.JoinConfiguration) *v1alpha3.JoinConfiguration

func Create

func Create(ctx context.Context, cluster *api.Cluster) (*api.Cluster, error)

func CreateAdminCertificate

func CreateAdminCertificate(ctx context.Context) (*x509.Certificate, *rsa.PrivateKey, error)

func CreateCACertificates

func CreateCACertificates(ctx context.Context, cluster *api.Cluster) (context.Context, error)

func CreateCredentialSecret

func CreateCredentialSecret(ctx context.Context, client kubernetes.Interface, cluster *api.Cluster) error

func CreateNodeGroup

func CreateNodeGroup(ctx context.Context, cluster *api.Cluster, role, sku string, nodeType api.NodeType, count int, spotPriceMax float64) error

func CreateSSHKey

func CreateSSHKey(ctx context.Context, cluster *api.Cluster) (context.Context, error)

func CreateValidKubeadmToken

func CreateValidKubeadmToken(kc kubernetes.Interface, duration time.Duration) (string, error)

func Delete

func Delete(ctx context.Context, name string) (*api.Cluster, error)

func DeleteClusterInstance

func DeleteClusterInstance(ctx context.Context, cluster *api.Cluster, node string) error

Deprecated

func DeleteClusterInstance2

func DeleteClusterInstance2(kc kubernetes.Interface, node string) error

func DeleteDyanamicVolumes

func DeleteDyanamicVolumes(client kubernetes.Interface) error

func DeleteLoadBalancers

func DeleteLoadBalancers(client kubernetes.Interface) error

func DeleteNG

func DeleteNG(ctx context.Context, clusterName, nodeGroupName string) error

func Env

func ExecuteSSHCommand

func ExecuteSSHCommand(name string, arg []string, stdIn io.Reader) (string, error)

func ExecuteTCPCommand

func ExecuteTCPCommand(command, addr string, config *ssh.ClientConfig) (string, error)

func FetchFromURL

func FetchFromURL(url string) (string, error)

Internal helper: return content of URL

func FindMasterNodeGroup

func FindMasterNodeGroup(nodeGroups []*api.NodeGroup) (*api.NodeGroup, error)

func FrontProxyCACert

func FrontProxyCACert(ctx context.Context) *x509.Certificate

func FrontProxyCAKey

func FrontProxyCAKey(ctx context.Context) *rsa.PrivateKey

func Get

func Get(ctx context.Context, name string) (*api.Cluster, error)

func GetAdminCertificate

func GetAdminCertificate(ctx context.Context, cluster *api.Cluster) (*x509.Certificate, *rsa.PrivateKey, error)

func GetAdminConfig

func GetAdminConfig(ctx context.Context, cluster *api.Cluster) (*api.KubeConfig, error)

func GetClusterIstance

func GetClusterIstance(ctx context.Context, cluster *api.Cluster, nodeGroup string) ([]string, error)

Deprecated

func GetClusterIstance2

func GetClusterIstance2(kc kubernetes.Interface, nodeGroup string) ([]string, error)

func GetExistingContextVersion

func GetExistingContextVersion(ctx context.Context, cluster *api.Cluster, sku string) (int64, error)

func GetExistingKubeadmToken

func GetExistingKubeadmToken(kc kubernetes.Interface, duration time.Duration) (string, error)

func GetKubeadmToken

func GetKubeadmToken() string

func GetLatestKubeadmVerson

func GetLatestKubeadmVerson() (string, error)

func GetSSHConfig

func GetSSHConfig(ctx context.Context, nodeName string, cluster *api.Cluster) (*api.SSHConfig, error)

func HasNoUserApps

func HasNoUserApps(client kubernetes.Interface) (bool, error)

func IsCloudManager

func IsCloudManager(name string) bool

IsCloudManager returns true if name corresponds to an already registered cloud provider.

func KubernetesReleaseVersion

func KubernetesReleaseVersion(version string) (string, error)

KubernetesReleaseVersion is helper function that can fetch available version information from release servers based on label names, like "stable" or "latest".

If argument is already semantic version string, it will return same string.

In case of labels, it tries to fetch from release servers and then return actual semantic version.

Available names on release servers:

stable      (latest stable release)
stable-1    (latest stable release in 1.x)
stable-1.0  (and similarly 1.1, 1.2, 1.3, ...)
latest      (latest release, including alpha/beta)
latest-1    (latest release in 1.x, including alpha/beta)
latest-1.0  (and similarly 1.1, 1.2, 1.3, ...)

func List

func List(ctx context.Context, opts metav1.ListOptions) ([]*api.Cluster, error)

func LoadCACertificates

func LoadCACertificates(ctx context.Context, cluster *api.Cluster) (context.Context, error)

func LoadSSHKey

func LoadSSHKey(ctx context.Context, cluster *api.Cluster) (context.Context, error)

func Logger

func Logger(ctx context.Context) api.Logger

func Mutator

func Mutator(ctx context.Context, cluster *api.Cluster, expectedInstance Instance, nodeGroup string) (int64, error)

func NameGenerator

func NameGenerator(ctx context.Context) api.NameGenerator

func NewAdminClient

func NewAdminClient(ctx context.Context, cluster *api.Cluster) (kubernetes.Interface, error)

WARNING: Returned KubeClient uses admin client cert. This should only be used for cluster provisioning operations.

func NewContext

func NewContext(parent context.Context, cfg *api.PharmerConfig, env _env.Environment) context.Context

func NewStoreProvider

func NewStoreProvider(ctx context.Context, cfg *api.PharmerConfig) store.Interface

func NewStringReader

func NewStringReader(ss []string) io.Reader

func NodeCount

func NodeCount(nodeGroups []*api.NodeGroup) int64

func ParseToken

func ParseToken(s string) (string, string, error)

func RandStringRunes

func RandStringRunes(n int) string

func ReadFileAs

func ReadFileAs(path string, obj interface{}) error

func RegisterCloudManager

func RegisterCloudManager(name string, cloud Factory)

RegisterCloudManager registers a cloud.Factory by name. This is expected to happen during app startup.

func SSHKey

func SSHKey(ctx context.Context) *ssh.SSHKey

func Store

func Store(ctx context.Context) store.Interface

func UpdateSpec

func UpdateSpec(ctx context.Context, cluster *api.Cluster) (*api.Cluster, error)

func WaitForReadyMaster

func WaitForReadyMaster(ctx context.Context, client kubernetes.Interface) error

func WaitForReadyMasterVersion

func WaitForReadyMasterVersion(ctx context.Context, client kubernetes.Interface, desiredVersion *semver.Version) error

func WithEnv

func WithEnv(parent context.Context, v _env.Environment) context.Context

func WithLogger

func WithLogger(parent context.Context, v api.Logger) context.Context

func WithNameGenerator

func WithNameGenerator(parent context.Context, v api.NameGenerator) context.Context

func WithStore

func WithStore(parent context.Context, v store.Interface) context.Context

Types

type Factory

type Factory func(ctx context.Context) (Interface, error)

Factory is a function that returns a cloud.ClusterManager. The config parameter provides an io.Reader handler to the factory in order to load specific configurations. If no configuration is provided the parameter is nil.

type GenericNodeGroupManager

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

func (*GenericNodeGroupManager) AddNodes

func (igm *GenericNodeGroupManager) AddNodes(count int64) error

func (*GenericNodeGroupManager) Apply

func (igm *GenericNodeGroupManager) Apply(dryRun bool) (acts []api.Action, err error)

func (*GenericNodeGroupManager) DeleteNodes

func (igm *GenericNodeGroupManager) DeleteNodes(nodes []core.Node) error

type GenericUpgradeManager

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

func (*GenericUpgradeManager) Apply

func (upm *GenericUpgradeManager) Apply(dryRun bool) (acts []api.Action, err error)

func (*GenericUpgradeManager) ExecuteSSHCommand

func (upm *GenericUpgradeManager) ExecuteSSHCommand(command string, node *core.Node) (string, error)

func (*GenericUpgradeManager) GetAvailableUpgrades

func (upm *GenericUpgradeManager) GetAvailableUpgrades() ([]*api.Upgrade, error)

func (*GenericUpgradeManager) MasterUpgrade

func (upm *GenericUpgradeManager) MasterUpgrade() error

func (*GenericUpgradeManager) NodeGroupUpgrade

func (upm *GenericUpgradeManager) NodeGroupUpgrade(ng *api.NodeGroup) (err error)

func (*GenericUpgradeManager) PrintAvailableUpgrades

func (upm *GenericUpgradeManager) PrintAvailableUpgrades(upgrades []*api.Upgrade)

printAvailableUpgrades prints a UX-friendly overview of what versions are available to upgrade to TODO look into columnize or some other formatter when time permits instead of using the tabwriter

type GroupStats

type GroupStats struct {
	Count int64
	Extra interface{}
}

type HookFunc

type HookFunc func() error

type Instance

type Instance struct {
	Type  InstanceType
	Stats GroupStats
}

type InstanceController

type InstanceController struct {
	Client kubernetes.Interface
}

type InstanceManager

type InstanceManager interface {
	CreateInstance(name, token string, ng *api.NodeGroup) (*api.NodeInfo, error)
	DeleteInstanceByProviderID(providerID string) error
}

type InstanceType

type InstanceType struct {
	ContextVersion int64
	Sku            string
	SpotInstance   bool
	Master         bool
	DiskType       string
	DiskSize       int64
}

func (*InstanceType) String

func (t *InstanceType) String() string

type Interface

type Interface interface {
	SSHGetter
	ProviderKubeConfig
	GetDefaultNodeSpec(cluster *api.Cluster, sku string) (api.NodeSpec, error)
	SetDefaults(in *api.Cluster) error
	Apply(in *api.Cluster, dryRun bool) ([]api.Action, error)
	IsValid(cluster *api.Cluster) (bool, error)
}

func GetCloudManager

func GetCloudManager(name string, ctx context.Context) (Interface, error)

GetCloudManager creates an instance of the named cloud provider, or nil if the name is not known. The error return is only used if the named provider was known but failed to initialize. The config parameter specifies the io.Reader handler of the configuration file for the cloud provider, or nil for no configuation.

type KubeVersionGetter

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

KubeVersionGetter handles the version-fetching mechanism from external sources

func (*KubeVersionGetter) ClusterVersion

func (g *KubeVersionGetter) ClusterVersion() (string, *versionutil.Version, error)

ClusterVersion gets API server version

func (*KubeVersionGetter) DeployedDNSAddon

func (g *KubeVersionGetter) DeployedDNSAddon() (string, string, error)

DeployedDNSAddon returns the type of DNS addon currently deployed

func (*KubeVersionGetter) IsUpgradeRequested

func (g *KubeVersionGetter) IsUpgradeRequested() (bool, error)

IsUpgradeRequested returns true if cluster.spec.kubernetesVersion is different from version reported from cluster.

func (*KubeVersionGetter) KubeadmVersion

func (g *KubeVersionGetter) KubeadmVersion() (string, *versionutil.Version, error)

MasterKubeadmVersion gets kubeadm version

func (*KubeVersionGetter) KubeletVersions

func (g *KubeVersionGetter) KubeletVersions() (map[string]uint32, error)

KubeletVersions gets the versions of the kubelets in the cluster

func (*KubeVersionGetter) VersionFromCILabel

func (g *KubeVersionGetter) VersionFromCILabel(ciVersionLabel, description string) (string, *versionutil.Version, error)

VersionFromCILabel resolves a version label like "latest" or "stable" to an actual version using the public Kubernetes CI uploads

type NodeDrain

type NodeDrain struct {
	Node string
	// contains filtered or unexported fields
}

func NewNodeDrain

func NewNodeDrain(ctx context.Context, kc kubernetes.Interface, cluster *api.Cluster) (NodeDrain, error)

func (*NodeDrain) Apply

func (nd *NodeDrain) Apply() error

func (*NodeDrain) DeleteNode

func (nd *NodeDrain) DeleteNode() error

type NodeGroupManager

type NodeGroupManager interface {
	Apply(dryRun bool) (acts []api.Action, err error)
	AddNodes(count int64) error
	DeleteNodes(nodes []core.Node) error
}

func NewNodeGroupManager

func NewNodeGroupManager(ctx context.Context, ng *api.NodeGroup, im InstanceManager, kc kubernetes.Interface, cluster *api.Cluster, token string, initHook HookFunc, gcHook HookFunc) NodeGroupManager

type ProviderKubeConfig

type ProviderKubeConfig interface {
	GetKubeConfig(cluster *api.Cluster) (*api.KubeConfig, error)
}

type SSHGetter

type SSHGetter interface {
	GetSSHConfig(cluster *api.Cluster, node *core.Node) (*api.SSHConfig, error)
}

type StringWriter

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

func (*StringWriter) Flush

func (s *StringWriter) Flush()

func (*StringWriter) Output

func (s *StringWriter) Output() string

func (*StringWriter) Write

func (s *StringWriter) Write(b []byte) (int, error)

type TemplateData

type TemplateData struct {
	ClusterName       string
	KubernetesVersion string
	KubeadmToken      string
	CloudCredential   map[string]string
	CAHash            string
	CAKey             string
	FrontProxyKey     string
	APIServerAddress  string
	NetworkProvider   string
	CloudConfig       string
	Provider          string
	NodeName          string
	ExternalProvider  bool

	InitConfiguration    *kubeadmapi.InitConfiguration
	ClusterConfiguration *kubeadmapi.ClusterConfiguration
	JoinConfiguration    *kubeadmapi.JoinConfiguration
	KubeletExtraArgs     map[string]string
}

func (TemplateData) ClusterConfigurationYAML

func (td TemplateData) ClusterConfigurationYAML() (string, error)

func (TemplateData) ForceKubeadmResetFlag

func (td TemplateData) ForceKubeadmResetFlag() (string, error)

func (TemplateData) InitConfigurationYAML

func (td TemplateData) InitConfigurationYAML() (string, error)

func (TemplateData) IsKubeadmV1Alpha3

func (td TemplateData) IsKubeadmV1Alpha3() bool

func (TemplateData) IsVersionLessThan

func (td TemplateData) IsVersionLessThan(currentVersion string) bool

func (TemplateData) IsVersionLessThan1_11

func (td TemplateData) IsVersionLessThan1_11() bool

func (TemplateData) IsVersionLessThan1_13

func (td TemplateData) IsVersionLessThan1_13() bool

func (TemplateData) JoinConfigurationYAML

func (td TemplateData) JoinConfigurationYAML() (string, error)

func (TemplateData) KubeletExtraArgsStr

func (td TemplateData) KubeletExtraArgsStr() string

func (TemplateData) PackageList

func (td TemplateData) PackageList() (string, error)

func (TemplateData) PrekVersion

func (td TemplateData) PrekVersion() (string, error)

func (TemplateData) UseForkedKubeadm_1_8_3

func (td TemplateData) UseForkedKubeadm_1_8_3() bool

Forked kubeadm 1.8.x for: https://github.com/kubernetes/kubernetes/pull/49840

func (TemplateData) UseKubeProxy1_11_0

func (td TemplateData) UseKubeProxy1_11_0() bool

type UpgradeManager

type UpgradeManager interface {
	GetAvailableUpgrades() ([]*api.Upgrade, error)
	PrintAvailableUpgrades([]*api.Upgrade)
	Apply(dryRun bool) ([]api.Action, error)
	MasterUpgrade() error
	NodeGroupUpgrade(ng *api.NodeGroup) error
}

func NewUpgradeManager

func NewUpgradeManager(ctx context.Context, ssh SSHGetter, kc kubernetes.Interface, cluster *api.Cluster) UpgradeManager

type VersionGetter

type VersionGetter interface {
	// IsUpgradeRequested returns true if cluster.spec.kubernetesVersion is different from version reported from cluster.
	IsUpgradeRequested() (bool, error)
	// ClusterVersion should return the version of the cluster i.e. the API Server version
	ClusterVersion() (string, *versionutil.Version, error)
	// MasterKubeadmVersion should return the version of the kubeadm CLI
	KubeadmVersion() (string, *versionutil.Version, error)
	// GetKubeDNSVersion returns the right kube-dns version for a specific k8s version
	DeployedDNSAddon() (string, string, error)
	// VersionFromCILabel should resolve CI labels like `latest`, `stable`, `stable-1.8`, etc. to real versions
	VersionFromCILabel(string, string) (string, *versionutil.Version, error)
	// KubeletVersions should return a map with a version and a number that describes how many kubelets there are for that version
	KubeletVersions() (map[string]uint32, error)
}

Easy to implement a fake variant of this interface for unit testing

func NewKubeVersionGetter

func NewKubeVersionGetter(client kubernetes.Interface, cluster *api.Cluster) VersionGetter

NewKubeVersionGetter returns a new instance of KubeVersionGetter

Directories

Path Synopsis
aks
aws
eks
gce
gke
ovh

Jump to

Keyboard shortcuts

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