Documentation ¶
Index ¶
- Constants
- Variables
- func Apply(scope *Scope) error
- func ApplyCreate(scope *Scope) error
- func ApplyDelete(s *Scope) error
- func ApplyScale(s *Scope) error
- func ApplyUpgrade(s *Scope) error
- func CreateCluster(s *Scope) error
- func CreateMachineSets(store store.ResourceInterface, opts *options.NodeGroupCreateConfig) error
- func Delete(clusterStore store.ClusterStore, name string) (*api.Cluster, error)
- func ExecuteTCPCommand(command, addr string, config *ssh.ClientConfig) (string, error)
- func FetchFromURL(url string) (string, error)
- func GenerateMachineSetName(sku string) string
- func GetDefaultKubeadmClusterConfig(cluster *api.Cluster, hostPath *kubeadmapi.HostPathMount) *kubeadmapi.ClusterConfiguration
- func GetSSHConfig(storeProvider store.ResourceInterface, clusterName, nodeName string) (*api.SSHConfig, error)
- func KubeConfigPath() string
- func KubernetesReleaseVersion(version string) (string, error)
- func ReadFileAs(path string, obj interface{}) error
- func RegisterCloudManager(name string, cloud Factory)
- func RenderStartupScript(cm Interface, machine *clusterapi.Machine, token, customTemplate string) (string, error)
- func UseCluster(opts *options.ClusterUseConfig, konf *api.KubeConfig) error
- type CloudManagerInterface
- type ClusterAPI
- type Factory
- type GenericUpgradeManager
- func (upm *GenericUpgradeManager) Apply() error
- func (upm *GenericUpgradeManager) ExecuteSSHCommand(command string, machine *clusterv1.Machine) (string, error)
- func (upm *GenericUpgradeManager) GetAvailableUpgrades() ([]*api.Upgrade, error)
- func (upm *GenericUpgradeManager) MasterUpgrade(oldMachine *clusterv1.Machine, newMachine *clusterv1.Machine) error
- func (upm *GenericUpgradeManager) NodeUpgrade(oldMachine *clusterv1.Machine, newMachine *clusterv1.Machine) (err error)
- func (upm *GenericUpgradeManager) PrintAvailableUpgrades(upgrades []*api.Upgrade)
- type HookFunc
- type Interface
- type KubeVersionGetter
- func (g *KubeVersionGetter) ClusterVersion() (string, *versionutil.Version, error)
- func (g *KubeVersionGetter) DeployedDNSAddon() (string, string, error)
- func (g *KubeVersionGetter) IsUpgradeRequested() (bool, error)
- func (g *KubeVersionGetter) KubeadmVersion() (string, *versionutil.Version, error)
- func (g *KubeVersionGetter) KubeletVersions() (map[string]uint32, error)
- func (g *KubeVersionGetter) VersionFromCILabel(ciVersionLabel, description string) (string, *versionutil.Version, error)
- type NewScopeParams
- type ProviderKubeConfig
- type Scope
- func (s *Scope) GetAdminClient() (kubernetes.Interface, error)
- func (s *Scope) GetCaCertPair() *certificates.CertKeyPair
- func (s *Scope) GetCertificates() *certificates.Certificates
- func (s *Scope) GetCloudManager() (Interface, error)
- func (s *Scope) GetCluster() *api.Cluster
- func (s *Scope) GetCredential() (*cloudapi.Credential, error)
- type StringWriter
- type TemplateData
- func (td TemplateData) ClusterConfigurationYAML() (string, error)
- func (td TemplateData) InitConfigurationYAML() (string, error)
- func (td TemplateData) IsVersionLessThan(currentVersion string) bool
- func (td TemplateData) JoinConfigurationYAML() (string, error)
- func (td TemplateData) PackageList() (string, error)
- func (td TemplateData) PrekVersion() (string, error)
- type UpgradeManager
- type VersionGetter
Constants ¶
const (
MachineControllerImage = "pharmer/machine-controller:0.3.0"
)
Variables ¶
var ( ErrNotFound = errors.New("node not found") ErrNotImplemented = errors.New("not implemented") ErrNoMasterNG = errors.New("Cluster has no master NodeGroup") )
var DefaultWriter = &StringWriter{ data: make([]byte, 0), }
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 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 -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 ApplyCreate ¶
func ApplyDelete ¶
func ApplyScale ¶
func ApplyUpgrade ¶
func CreateCluster ¶
func CreateMachineSets ¶
func CreateMachineSets(store store.ResourceInterface, opts *options.NodeGroupCreateConfig) error
func ExecuteTCPCommand ¶
func ExecuteTCPCommand(command, addr string, config *ssh.ClientConfig) (string, error)
func FetchFromURL ¶
Internal helper: return content of URL
func GetDefaultKubeadmClusterConfig ¶
func GetDefaultKubeadmClusterConfig(cluster *api.Cluster, hostPath *kubeadmapi.HostPathMount) *kubeadmapi.ClusterConfiguration
func GetSSHConfig ¶
func KubeConfigPath ¶
func KubeConfigPath() string
func KubernetesReleaseVersion ¶
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 ReadFileAs ¶
func RegisterCloudManager ¶
RegisterCloudManager registers a cloud.Factory by name. This is expected to happen during app startup.
func RenderStartupScript ¶
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 ¶
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 (*GenericUpgradeManager) GetAvailableUpgrades ¶
func (upm *GenericUpgradeManager) GetAvailableUpgrades() ([]*api.Upgrade, error)
func (*GenericUpgradeManager) MasterUpgrade ¶
func (*GenericUpgradeManager) NodeUpgrade ¶
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 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 ¶
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 (*Scope) GetCluster ¶
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
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 *clusterv1.Machine, token string) TemplateData
func NewNodeTemplateData ¶
func NewNodeTemplateData(cm Interface, machine *clusterv1.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