util

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UbuntuOSType = "ubuntu"
	CentOSType   = "centos"

	DefaultDownloadURL = "https://download.docker.com"
	DockerPreqReqList  = "apt-transport-https ca-certificates curl gnupg-agent software-properties-common"

	KubernetesDownloadURL = "https://apt.kubernetes.io/"
	KubernetesGPGURL      = "https://packages.cloud.google.com/apt/doc/apt-key.gpg"

	KubeEdgeDownloadURL       = "https://github.com/kubeedge/kubeedge/releases/download"
	KubeEdgePath              = "/etc/kubeedge/"
	KubeEdgeConfPath          = KubeEdgePath + "kubeedge/edge/conf"
	KubeEdgeBinaryName        = "edge_core"
	KubeEdgeDefaultCertPath   = KubeEdgePath + "certs/"
	KubeEdgeConfigEdgeYaml    = KubeEdgeConfPath + "/edge.yaml"
	KubeEdgeConfigNodeJSON    = KubeEdgeConfPath + "/node.json"
	KubeEdgeConfigLoggingYaml = KubeEdgeConfPath + "/logging.yaml"
	KubeEdgeConfigModulesYaml = KubeEdgeConfPath + "/modules.yaml"

	KubeEdgeCloudCertGenPath      = KubeEdgePath + "certgen.sh"
	KubeEdgeEdgeCertsTarFileName  = "certs.tgz"
	KubeEdgeEdgeCertsTarFilePath  = KubeEdgePath + "certs.tgz"
	KubeEdgeCloudConfPath         = KubeEdgePath + "kubeedge/cloud/conf"
	KubeEdgeControllerYaml        = KubeEdgeCloudConfPath + "/controller.yaml"
	KubeEdgeControllerLoggingYaml = KubeEdgeCloudConfPath + "/logging.yaml"
	KubeEdgeControllerModulesYaml = KubeEdgeCloudConfPath + "/modules.yaml"
	KubeCloudBinaryName           = "edgecontroller"
	KubeCloudApiserverYamlPath    = "/etc/kubernetes/manifests/kube-apiserver.yaml"
	KubeCloudReplaceIndex         = 25
	KubeCloudReplaceString        = "    - --insecure-bind-address=0.0.0.0\n"

	KubeAPIServerName          = "kube-apiserver"
	KubeEdgeHTTPProto          = "http"
	KubeEdgeHTTPSProto         = "https"
	KubeEdgeHTTPPort           = "8080"
	KubeEdgeHTTPSPort          = "6443"
	KubeEdgeHTTPRequestTimeout = 30
)

Constants used by installers

View Source
const (
	UbuntuXenial = "xenial"
	UbuntuBionic = "bionic"
)

Ubuntu releases

Variables

View Source
var (
	CertGenSh = []byte(`#!/bin/sh

readonly caPath=${CA_PATH:-/etc/kubeedge/ca}
readonly caSubject=${CA_SUBJECT:-/C=CN/ST=Zhejiang/L=Hangzhou/O=KubeEdge/CN=kubeedge.io}
readonly certPath=${CERT_PATH:-/etc/kubeedge/certs}
readonly subject=${SUBJECT:-/C=CN/ST=Zhejiang/L=Hangzhou/O=KubeEdge/CN=kubeedge.io}

genCA() {
    openssl genrsa -des3 -out ${caPath}/rootCA.key -passout pass:kubeedge.io 4096
    openssl req -x509 -new -nodes -key ${caPath}/rootCA.key -sha256 -days 3650 \
    -subj ${subject} -passin pass:kubeedge.io -out ${caPath}/rootCA.crt
}

ensureCA() {
    if [ ! -e ${caPath}/rootCA.key ] || [ ! -e ${caPath}/rootCA.crt ]; then
        genCA
    fi
}

ensureFolder() {
    if [ ! -d ${caPath} ]; then
        mkdir -p ${caPath}
    fi
    if [ ! -d ${certPath} ]; then
        mkdir -p ${certPath}
    fi
}

genCertAndKey() {
    ensureFolder
    ensureCA
    local name=$1
    openssl genrsa -out ${certPath}/${name}.key 2048
    openssl req -new -key ${certPath}/${name}.key -subj ${subject} -out ${certPath}/${name}.csr
    openssl x509 -req -in ${certPath}/${name}.csr -CA ${caPath}/rootCA.crt -CAkey ${caPath}/rootCA.key \
    -CAcreateserial -passin pass:kubeedge.io -out ${certPath}/${name}.crt -days 365 -sha256
}

buildSecret() {
    local name="edge"
    genCertAndKey ${name} > /dev/null 2>&1
    cat <<EOF
apiVersion: v1
kind: Secret
metadata:
  name: edgecontroller
  namespace: kubeedge
  labels:
    k8s-app: kubeedge
    kubeedge: edgecontroller
stringData:
  rootCA.crt: |
$(pr -T -o 4 ${caPath}/rootCA.crt)
  edge.crt: |
$(pr -T -o 4 ${certPath}/${name}.crt)
  edge.key: |
$(pr -T -o 4 ${certPath}/${name}.key)

EOF
}

$1 $2
`)
)

