cloud

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2019 License: Apache-2.0 Imports: 56 Imported by: 0

Documentation

Overview

Copyright The Pharmer Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright The Pharmer Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright The Pharmer Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright The Pharmer Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright The Pharmer Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright The Pharmer Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright The Pharmer Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright The Pharmer Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright The Pharmer Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright The Pharmer Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright The Pharmer Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright The Pharmer Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright The Pharmer Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright The Pharmer Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

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 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

{{- template "install-docker-script" }}

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 }}'

curl -fsSL --retry 5 -o pre-k {{ .PrekVersion }} \
	&& 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 -f

{{ template "setup-certs" . }}

{{ template "cloud-config" . }}

mkdir -p /etc/kubernetes/kubeadm



{{ template "pre-k" . }}

{{ if not .ControlPlaneJoin }}
kubeadm init --config=/etc/kubernetes/kubeadm/config.yaml --skip-token-print
{{ else }}

cat > /etc/kubernetes/kubeadm/join.yaml <<EOF
{{ .JoinConfiguration }}
EOF

PUBLIC_IP=$(pre-k machine public-ips --all=false)
echo $PUBLIC_IP
sed -i "s/CONTROLPLANEIP/$PUBLIC_IP/g" /etc/kubernetes/kubeadm/join.yaml
cat /etc/kubernetes/kubeadm/join.yaml

kubeadm join --config=/etc/kubernetes/kubeadm/join.yaml

