2 Copyright 2019 The Kubeedge Authors.
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
23 types "elcli/cmd/common"
27 //CentOS struct objects shall have information of the tools version to be installed
28 //on Hosts having Ubuntu OS.
29 //It implements OSTypeInstaller interface
32 KubernetesVersion string
33 IsEdgeNode bool //True - Edgenode False - Cloudnode
34 K8SImageRepository string
35 K8SPodNetworkCidr string
38 //SetDockerVersion sets the Docker version for the objects instance
39 func (c *CentOS) SetDockerVersion(version string) {
40 c.DockerVersion = version
43 //SetK8SVersionAndIsNodeFlag sets the K8S version for the objects instance
44 //It also sets if this host shall act as edge node or not
45 func (c *CentOS) SetK8SVersionAndIsNodeFlag(version string, flag bool) {
46 c.KubernetesVersion = version
50 //SetK8SImageRepoAndPodNetworkCidr sets the K8S image Repository and pod network
52 func (c *CentOS) SetK8SImageRepoAndPodNetworkCidr(repo, cidr string) {
53 c.K8SImageRepository = repo
54 c.K8SPodNetworkCidr = cidr
57 //IsDockerInstalled checks if docker is installed in the host or not
58 func (c *CentOS) IsDockerInstalled(string) (types.InstallState, error) {
59 //yum list installed | grep docker-ce | awk '{print $2}' | cut -d'-' -f 1
62 return types.VersionNAInRepo, nil
66 //InstallDocker will install the specified docker in the host
67 func (c *CentOS) InstallDocker() error {
68 fmt.Println("InstallDocker called")
69 // yum install -y yum-utils
70 // yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
72 // yum list --showduplicates 'docker-ce' | grep '17.06.0' | head -1 | awk '{print $2}'
73 // yum install -y docker-ce-17.06.0.ce-1.el7.centos
74 // [root@localhost ~]# systemctl start docker
75 // [root@localhost ~]# ---> Always restart systemctl restart docker
76 // [root@localhost ~]#
77 // IF downgrade yum downgrade -y docker-ce-17.06.0.ce-1.el7.centos
78 // Check always for version, if it is a downgrade or upgrade
83 //IsToolVerInRepo checks if the tool mentioned in available in OS repo or not
84 func (c *CentOS) IsToolVerInRepo(toolName, version string) (bool, error) {
85 //yum --cacheonly list | grep openssl
86 //For K8S, dont check in repo, just install
87 fmt.Println("IsToolVerInRepo called")
91 //InstallMQTT checks if MQTT is already installed and running, if not then install it from OS repo
92 //Information is used from https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-the-mosquitto-mqtt-messaging-broker-on-centos-7
93 func (c *CentOS) InstallMQTT() error {
95 //yum -y install epel-release
96 cmd := &Command{Cmd: exec.Command("sh", "-c", "yum -y install epel-release")}
97 err := cmd.ExecuteCmdShowOutput()
98 stdout := cmd.GetStdOutput()
99 errout := cmd.GetStdErr()
100 if err != nil || errout != "" {
101 return fmt.Errorf("%s", errout)
105 //yum -y install mosquitto
106 cmd = &Command{Cmd: exec.Command("sh", "-c", "yum -y install mosquitto")}
107 err = cmd.ExecuteCmdShowOutput()
108 stdout = cmd.GetStdOutput()
109 errout = cmd.GetStdErr()
110 if err != nil || errout != "" {
111 return fmt.Errorf("%s", errout)
116 //systemctl start mosquitto
117 cmd = &Command{Cmd: exec.Command("sh", "-c", "systemctl start mosquitto")}
119 stdout = cmd.GetStdOutput()
120 errout = cmd.GetStdErr()
122 return fmt.Errorf("%s", errout)
126 //systemctl enable mosquitto
127 cmd = &Command{Cmd: exec.Command("sh", "-c", "systemctl enable mosquitto")}
129 stdout = cmd.GetStdOutput()
130 errout = cmd.GetStdErr()
132 return fmt.Errorf("%s", errout)
140 //IsK8SComponentInstalled checks if said K8S version is already installed in the host
141 func (c *CentOS) IsK8SComponentInstalled(component, defVersion string) (types.InstallState, error) {
142 // [root@localhost ~]# yum list installed | grep kubeadm | awk '{print $2}' | cut -d'-' -f 1
144 // [root@localhost ~]#
145 // [root@localhost ~]# yum list installed | grep kubeadm
146 // kubeadm.x86_64 1.14.1-0 @kubernetes
147 // [root@localhost ~]#
149 return types.VersionNAInRepo, nil
152 //InstallK8S will install kubeadm, kudectl and kubelet for the cloud node
153 func (c *CentOS) InstallK8S() error {
154 fmt.Println("InstallK8S called")
155 //Follow https://kubernetes.io/docs/setup/independent/install-kubeadm/
159 //StartK8Scluster will do "kubeadm init" and cluster will be started
160 func (c *CentOS) StartK8Scluster() error {