Edge controller Configuration files and certificate generator script

Functions

func AddToolVals

func AddToolVals(f *pflag.Flag, flagData map[string]types.FlagData)

AddToolVals gets the value and default values of each flags and collects them in temporary cache

func CheckIfAvailable

func CheckIfAvailable(val, defval string) string

CheckIfAvailable checks is val of a flag is empty then return the default value

func GetOSInterface

func GetOSInterface() types.OSTypeInstaller

GetOSInterface helps in returning OS specific object which implements OSTypeInstaller interface.

func GetOSVersion

func GetOSVersion() string

GetOSVersion gets the OS name

func IsKubeEdgeController

func IsKubeEdgeController() (types.ModuleRunning, error)

IsKubeEdgeController identifies if the node is having edge controller and k8s api-server already running. If so, then return true, else it can used as edge node and initialise it.

Types

type CentOS

type CentOS struct {
	DockerVersion     string
	KubernetesVersion string
	KubeEdgeVersion   string
	IsEdgeNode        bool //True - Edgenode False - Cloudnode
}

CentOS struct objects shall have information of the tools version to be installed on Hosts having Ubuntu OS. It implements OSTypeInstaller interface

func (*CentOS) InstallDocker

func (c *CentOS) InstallDocker() error

InstallDocker will install the specified docker in the host

func (*CentOS) InstallK8S

func (c *CentOS) InstallK8S() error

InstallK8S will install kubeadm, kudectl and kubelet for the cloud node

func (*CentOS) InstallKubeEdge

func (c *CentOS) InstallKubeEdge() error

InstallKubeEdge downloads the provided version of KubeEdge. Untar's in the specified location /etc/kubeedge/ and then copies the binary to /usr/local/bin path.

func (*CentOS) InstallMQTT

func (c *CentOS) InstallMQTT() error

InstallMQTT checks if MQTT is already installed and running, if not then install it from OS repo Information is used from https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-the-mosquitto-mqtt-messaging-broker-on-centos-7

func (*CentOS) IsDockerInstalled

func (c *CentOS) IsDockerInstalled(string) (types.InstallState, error)

IsDockerInstalled checks if docker is installed in the host or not

func (*CentOS) IsK8SComponentInstalled

func (c *CentOS) IsK8SComponentInstalled(component, defVersion string) (types.InstallState, error)

IsK8SComponentInstalled checks if said K8S version is already installed in the host

func (*CentOS) IsKubeEdgeProcessRunning

func (c *CentOS) IsKubeEdgeProcessRunning(proc string) (bool, error)

IsKubeEdgeProcessRunning checks if the given process is running or not

func (*CentOS) IsToolVerInRepo

func (c *CentOS) IsToolVerInRepo(toolName, version string) (bool, error)

IsToolVerInRepo checks if the tool mentioned in available in OS repo or not

func (*CentOS) KillKubeEdgeBinary

func (c *CentOS) KillKubeEdgeBinary(proc string) error

KillKubeEdgeBinary will search for KubeEdge process and forcefully kill it

func (*CentOS) RunEdgeCore

func (c *CentOS) RunEdgeCore() error

RunEdgeCore sets the environment variable GOARCHAIUS_CONFIG_PATH for the configuration path and the starts edge_core with logs being captured

func (*CentOS) SetDockerVersion

func (c *CentOS) SetDockerVersion(version string)

