kubespray

package
v0.0.0-...-1a511a4 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AMD64 = amd64
	ARM64 = arm64
)
View Source
const (
	ErrKubernetesVersionEmpty         = errors.Error("KubernetesVersion is empty")
	ErrKubernetesVersionInvalidFormat = errors.Error("KubernetesVersion invalid format")
)
View Source
const (
	DockerVersion_19_03   = "19.03"
	DockerVersion_20_10   = "20.10"
	ContainerdVersion     = "1.4.9"
	NetworkPluginCalico   = "calico"
	NetworkPluginCNI      = "cni"
	CgroupDriver          = "systemd"
	CloudProviderExternal = "external"
)
View Source
const (
	KubesprayNodeRoleMaster       = "kube-master"
	KubesprayNodeRoleControlPlane = "kube-control-plane"
	KubesprayNodeRoleEtcd         = "etcd"
	KubesprayNodeRoleNode         = "kube-node"
	KubesprayNodeRoleCalicoRR     = "calico-rr"
)
View Source
const (
	DefaultAnsiblePath = "/opt/yunion/ansible"
)

Variables

View Source
var (
	DefaultKubesprayClusterYML        = "cluster.yml"
	DefaultKubesprayRemoveNodeYML     = "remove-node.yml"
	DefaultKubesprayScaleYML          = "scale.yml"
	DefaultKubesprayUpgradeClusterYML = "upgrade-cluster.yml"

	KubesprayNodeRoles = []KubesprayNodeRole{
		KubesprayNodeRoleMaster,
		KubesprayNodeRoleControlPlane,
		KubesprayNodeRoleEtcd,
		KubesprayNodeRoleNode,
		KubesprayNodeRoleCalicoRR,
	}
)
View Source
var (
	DefaultPlaybookConfigPath = "ansible.cfg"
)
View Source
var (
	KubernetesVersionRegexp = regexp.MustCompile(`^1\.\d{1,2}\.\d$`)
)

Functions

func GetCNICheckSum

func GetCNICheckSum(arch, version string) (string, error)

func GetKubeadmCheckSum

func GetKubeadmCheckSum(arch, version string) (string, error)

func GetKubectlCheckSum

func GetKubectlCheckSum(arch, version string) (string, error)

func GetKubeletCheckSum

func GetKubeletCheckSum(arch, version string) (string, error)

func ValidateKubernetesVersion

func ValidateKubernetesVersion(kv string) error

Types

type AnsibleRunner

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

func NewAnsibleRunner

func NewAnsibleRunner(playbookPath string, kubeVersion string, hosts ...*KubesprayInventoryHost) (*AnsibleRunner, error)

func (*AnsibleRunner) AddLimitHosts

func (r *AnsibleRunner) AddLimitHosts(checkHost bool, hosts ...string) error

func (*AnsibleRunner) Clear

func (r *AnsibleRunner) Clear() error

func (*AnsibleRunner) Execute

func (r *AnsibleRunner) Execute(command string, args []string, prefix string) error

func (*AnsibleRunner) GetOutput

func (r *AnsibleRunner) GetOutput() string

func (*AnsibleRunner) ResultsFunc

func (*AnsibleRunner) Run

func (r *AnsibleRunner) Run(debug bool, tags []string) error

func (*AnsibleRunner) SetAction

func (r *AnsibleRunner) SetAction(action string) *AnsibleRunner

func (*AnsibleRunner) SetExtraVars

func (r *AnsibleRunner) SetExtraVars(vars interface{}) error

type CommonVars

type CommonVars struct {
	DockerRegistryMirrors    []string `json:"docker_registry_mirrors,allowempty"`
	DockerInsecureRegistries []string `json:"docker_insecure_registries,allowempty"`
	KubernetesVersion        string   `json:"kubernetes_version"`
}

type CreateRunner

type CreateRunner interface {
	Run() error
	// GetOutput get ansible playbook output
	GetOutput() string
}

type DefaultKubesprayExecutor

type DefaultKubesprayExecutor interface {
	Cluster(vars *KubesprayRunVars, hosts ...*KubesprayInventoryHost) KubesprayRunner
	Scale(vars *KubesprayRunVars, allHosts []*KubesprayInventoryHost, addedHosts ...*KubesprayInventoryHost) KubesprayRunner
	RemoveNode(vars *KubesprayRunVars, allHosts []*KubesprayInventoryHost, removeHosts ...*KubesprayInventoryHost) KubesprayRunner
	UpgradeMasterConfig(vars *KubesprayRunVars, hosts ...*KubesprayInventoryHost) KubesprayRunner
}