{{ 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.13.1/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

kubectl apply \
  -f https://raw.githubusercontent.com/pharmer/addons/clusterapi/cluster-api/cluster-crd.yaml \
  --kubeconfig /etc/kubernetes/admin.conf

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

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

Functions

func Apply

func Apply(scope *Scope) error

func ApplyCreate

func ApplyCreate(scope *Scope) error

func ApplyDelete

func ApplyDelete(s *Scope) error

func ApplyScale

func ApplyScale(s *Scope) error

func ApplyUpgrade

func ApplyUpgrade(s *Scope) error

func CreateCluster

func CreateCluster(s *Scope) error

func CreateMachineSets

func CreateMachineSets(store store.ResourceInterface, opts *options.NodeGroupCreateConfig) error

func Delete

func Delete(clusterStore store.ClusterStore, name string) (*api.Cluster, 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 GenerateMachineSetName

func GenerateMachineSetName(sku string) string

TODO: move

func GetDefaultKubeadmClusterConfig

func GetDefaultKubeadmClusterConfig(cluster *api.Cluster, hostPath *kubeadmapi.HostPathMount) *kubeadmapi.ClusterConfiguration

func GetSSHConfig

func GetSSHConfig(storeProvider store.ResourceInterface, clusterName, nodeName string) (*api.SSHConfig, error)

func KubeConfigPath

func KubeConfigPath() string

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 MachineControllerImage

func MachineControllerImage() 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 RenderStartupScript

func RenderStartupScript(cm Interface, machine *clusterapi.Machine, token, customTemplate string) (string, error)

func UseCluster

func UseCluster(opts *options.ClusterUseConfig, konf *api.KubeConfig) error

Types

type CloudManagerInterface

type CloudManagerInterface interface {
	GetCluster() *api.Cluster
	GetCaCertPair() *certificates.CertKeyPair
	GetCertificates() *certificates.Certificates
	GetCredential() (*cloudapi.Credential, error)

	GetAdminClient() (kubernetes.Interface, error)
	GetCloudManager() (Interface, error)
}

type ClusterAPI

type ClusterAPI struct {
	*Scope
	// contains filtered or unexported fields
}

func NewClusterAPI

func NewClusterAPI(s *Scope, namespace string) (*ClusterAPI, error)

func (*ClusterAPI) Apply

func (ca *ClusterAPI) Apply(controllerManager string) error

func (*ClusterAPI) CreateAPIServerAndController

func (ca *ClusterAPI) CreateAPIServerAndController(controllerManager string) error

func (*ClusterAPI) CreateMachineController

func (ca *ClusterAPI) CreateMachineController(controllerManager string) error

func (*ClusterAPI) CreatePharmerSecret

func (ca *ClusterAPI) CreatePharmerSecret() error

type Factory

type Factory func(scope *Scope) Interface

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 GenericUpgradeManager

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

func (*GenericUpgradeManager) Apply

func (upm *GenericUpgradeManager) Apply() error

func (*GenericUpgradeManager) ExecuteSSHCommand

func (upm *GenericUpgradeManager) ExecuteSSHCommand(command string, machine *clusterapi.Machine) (string, error)

func (*GenericUpgradeManager) GetAvailableUpgrades

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

func (*GenericUpgradeManager) MasterUpgrade

func (upm *GenericUpgradeManager) MasterUpgrade(oldMachine *clusterapi.Machine, newMachine *clusterapi.Machine) error

func (*GenericUpgradeManager) NodeUpgrade

func (upm *GenericUpgradeManager) NodeUpgrade(oldMachine *clusterapi.Machine, newMachine *clusterapi.Machine) (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 HookFunc

type HookFunc func() error

type Interface

type Interface interface {
	CloudManagerInterface

	CreateCredentials(kc kubernetes.Interface) error

	AddToManager(m manager.Manager) error

	ProviderKubeConfig

	SetCloudConnector() error

	ApplyDelete() error
	// only managed providers
	ApplyScale() error
	SetDefaultCluster() error
	GetDefaultMachineProviderSpec(sku string, role api.MachineRole) (clusterapi.ProviderSpec, error)

	NewMasterTemplateData(machine *clusterapi.Machine, token string, td TemplateData) TemplateData
	NewNodeTemplateData(machine *clusterapi.Machine, token string, td TemplateData) TemplateData

	PrepareCloud() error
	EnsureMaster(machine *clusterapi.Machine) error

	GetMasterSKU(totalNodes int32) string

	GetClusterAPIComponents() (string, error)
}

func GetCloudManager

func GetCloudManager(s *Scope) (Interface, error)

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 NewScopeParams

type NewScopeParams struct {
	Cluster       *api.Cluster
	Certs         *certificates.Certificates
	StoreProvider store.ResourceInterface
	Logger        logr.Logger
}

type ProviderKubeConfig

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

type Scope

type Scope struct {
	Cluster        *api.Cluster
	Certs          *certificates.Certificates
	CredentialData map[string]string
	StoreProvider  store.ResourceInterface
	CloudManager   Interface
	AdminClient    kubernetes.Interface
	logr.Logger
}

func NewScope

func NewScope(params NewScopeParams) *Scope

func (*Scope) GetAdminClient

func (s *Scope) GetAdminClient() (kubernetes.Interface, error)

func (*Scope) GetCaCertPair

func (s *Scope) GetCaCertPair() *certificates.CertKeyPair

func (*Scope) GetCertificates

func (s *Scope) GetCertificates() *certificates.Certificates

func (*Scope) GetCloudManager

func (s *Scope) GetCloudManager() (Interface, error)

func (*Scope) GetCluster

func (s *Scope) GetCluster() *api.Cluster

func (*Scope) GetCredential

func (s *Scope) GetCredential() (*cloudapi.Credential, 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
	SAKey             string
	ETCDCAKey         string
	APIServerAddress  string
	NetworkProvider   string
	CloudConfig       string
	Provider          string
	NodeName          string
	ExternalProvider  bool

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

func NewMasterTemplateData

func NewMasterTemplateData(cm Interface, machine *clusterapi.Machine, token string) TemplateData

func NewNodeTemplateData

func NewNodeTemplateData(cm Interface, machine *clusterapi.Machine, token string) TemplateData

func (TemplateData) ClusterConfigurationYAML

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

func (TemplateData) InitConfigurationYAML

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

func (TemplateData) IsVersionLessThan

func (td TemplateData) IsVersionLessThan(currentVersion string) bool

func (TemplateData) JoinConfigurationYAML

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

func (TemplateData) PackageList

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

func (TemplateData) PrekVersion

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

type UpgradeManager

type UpgradeManager interface {
	GetAvailableUpgrades() ([]*api.Upgrade, error)
	PrintAvailableUpgrades([]*api.Upgrade)
	Apply() error
	MasterUpgrade(oldMachine *clusterapi.Machine, newMachine *clusterapi.Machine) error
	NodeUpgrade(oldMachine *clusterapi.Machine, newMachine *clusterapi.Machine) error
}

func NewUpgradeManager

func NewUpgradeManager(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
utils

Jump to

Keyboard shortcuts

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