SetDockerVersion sets the Docker version for the objects instance

func (*CentOS) SetK8SVersionAndIsNodeFlag

func (c *CentOS) SetK8SVersionAndIsNodeFlag(version string, flag bool)

SetK8SVersionAndIsNodeFlag sets the K8S version for the objects instance It also sets if this host shall act as edge node or not

func (*CentOS) SetKubeEdgeVersion

func (c *CentOS) SetKubeEdgeVersion(version string)

SetKubeEdgeVersion sets the KubeEdge version for the objects instance

func (*CentOS) StartK8Scluster

func (c *CentOS) StartK8Scluster() error

StartK8Scluster will do "kubeadm init" and cluster will be started

type Command

type Command struct {
	Cmd    *exec.Cmd
	StdOut []byte
	StdErr []byte
}

Command defines commands to be executed and captures std out and std error

func (Command) ExecuteCmdShowOutput

func (cm Command) ExecuteCmdShowOutput() error

ExecuteCmdShowOutput captures both StdOut and StdErr after exec.cmd(). It helps in the commands where it takes some time for execution.

func (*Command) ExecuteCommand

func (cm *Command) ExecuteCommand()

ExecuteCommand executes the command and captures the output in stdOut

func (Command) GetStdErr

func (cm Command) GetStdErr() string

GetStdErr gets StdErr field

func (Command) GetStdOutput

func (cm Command) GetStdOutput() string

GetStdOutput gets StdOut field

type Common

type Common struct {
	types.OSTypeInstaller
	OSVersion   string
	ToolVersion string
	KubeConfig  string
}

Common struct contains OS and Tool version properties and also embeds OS interface

func (*Common) SetOSInterface

func (co *Common) SetOSInterface(intf types.OSTypeInstaller)

SetOSInterface defines a method to set the implemtation of the OS interface

type DockerInstTool

type DockerInstTool struct {
	Common
	DefaultToolVer string
}

DockerInstTool embedes Common struct and contains the default docker version It implements ToolsInstaller interface

func (*DockerInstTool) InstallTools

func (d *DockerInstTool) InstallTools() error

InstallTools sets the OS interface, checks if docker installation is required or not. If required then install the said version.

func (*DockerInstTool) TearDown

func (d *DockerInstTool) TearDown() error

TearDown shoud uninstall docker, but it is not required either for cloud or edge node. It is defined so that DockerInstTool implements ToolsInstaller interface

type K8SInstTool

type K8SInstTool struct {
	Common
	IsEdgeNode     bool //True - Edgenode False - Cloudnode
	DefaultToolVer string
}

K8SInstTool embedes Common struct and contains the default K8S version and a flag depicting if host is an edge or cloud node It implements ToolsInstaller interface

func (*K8SInstTool) InstallTools

func (ks *K8SInstTool) InstallTools() error

InstallTools sets the OS interface, checks if K8S installation is required or not. If required then install the said version.

func (*K8SInstTool) TearDown

func (ks *K8SInstTool) TearDown() error

TearDown shoud uninstall K8S, but it is not required either for cloud or edge node. It is defined so that K8SInstTool implements ToolsInstaller interface

type KubeCloudInstTool

type KubeCloudInstTool struct {
	Common
}

KubeCloudInstTool embedes Common struct It implements ToolsInstaller interface

func (*KubeCloudInstTool) InstallTools

func (cu *KubeCloudInstTool) InstallTools() error

InstallTools downloads KubeEdge for the specified version and makes the required configuration changes and initiates edgecontroller.

func (*KubeCloudInstTool) RunEdgeController

func (cu *KubeCloudInstTool) RunEdgeController() error

RunEdgeController starts edgecontroller process

func (*KubeCloudInstTool) TearDown

func (cu *KubeCloudInstTool) TearDown() error

TearDown method will remove the edge node from api-server and stop edgecontroller process

type KubeEdgeInstTool

type KubeEdgeInstTool struct {
	Common
	//CertPath       string
	EdgeContrlrIP  string
	K8SApiServerIP string
	EdgeNodeID     string
	RuntimeType    string
}

KubeEdgeInstTool embedes Common struct and contains cloud node ip:port information It implements ToolsInstaller interface

func (*KubeEdgeInstTool) InstallTools