func NewDefaultKubesprayExecutor

func NewDefaultKubesprayExecutor() DefaultKubesprayExecutor

type IDriver

type IDriver interface {
	ChangeVars(vars *KubesprayVars)
}

type KubesprayInventory

type KubesprayInventory struct {
	Hosts []*KubesprayInventoryHost
	// contains filtered or unexported fields
}

func NewKubesprayInventory

func NewKubesprayInventory(kubeVersion string, host ...*KubesprayInventoryHost) *KubesprayInventory

func (KubesprayInventory) IsIncludeHost

func (i KubesprayInventory) IsIncludeHost(host string) bool

func (KubesprayInventory) ToString

func (i KubesprayInventory) ToString() (string, error)

type KubesprayInventoryHost

type KubesprayInventoryHost struct {
	Hostname    string
	AliasName   string
	AnsibleHost string
	User        string
	Ip          string
	AccessIp    string
	Password    string
	Roles       sets.String
	// contains filtered or unexported fields
}

func NewKubesprayInventoryHost

func NewKubesprayInventoryHost(
	hostname string,
	sshIP string,
	user string,
	password string,

	roles ...KubesprayNodeRole,
) (*KubesprayInventoryHost, error)

func (*KubesprayInventoryHost) Clear

func (h *KubesprayInventoryHost) Clear() error

func (KubesprayInventoryHost) GetEtcdMemberName

func (h KubesprayInventoryHost) GetEtcdMemberName() string

func (*KubesprayInventoryHost) GetPrivateKey

func (h *KubesprayInventoryHost) GetPrivateKey() string

func (KubesprayInventoryHost) HasRole

func (KubesprayInventoryHost) IsEtcdMember

func (h KubesprayInventoryHost) IsEtcdMember() bool

func (*KubesprayInventoryHost) SetAliasName

func (h *KubesprayInventoryHost) SetAliasName(name string)

func (*KubesprayInventoryHost) SetPrivateKey

func (h *KubesprayInventoryHost) SetPrivateKey(content []byte) error

func (KubesprayInventoryHost) ToString

func (h KubesprayInventoryHost) ToString() (string, error)

type KubesprayNodeRole

type KubesprayNodeRole string

type KubesprayRunVars

type KubesprayRunVars struct {
	KubesprayVars
}

type KubesprayRunner

type KubesprayRunner interface {
	AddLimitHosts(checkHost bool, hosts ...string) error
	Run(debug bool, tags []string) error
	// GetOutput get ansible playbook output
	GetOutput() string
}

func NewDefaultKubesprayClusterRunner

func NewDefaultKubesprayClusterRunner(vars *KubesprayRunVars, hosts ...*KubesprayInventoryHost) (KubesprayRunner, error)

func NewDefaultKubesprayRemoveNodeRunner

func NewDefaultKubesprayRemoveNodeRunner(
	vars *KubesprayRunVars,
	allHosts []*KubesprayInventoryHost,
	hosts ...*KubesprayInventoryHost,
) (KubesprayRunner, error)

func NewDefaultKubesprayScaleRunner

func NewDefaultKubesprayScaleRunner(
	vars *KubesprayRunVars,
	allHosts []*KubesprayInventoryHost,
	addedHosts ...*KubesprayInventoryHost,
) (KubesprayRunner, error)

func NewDefaultKubesprayUpgradeRunner

func NewDefaultKubesprayUpgradeRunner(vars *KubesprayRunVars, hosts ...*KubesprayInventoryHost) (KubesprayRunner, error)

func NewRunner

func NewRunner(playbookPath string, vars *KubesprayRunVars, hosts ...*KubesprayInventoryHost) (KubesprayRunner, error)

type KubesprayVars

