Skip to content

Commit

Permalink
Support kernel upgrade operation optional.
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudnativer committed Nov 19, 2021
1 parent 3560635 commit 7dbdb84
Show file tree
Hide file tree
Showing 46 changed files with 824 additions and 175 deletions.
2 changes: 1 addition & 1 deletion data/config/language.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
en
cn
1 change: 1 addition & 0 deletions data/config/tools.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
on,on,on
2 changes: 2 additions & 0 deletions data/msg/msg.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@





2 changes: 1 addition & 1 deletion data/statistics/cpuinfo.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1
0
2 changes: 1 addition & 1 deletion data/statistics/diskinfo.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
23
38
2 changes: 1 addition & 1 deletion data/statistics/k8snum.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0
1
2 changes: 1 addition & 1 deletion data/statistics/labellist.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
,,,,
,,,,k8s-test-001
2 changes: 1 addition & 1 deletion data/statistics/meminfo.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4
6
2 changes: 1 addition & 1 deletion data/statistics/nodenumlist.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
,,,,
,,,,3
2 changes: 1 addition & 1 deletion data/statistics/stuok.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0E+00
1E+02
2 changes: 1 addition & 1 deletion data/statistics/stuunkonw.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1E+02
0E+00
Binary file modified docs/images/loginkey.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/loginkey2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 27 additions & 29 deletions kube-install.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,7 @@ import (

func main() {

var exec string
var master string
var node string
var k8sver string
var ostype string
var softdir string
var label string
var sship string
var sshpass string
var listen string
var exec,master,node,k8sver,ostype,softdir,label,sship,sshpass,listen,upgradekernel string

initFlag := flag.Bool("init",false,"Initialize the local system environment.")
iFlag := flag.Bool("i",false,"Initialize the local system environment.")
Expand All @@ -42,8 +33,9 @@ func main() {
flag.StringVar(&node,"node","","The IP address of k8s node server filled in for the first installation")
flag.StringVar(&ostype,"ostype","","Specifies the distribution operating system type: centos7 | centos8 | rhel7 | rhel8 | ubuntu20 | suse15")
flag.StringVar(&k8sver,"k8sver","","Specifies the version of k8s software installed.(Default is \"kubernetes 1.22\")")
flag.StringVar(&upgradekernel,"upgradekernel","no","Because the lower versions of CentOS 7 and redhat 7 may lack kernel modules, only the kernel automatic upgrade of CentOS 7 and rhel7 operating systems is supported here, and other operating systems do not need to be upgraded. (Default is \"no\")")
flag.StringVar(&softdir,"softdir","","Specifies the installation directory of kubernetes cluster.(Default is \"/exec/kube-install\")")
flag.StringVar(&label,"label",".default","In the case of deploying and operating multiple kubernetes clusters, it is necessary to specify a label to uniquely identify a kubernetes cluster.")
flag.StringVar(&label,"label",".default","In the case of deploying and operating multiple kubernetes clusters, it is necessary to specify a label to uniquely identify a kubernetes cluster. (Length must be less than 32 strings)")
flag.StringVar(&sship,"sship","","The IP address of the target host through which the SSH channel is opened.(Use with \"sshcontrol\")")
flag.StringVar(&sshpass,"sshpass","","The SSH password of the target host through which the SSH channel is opened.(Use with \"sshcontrol\")")
flag.Parse()
Expand All @@ -58,8 +50,8 @@ func main() {

// Set the version number and release date of Kube-Install.
const (
Version string = "v0.7.2"
ReleaseDate string = "10/22/2021"
Version string = "v0.7.3"
ReleaseDate string = "12/8/2021"
CompatibleK8S string = "1.17, 1.18, 1.19, 1.20, 1.21, 1.22, and 1.23"
CompatibleOS string = "CentOS linux 7, CentOS linux 8, RHEL 7, RHEL 8, Ubuntu 20, and SUSE 15"
)
Expand All @@ -72,6 +64,7 @@ func main() {
fmt.Println("\nInitialization in progress, please wait...\n")
kilib.CreateDir(currentDir+"/data/config", currentDir, logName, "")
kilib.CreateFile(currentDir+"/data/config/language.txt", currentDir, logName, "")
kilib.CreateFile(currentDir+"/data/config/tools.txt", currentDir, logName, "")
kilib.CreateDir(currentDir+"/data/output", currentDir, logName, "")
kilib.CreateDir(currentDir+"/data/logs", currentDir, logName, "")
kilib.CreateDir(currentDir+"/data/msg", currentDir, logName, "")
Expand Down Expand Up @@ -119,22 +112,24 @@ func main() {
case *showk8sFlag , *sFlag :
labelArray,err := kilib.GetAllDir(currentDir+"/data/output",currentDir,logName,"")
kilib.CheckErr(err,currentDir,logName,"")
fmt.Println("-----------------------------------------------------------┬-----------------------------------┬-------------------------------\n Label Of K8S Cluster | Version | Installation Status | Resource File Directory | K8S-Master Information \n-----------------------------------------------------------┼------------------------------------------------------------------")
fmt.Println("------------------------------------------------------------┬-------------------------------------┬---------------------------------\n Kubernetes Cluster Label | Version | Install Status | Install Resource Directory | Kubernetes Master Information \n------------------------------------------------------------┼-------------------------------------┼---------------------------------")
for _, i := range labelArray {
label1 := " | "
k8sver1 := " | "
status1 := " | "
softDir1 := " |"
label2 := string(i)
k8sver2 := "k8s "+kilib.GetClusterK8sVer(label2,currentDir,"")
status2,_ := kilib.GetClusterStatus(label2,currentDir,logName,"")
softDir2 := kilib.GetClusterSoftdir(label2,currentDir,"")
if len(softDir2) < len(softDir1) { softDir2 = softDir2 + softDir1[len(softDir2):len(softDir1)] }
master2 := kilib.GetClusterMaster(label2,currentDir,logName,"")
fmt.Printf(" " + label2 + label1[len(label2):len(label1)] + k8sver2 + k8sver1[len(k8sver2):len(k8sver1)] + status2 + status1[len(status2):len(status1)] + softDir2+" ")
fmt.Println(master2)
var label2,softDir2 string
labelInit := " | "
k8sverInit := " | "
statusInit := " | "
softDirInit := " |"
label := string(i)
if len(label) < len(labelInit) { label2 = label + labelInit[len(label):len(labelInit)] } else { label2 = label + " | " }
k8sver := "k8s "+kilib.GetClusterK8sVer(label,currentDir,"")
status,_ := kilib.GetClusterStatus(label,currentDir,logName,"")
softDir := kilib.GetClusterSoftdir(label,currentDir,"")
if len(softDir) < len(softDirInit) { softDir2 = softDir + softDirInit[len(softDir):len(softDirInit)] } else { softDir2 = softDir + " |" }
master := kilib.GetClusterMaster(label,currentDir,logName,"")
fmt.Printf(" " + label2 + k8sver + k8sverInit[len(k8sver):len(k8sverInit)] + status + statusInit[len(status):len(statusInit)] + softDir2+" ")
fmt.Println(master)
}
fmt.Println("-----------------------------------------------------------┴------------------------------------------------------------------")
fmt.Println("------------------------------------------------------------┴-------------------------------------┴---------------------------------")

// View software version details.
case *versionFlag , *vFlag :
Expand Down Expand Up @@ -163,15 +158,18 @@ func main() {
case exec == "install" :
kilib.CheckParam(exec,"master",master)
kilib.CheckParam(exec,"node",node)
if !kilib.CheckLabel(label) {
panic("\nThe \"-ostype\" parameter length must be less than 32 strings, please check! \n\n ")
}
masterArray,nodeArray,softdir,subProcessDir,ostypeResult := kilib.ParameterConvert("", master, node, softdir, label, ostype)
kilib.DatabaseInit(currentDir,subProcessDir,logName,"")
kilib.InstallCore("",master,masterArray,node,nodeArray,softdir,currentDir,kissh,subProcessDir,currentUser,label,ostypeResult,ostype,k8sver,logName,Version,CompatibleK8S,CompatibleOS,"","newinstall")
kilib.InstallCore("",master,masterArray,node,nodeArray,softdir,currentDir,kissh,subProcessDir,currentUser,label,ostypeResult,ostype,k8sver,logName,Version,CompatibleK8S,CompatibleOS,"","newinstall",upgradekernel)

//Execute addnode command
case exec == "addnode" :
kilib.CheckParam(exec,"node",node)
_,nodeArray,_,subProcessDir,ostypeResult := kilib.ParameterConvert("", "", node, softdir, label, ostype)
kilib.AddNodeCore("",node,nodeArray,currentDir,kissh,subProcessDir,currentUser,label,softdir,ostypeResult,logName,CompatibleOS)
kilib.AddNodeCore("",node,nodeArray,currentDir,kissh,subProcessDir,currentUser,label,softdir,ostypeResult,logName,CompatibleOS,upgradekernel)

//Execute delnode command
case exec == "delnode" :
Expand Down
2 changes: 1 addition & 1 deletion kube-install.service
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Unit]
Description=The highly available multiple kubernetes cluster can be installed offline with one click.
Description=The highly available multiple kubernetes cluster can be installed offline with one click.
Documentation=https://cloudnativer.github.io
After=sshd.service
Requires=sshd.service
Expand Down
9 changes: 9 additions & 0 deletions lib/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ func CheckPort(port int) bool {
}
}

// Check whether the cluster label is correct.
func CheckLabel(label string) bool {
if len(label) > 32 {
return false
} else {
return true
}
}

// Check whether the parameters are input normally.
func CheckParam(option string, paramName string, param string) {
if param == "" {
Expand Down
1 change: 0 additions & 1 deletion lib/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,3 @@ func LogStr(mode string) string {
}
return logStr
}

32 changes: 24 additions & 8 deletions lib/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,17 @@ func DeleteMasterCore(mode string, masterArray []string, currentDir string, kiss
}

// Add the core operation part of the node.
func AddNodeCore(mode string, node string, nodeArray []string, currentDir string, kissh string, subProcessDir string, currentUser string, label string, softDir string, osTypeResult string, logName string, CompatibleOS string) {
func AddNodeCore(mode string, node string, nodeArray []string, currentDir string, kissh string, subProcessDir string, currentUser string, label string, softDir string, osTypeResult string, logName string, CompatibleOS string, upgradeKernel string) {
opt := "addnode"
logStr := LogStr(mode)
upgradeKernelStr := "\n Automatically Upgrade OS Kernel: Not Support"
if osTypeResult == "centos7" || osTypeResult == "rhel7" {
if upgradeKernel == "yes"{
upgradeKernelStr = "\n Automatically Upgrade OS Kernel: YES"
} else {
upgradeKernelStr = "\n Automatically Upgrade OS Kernel: NO"
}
}
CheckOS(CompatibleOS, osTypeResult, currentDir, logName, mode)
CreateDir(currentDir+"/data/output"+subProcessDir, currentDir, logName, mode)
for i := 0; i < len(nodeArray); i++ {
Expand All @@ -116,7 +124,7 @@ func AddNodeCore(mode string, node string, nodeArray []string, currentDir string
}
os.OpenFile(currentDir+"/data/logs"+subProcessDir+"/logs/addnode.log", os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0766)
ShellExecute("echo \"*************************************************************************************\n\n[Info] "+time.Now().String()+" Adding kubernetes node, please wait ... \n\""+logStr+currentDir+"/data/logs"+subProcessDir+"/logs/addnode.log")
ShellExecute("echo \" Kubernetes Cluster Label: "+label+"\n Kubernetes Node: "+node+"\n System User for Operation: "+currentUser+"\""+logStr+currentDir+"/data/logs"+subProcessDir+"/logs/addnode.log")
ShellExecute("echo \" Kubernetes Cluster Label: "+label+"\n Kubernetes Node: "+node+ upgradeKernelStr +"\n System User for Operation: "+currentUser+"\""+logStr+currentDir+"/data/logs"+subProcessDir+"/logs/addnode.log")
ShellExecute("sed -i '1d' "+currentDir+"/data/msg/msg.txt")
ShellExecute("echo \"<div class='g_12'><div class='info iDialog'>[Info] "+time.Now().String()+" Adding kubernetes node to "+label+" cluster ... </div></div>\" >> "+currentDir+"/data/msg/msg.txt")
if !AddnodeConfig(mode, nodeArray, currentDir, subProcessDir, logName) {
Expand All @@ -126,7 +134,7 @@ func AddNodeCore(mode string, node string, nodeArray []string, currentDir string
ShellExecute("echo [Error] "+time.Now().String()+" \"The parameters you entered are incorrect, please check! \n\""+logStr+currentDir+"/data/logs"+subProcessDir+"/logs/addnode.log")
return
}
AddnodeYML("",currentDir+"/data/output"+subProcessDir,currentDir,currentUser,osTypeResult,logName)
AddnodeYML("",currentDir+"/data/output"+subProcessDir,currentDir,currentUser,logName,upgradeKernel,osTypeResult)
err_addnode := ExecuteOpt(kissh, currentDir, opt, opt, subProcessDir, "")
if err_addnode != nil {
for i := 0; i < len(nodeArray); i++ {
Expand Down Expand Up @@ -202,10 +210,18 @@ func DeleteNodeCore(mode string, nodeArray []string, currentDir string, kissh st
}

// Install the core operation part of the cluster.
func InstallCore(mode string, master string, masterArray []string, node string, nodeArray []string, softDir string, currentDir string, kissh string, subProcessDir string, currentUser string, label string, osTypeResult string, osType string, k8sVer string, logName string, Version string, CompatibleK8S string, CompatibleOS string, installTime string, way string) {
func InstallCore(mode string, master string, masterArray []string, node string, nodeArray []string, softDir string, currentDir string, kissh string, subProcessDir string, currentUser string, label string, osTypeResult string, osType string, k8sVer string, logName string, Version string, CompatibleK8S string, CompatibleOS string, installTime string, way string, upgradeKernel string) {
opt := "install"
layoutName := "install"
logStr := LogStr(mode)
upgradeKernelStr := "\n Automatically Upgrade OS Kernel: Not Support"
if osTypeResult == "centos7" || osTypeResult == "rhel7" {
if upgradeKernel == "yes"{
upgradeKernelStr = "\n Automatically Upgrade OS Kernel: YES"
} else {
upgradeKernelStr = "\n Automatically Upgrade OS Kernel: NO"
}
}
CheckOS(CompatibleOS, osTypeResult, currentDir, logName, mode)
CheckK8sVersion(Version, CompatibleK8S, k8sVer, currentDir, logName, mode)
CreateDir(currentDir+"/data/output"+subProcessDir, currentDir, logName, mode)
Expand Down Expand Up @@ -238,14 +254,14 @@ func InstallCore(mode string, master string, masterArray []string, node string,
InstallIpvsYaml(mode, currentDir, masterArray, subProcessDir, logName)
var err_install error
if len(masterArray) == 1{
OnemasterInstallYML(mode,currentDir+"/data/output"+subProcessDir,currentDir,currentUser,osTypeResult,logName)
OnemasterInstallYML(mode,currentDir+"/data/output"+subProcessDir,currentDir,currentUser,logName, upgradeKernel,osTypeResult)
layoutName = "onemasterinstall"
}else{
InstallYML(mode,currentDir+"/data/output"+subProcessDir, currentDir, currentUser, osTypeResult, logName)
InstallYML(mode,currentDir+"/data/output"+subProcessDir, currentDir, currentUser, logName, upgradeKernel,osTypeResult)
}
if installTime != "" {
ShellExecute("echo \"*************************************************************************************\n\n[Info] "+time.Now().String()+" Start scheduled installation task, please wait ... \n\""+logStr+currentDir+"/data/logs"+subProcessDir+"/logs/install.log")
ShellExecute("echo \" Kubernetes Cluster Label: "+label+"\n Kubernetes Version: Kubernetes v"+k8sVer+"\n Kubernetes Master: "+master+"\n Kubernetes Node: "+node+"\n Operating System Type: "+osType+"\n System User for Installation: "+currentUser+"\""+logStr+currentDir+"/data/logs"+subProcessDir+"/logs/install.log")
ShellExecute("echo \" Kubernetes Cluster Label: "+label+"\n Kubernetes Version: Kubernetes v"+k8sVer+"\n Kubernetes Master: "+master+"\n Kubernetes Node: "+node+"\n Operating System Type: "+osType+ upgradeKernelStr +"\n System User for Installation: "+currentUser+"\""+logStr+currentDir+"/data/logs"+subProcessDir+"/logs/install.log")
DatabaseUpdate(currentDir+"/data/output"+subProcessDir+"/softdirtemp.txt", softDir, currentDir, logName, mode)
DatabaseUpdate(currentDir+"/data/output"+subProcessDir+"/ostypetemp.txt", osType, currentDir, logName, mode)
DatabaseUpdate(currentDir+"/data/output"+subProcessDir+"/k8svertemp.txt", k8sVer, currentDir, logName, mode)
Expand All @@ -254,7 +270,7 @@ func InstallCore(mode string, master string, masterArray []string, node string,
return
} else {
ShellExecute("echo \"*************************************************************************************\n\n[Info] "+time.Now().String()+" Installing kubernetes cluster, please wait ... \n\""+logStr+currentDir+"/data/logs"+subProcessDir+"/logs/install.log")
ShellExecute("echo \" Kubernetes Cluster Label: "+label+"\n Kubernetes Version: Kubernetes v"+k8sVer+"\n Kubernetes Master: "+master+"\n Kubernetes Node: "+node+"\n Operating System Type: "+osType+"\n System User for Installation: "+currentUser+"\""+logStr+currentDir+"/data/logs"+subProcessDir+"/logs/install.log")
ShellExecute("echo \" Kubernetes Cluster Label: "+label+"\n Kubernetes Version: Kubernetes v"+k8sVer+"\n Kubernetes Master: "+master+"\n Kubernetes Node: "+node+"\n Operating System Type: "+osType+ upgradeKernelStr +"\n System User for Installation: "+currentUser+"\""+logStr+currentDir+"/data/logs"+subProcessDir+"/logs/install.log")
sch,_ := ReadFile(currentDir+"/data/output"+subProcessDir+"/scheduler.txt")
if sch == "on" {
ShellExecute("echo [Error] "+time.Now().String()+" \"Installation conflict! Background scheduled tasks exist and installation is in progress.\n\""+logStr+currentDir+"/data/logs"+subProcessDir+"/logs/install.log")
Expand Down
Loading

0 comments on commit 7dbdb84

Please sign in to comment.