func (ku *KubeEdgeInstTool) InstallTools() error

InstallTools downloads KubeEdge for the specified verssion and makes the required configuration changes and initiates edge_core.

func (*KubeEdgeInstTool) TearDown

func (ku *KubeEdgeInstTool) TearDown() error

TearDown method will remove the edge node from api-server and stop edge_core process

type MQTTInstTool

type MQTTInstTool struct {
	Common
}

MQTTInstTool embedes Common struct and It implements ToolsInstaller interface

func (*MQTTInstTool) InstallTools

func (m *MQTTInstTool) InstallTools() error

InstallTools sets the OS interface, it simply installs the said version

func (*MQTTInstTool) TearDown

func (m *MQTTInstTool) TearDown() error

TearDown shoud uninstall MQTT, but it is not required either for cloud or edge node. It is defined so that MQTTInstTool implements ToolsInstaller interface

type UbuntuOS

type UbuntuOS struct {
	DockerVersion     string
	KubernetesVersion string
	KubeEdgeVersion   string
	IsEdgeNode        bool //True - Edgenode False - Cloudnode
}

UbuntuOS struct objects shall have information of the tools version to be installed on Hosts having Ubuntu OS. It implements OSTypeInstaller interface

func (*UbuntuOS) InstallDocker

func (u *UbuntuOS) InstallDocker() error

InstallDocker will install the specified docker in the host

func (*UbuntuOS) InstallK8S

func (u *UbuntuOS) InstallK8S() error

InstallK8S will install kubeadm, kudectl and kubelet for the cloud node

func (*UbuntuOS) InstallKubeEdge

func (u *UbuntuOS) InstallKubeEdge() error

InstallKubeEdge downloads the provided version of KubeEdge. Untar's in the specified location /etc/kubeedge/ and then copies the binary to /usr/local/bin path.

func (*UbuntuOS) InstallMQTT

func (u *UbuntuOS) InstallMQTT() error

InstallMQTT checks if MQTT is already installed and running, if not then install it from OS repo

func (*UbuntuOS) IsDockerInstalled

func (u *UbuntuOS) IsDockerInstalled(defVersion string) (types.InstallState, error)

IsDockerInstalled checks if docker is installed in the host or not

func (*UbuntuOS) IsK8SComponentInstalled

func (u *UbuntuOS) IsK8SComponentInstalled(component, defVersion string) (types.InstallState, error)

IsK8SComponentInstalled checks if said K8S version is already installed in the host

func (*UbuntuOS) IsKubeEdgeProcessRunning

func (u *UbuntuOS) IsKubeEdgeProcessRunning(proc string) (bool, error)

IsKubeEdgeProcessRunning checks if the given process is running or not

func (*UbuntuOS) IsToolVerInRepo

func (u *UbuntuOS) IsToolVerInRepo(toolName, version string) (bool, error)

IsToolVerInRepo checks if the tool mentioned in available in OS repo or not

func (*UbuntuOS) KillKubeEdgeBinary

func (u *UbuntuOS) KillKubeEdgeBinary(proc string) error

KillKubeEdgeBinary will search for KubeEdge process and forcefully kill it

func (*UbuntuOS) RunEdgeCore

func (u *UbuntuOS) RunEdgeCore() error

RunEdgeCore sets the environment variable GOARCHAIUS_CONFIG_PATH for the configuration path and the starts edge_core with logs being captured

func (*UbuntuOS) SetDockerVersion

func (u *UbuntuOS) SetDockerVersion(version string)

SetDockerVersion sets the Docker version for the objects instance

func (*UbuntuOS) SetK8SVersionAndIsNodeFlag

func (u *UbuntuOS) SetK8SVersionAndIsNodeFlag(version string, flag bool)

SetK8SVersionAndIsNodeFlag sets the K8S version for the objects instance It also sets if this host shall act as edge node or not

func (*UbuntuOS) SetKubeEdgeVersion

func (u *UbuntuOS) SetKubeEdgeVersion(version string)

SetKubeEdgeVersion sets the KubeEdge version for the objects instance

func (*UbuntuOS) StartK8Scluster

func (u *UbuntuOS) StartK8Scluster() error

StartK8Scluster will do "kubeadm init" and cluster will be started

Jump to

Keyboard shortcuts

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