type KubesprayVars struct {
	// DownloadRunOnce will make kubespray download container images and binaries only once
	// and then push them to the cluster nodes. The default download delegate node is the
	// first `kube-master`
	DownloadRunOnce bool  `json:"download_run_once"`
	SkipDownloads   *bool `json:"skip_downloads,omitempty"`
	// YumRepo for rpm: http://mirrors.aliyun.com
	YumRepo string `json:"yum_repo"`
	// GCRImageRepo: gcr.azk8s.cn
	GCRImageRepo string `json:"gcr_image_repo"`
	// KubeImageRepo: registry.aliyuncs.com/google_containers or gcr.azk8s.cn/google-containers
	KubeImageRepo string `json:"kube_image_repo"`
	// QuayImageRepo: quay.mirrors.ustc.edu.cn
	QuayImageRepo string `json:"quay_image_repo"`

	// Docker CentOS/Redhat repo
	// DockerRHRepoBaseUrl: {{ yum_repo }}/docker-ce/{{ ansible_distribution_major_version }}/$basearch
	DockerRHRepoBaseUrl string `json:"docker_rh_repo_base_url"`
	// DockerRHRepoGPGKey: {{ yum_repo }}/docker-ce/gpg
	DockerRHRepoGPGKey       string   `json:"docker_rh_repo_gpgkey,allowempty"`
	DockerRegistryMirrors    []string `json:"docker_registry_mirrors"`
	DockerInsecureRegistries []string `json:"docker_insecure_registries"`
	DockerOptions            string   `json:"docker_options"`
	DockerVersion            string   `json:"docker_version"`
	DockerCliVersion         string   `json:"docker_cli_version"`
	ContainerManager         string   `json:"container_manager"`
	ContainerdVersion        string   `json:"containerd_version,omitempty"`
	EtcdDeploymentType       string   `json:"etcd_deployment_type,omitempty"`

	// kubespray etcd cluster not support kubeadm managed very well currently
	// EtcdKubeadmEnabled     bool   `json:"etcd_kubeadm_enabled"`
	KubeVersion            string `json:"kube_version"`
	CNIVersion             string `json:"cni_version"`
	EnableNodelocalDNS     bool   `json:"enable_nodelocaldns"`
	CloudProvider          string `json:"cloud_provider,omitempty"`
	NodelocalDNSVersion    string `json:"nodelocaldns_version"`
	NodelocalDNSImageRepo  string `json:"nodelocaldns_image_repo"`
	DNSAutoscalerImageRepo string `json:"dnsautoscaler_image_repo"`
	// KubeletDownloadUrl: https://storage.googleapis.com/kubernetes-release/release/{{ kube_version  }}/bin/linux/{{ image_arch }}/kubelet
	KubeletDownloadUrl string `json:"kubelet_download_url,omitempty"`
	// KubectlDownloadUrl: https://storage.googleapis.com/kubernetes-release/release/{{ kube_version }}/bin/linux/{{ image_arch }}/kubectl
	KubectlDownloadUrl string `json:"kubectl_download_url,omitempty"`
	// KubeadmDownloadUrl: https://storage.googleapis.com/kubernetes-release/release/{{ kubeadm_version }}/bin/linux/{{ image_arch }}/kubeadm
	KubeadmDownloadUrl string `json:"kubeadm_download_url,omitempty"`
	// CNIDownloadUrl: https://github.com/containernetworking/plugins/releases/download/{{ cni_version }}/cni-plugins-linux-{{ image_arch }}-{{ cni_version }}.tgz
	CNIDownloadUrl    string `json:"cni_download_url,omitempty"`
	CNIBinaryChecksum string `json:"cni_binary_checksum,omitempty"`
	// CrictlDownloadUrl: https://iso.yunion.cn/binaries/cri-tools/releases/download/{{ crictl_version }}/crictl-{{ crictl_version }}-{{ ansible_system | lower }}-{{ image_arch }}.tar.gz
	CrictlDownloadUrl string `json:"crictl_download_url"`

	// etcd related vars
	EtcdImageRepo   string `json:"etcd_image_repo"`
	EtcdVersion     string `json:"etcd_version"`
	EtcdDownloadUrl string `json:"etcd_download_url,omitempty"`

	// Calico related vars
	// CalicoctlDownloadUrl: https://iso.yunion.cn/binaries/calicoctl/releases/download/v3.16.5/calicoctl-linux-amd64
	CalicoVersion                 string `json:"calico_version"`
	CalicoctlDownloadUrl          string `json:"calicoctl_download_url,omitempty"`
	CalicoctlAlternateDownloadUrl string `json:"calicoctl_alternate_download_url,omitempty"`
	// https://github.com/projectcalico/calico/archive/{{ calico_version }}.tar.gz
	CalicoCRDsDownloadUrl  string `json:"calico_crds_download_url,omitempty"`
	CalicoNodeImageRepo    string `json:"calico_node_image_repo"`
	CalicoNodeImageTag     string `json:"calico_node_image_tag"`
	CalicoCNIImageRepo     string `json:"calico_cni_image_repo"`
	CalicoCNIImageTag      string `json:"calico_cni_image_tag"`
	CalicoPolicyImageRepo  string `json:"calico_policy_image_repo"`
	CalicoPolicyImageTag   string `json:"calico_policy_image_tag"`
	CalicoTyphaImageRepo   string `json:"calico_typha_image_repo"`
	CalicoTyphaImageTag    string `json:"calico_typha_image_tag"`
	CalicoFlexvolImageRepo string `json:"calico_flexvol_image_repo"`
	CalicoFlexvolImageTag  string `json:"calico_flexvol_image_tag"`

	// Address in cert sans
	SupplementaryAddresses []string `json:"supplementary_addresses_in_ssl_keys"`

	// Add new master and etcd node vars
	IgnoreAssertErrors string `json:"ignore_assert_errors"`
	EtcdRetries        int    `json:"etcd_retries"`

	// Remove nodes vars
	// ResetNodes should be false if want to remove node not online
	ResetNodes bool `json:"reset_nodes"`
	// Node being removed
	Node string `json:"node"`
	// DeleteNodesConfirmation must set to yes
	DeleteNodesConfirmation string `json:"delete_nodes_confirmation"`
	// DeleteNodesConfirmation must set to true
	SkipConfirmation bool `json:"skip_confirmation"`
	//kubespray verion
	KubesprayVersion string `json:"kubespray_version"`
	//CorednsImage path /coredns
	CorednsImageIsNamespaced bool `json:"coredns_image_is_namespaced"`
	//file download url
	DownloadFileURL string `json:"download_file_url"`
	//iamge repo
	ImageRepo string `json:"image_repo"`
	//docker info
	DockerUser     string `json:"docker_user"`
	DockerPassword string `json:"docker_password"`
	DockerHost     string `json:"docker_host"`

	AutoRenewCertificates bool `json:"auto_renew_certificates"`

	// NginxImageRepo is "{{ docker_image_repo }}/library/nginx" by default
	NginxImageRepo string `json:"nginx_image_repo"`
	// NginxImageTag is 1.19 by default
	NginxImageTag string `json:"nginx_image_tag"`

	// kubernetes-apps
	IngressNginxEnabled bool `json:"ingress_nginx_enabled"`
	// IngressNginxControllerImageRepo is "{{ kube_image_repo }}/ingress-nginx/controller" by default
	IngressNginxControllerImageRepo string `json:"ingress_nginx_controller_image_repo"`
	// IngressNginxControllerImageTag is:
	// - k8s v1.17 => v0.41.2
	// - k8s v1.20 => v1.0.0
	IngressNginxControllerImageTag string            `json:"ingress_nginx_controller_image_tag"`
	IngressNginxConfigmap          map[string]string `json:"ingress_nginx_configmap"`
	KubeNetworkPlugin              string            `json:"kube_network_plugin,omitempty"`
	KubeletCgroupDriver            string            `json:"kubelet_cgroup_driver"`
	DockerCgroupDriver             string            `json:"docker_cgroup_driver"`
	OverrideSystemHostname         bool              `json:"override_system_hostname"`

	// k8s services options
	KubeletPreferredAddressTypes   string            `json:"kubelet_preferred_address_types,omitempty"`
	KubeKubeadmApiserverExtraArgs  map[string]string `json:"kube_kubeadm_apiserver_extra_args,omitempty"`
	KubeKubeadmControllerExtraArgs map[string]string `json:"kube_kubeadm_controller_extra_args,omitempty"`
}

func NewDefaultVars

func NewDefaultVars(k8sVersion string, extraConf *api.ClusterExtraConfig, drv IDriver) KubesprayVars

func NewOfflineVars

func NewOfflineVars(k8sVersion string, extraConf *api.ClusterExtraConfig, drv IDriver) KubesprayVars

func (KubesprayVars) Validate

func (v KubesprayVars) Validate() error

Jump to

Keyboard shortcuts

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