Add nightly build support

Signed-off-by: rick <rick@jenkins-zh.cn>
This commit is contained in:
rick 2020-12-28 11:09:04 +08:00
parent d2a78d20c4
commit 25f1c87383
6 changed files with 93 additions and 50 deletions

View File

@ -16,9 +16,13 @@ limitations under the License.
package cmd
import (
"fmt"
"github.com/kubesphere/kubekey/apis/kubekey/v1alpha1"
"github.com/kubesphere/kubekey/pkg/install"
"github.com/kubesphere/kubekey/pkg/util"
"github.com/kubesphere/kubekey/version"
"github.com/spf13/cobra"
"time"
)
// clusterCmd represents the cluster command
@ -41,8 +45,26 @@ func init() {
createCmd.AddCommand(clusterCmd)
clusterCmd.Flags().StringVarP(&opt.ClusterCfgFile, "filename", "f", "", "Path to a configuration file")
clusterCmd.Flags().StringVarP(&opt.Kubernetes, "with-kubernetes", "", "v1.17.9", "Specify a supported version of kubernetes")
clusterCmd.Flags().StringVarP(&opt.Kubernetes, "with-kubernetes", "", v1alpha1.DefaultKubeVersion, "Specify a supported version of kubernetes")
clusterCmd.Flags().BoolVarP(&opt.Kubesphere, "with-kubesphere", "", false, "Deploy a specific version of kubesphere (default v3.0.0)")
clusterCmd.Flags().BoolVarP(&opt.SkipCheck, "yes", "y", false, "Skip pre-check of the installation")
clusterCmd.Flags().BoolVarP(&opt.SkipPullImages, "skip-pull-images", "", false, "Skip pre pull images")
if err := setValidArgs(clusterCmd); err != nil {
panic(fmt.Sprintf("Got error with the completion setting"))
}
}
func setValidArgs(cmd *cobra.Command) (err error) {
cmd.ValidArgsFunction = func(cmd *cobra.Command, args []string, toComplete string) (
strings []string, directive cobra.ShellCompDirective) {
versionArray := []string{"v2.1.1", "v3.0.0", time.Now().Add(-time.Hour * 24).Format("nightly-20060102")}
return versionArray, cobra.ShellCompDirectiveNoFileComp
}
err = cmd.RegisterFlagCompletionFunc("with-kubernetes", func(cmd *cobra.Command, args []string, toComplete string) (
strings []string, directive cobra.ShellCompDirective) {
return version.SupportedK8sVersionList(), cobra.ShellCompDirectiveNoFileComp
})
return
}

View File

@ -1,6 +1,8 @@
package main
import "github.com/kubesphere/kubekey/cmd"
import (
"github.com/kubesphere/kubekey/cmd"
)
// Using a separate entry-point can reduce the size of the binary file
func main() {

View File

@ -21,6 +21,7 @@ import (
"github.com/kubesphere/kubekey/version"
"github.com/spf13/cobra"
"io"
"strings"
)
var shortVersion bool
@ -59,23 +60,6 @@ func printVersion(short bool) error {
}
func printSupportedK8sVersionList(output io.Writer) (err error) {
_, err = output.Write([]byte(`v1.15.12
v1.16.8
v1.16.10
v1.16.12
v1.16.13
v1.17.0
v1.17.4
v1.17.5
v1.17.6
v1.17.7
v1.17.8
v1.17.9
v1.18.3
v1.18.5
v1.18.6
v1.18.8
v1.19.0
`))
_, err = output.Write([]byte(fmt.Sprintln(strings.Join(version.SupportedK8sVersionList(), "\n"))))
return
}

View File

@ -42,11 +42,11 @@ func ParseClusterCfg(clusterCfgPath, k8sVersion, ksVersion string, ksEnabled boo
objName string
)
if len(clusterCfgPath) == 0 {
user, _ := user.Current()
if user.Username != "root" {
return nil, "", errors.New(fmt.Sprintf("Current user is %s. Please use root!", user.Username))
currentUser, _ := user.Current()
if currentUser.Username != "root" {
return nil, "", errors.New(fmt.Sprintf("Current user is %s. Please use root!", currentUser.Username))
}
clusterCfg, objName = AllinoneCfg(user, k8sVersion, ksVersion, ksEnabled, logger)
clusterCfg, objName = AllinoneCfg(currentUser, k8sVersion, ksVersion, ksEnabled, logger)
} else {
cfg, name, err := ParseCfg(clusterCfgPath, k8sVersion, ksVersion, ksEnabled)
if err != nil {
@ -119,20 +119,22 @@ func ParseCfg(clusterCfgPath, k8sVersion, ksVersion string, ksEnabled bool) (*ku
if ksEnabled {
clusterCfg.Spec.KubeSphere.Enabled = true
switch strings.TrimSpace(ksVersion) {
case "":
clusterCfg.Spec.KubeSphere.Version = "v3.0.0"
clusterCfg.Spec.KubeSphere.Configurations = kubesphere.V3_0_0
case "v3.0.0":
case "v3.0.0", "", "latest":
clusterCfg.Spec.KubeSphere.Version = "v3.0.0"
clusterCfg.Spec.KubeSphere.Configurations = kubesphere.V3_0_0
case "v2.1.1":
clusterCfg.Spec.KubeSphere.Version = "v2.1.1"
clusterCfg.Spec.KubeSphere.Configurations = kubesphere.V2_1_1
case "latest":
clusterCfg.Spec.KubeSphere.Version = "latest"
clusterCfg.Spec.KubeSphere.Configurations = kubesphere.V3_0_0
default:
return nil, "", errors.New(fmt.Sprintf("Unsupported version: %s", strings.TrimSpace(ksVersion)))
// make it be convenient to have a nightly build of KubeSphere
if strings.HasPrefix(ksVersion, "nightly-") {
// this is not the perfect solution here, but it's not necessary to track down the exact version between the
// nightly build and a released. So please keep update it with the latest release here.
clusterCfg.Spec.KubeSphere.Version = ksVersion
clusterCfg.Spec.KubeSphere.Configurations = kubesphere.V3_0_0
} else {
return nil, "", errors.New(fmt.Sprintf("Unsupported version: %s", strings.TrimSpace(ksVersion)))
}
}
}
@ -182,21 +184,24 @@ func AllinoneCfg(user *user.User, k8sVersion, ksVersion string, ksEnabled bool,
if ksEnabled {
allinoneCfg.Spec.KubeSphere.Enabled = true
switch strings.TrimSpace(ksVersion) {
case "":
allinoneCfg.Spec.KubeSphere.Version = "v3.0.0"
allinoneCfg.Spec.KubeSphere.Configurations = kubesphere.V3_0_0
case "v3.0.0":
ksVersion = strings.TrimSpace(ksVersion)
switch ksVersion {
case "v3.0.0", "", "latest":
allinoneCfg.Spec.KubeSphere.Version = "v3.0.0"
allinoneCfg.Spec.KubeSphere.Configurations = kubesphere.V3_0_0
case "v2.1.1":
allinoneCfg.Spec.KubeSphere.Version = "v2.1.1"
allinoneCfg.Spec.KubeSphere.Configurations = kubesphere.V2_1_1
case "latest":
allinoneCfg.Spec.KubeSphere.Version = "latest"
allinoneCfg.Spec.KubeSphere.Configurations = kubesphere.V3_0_0
default:
logger.Fatalf("Unsupported version: %s", strings.TrimSpace(ksVersion))
// make it be convenient to have a nightly build of KubeSphere
if strings.HasPrefix(ksVersion, "nightly-") {
// this is not the perfect solution here, but it's not necessary to track down the exact version between the
// nightly build and a released. So please keep update it with the latest release here.
allinoneCfg.Spec.KubeSphere.Version = ksVersion
allinoneCfg.Spec.KubeSphere.Configurations = kubesphere.V3_0_0
} else {
logger.Fatalf("Unsupported version: %s", strings.TrimSpace(ksVersion))
}
}
}

View File

@ -39,15 +39,9 @@ func DeployKubeSphere(version, repo, kubeconfig string) error {
var kubesphereConfig, installerYaml string
switch version {
case "":
kubesphereConfig = kubesphere.V3_0_0
str, err := kubesphere.GenerateKubeSphereYaml(repo, "v3.0.0")
if err != nil {
return err
}
installerYaml = str
case "v3.0.0", "latest":
case "v3.0.0", "latest", "":
kubesphereConfig = kubesphere.V3_0_0
version = "v3.0.0"
str, err := kubesphere.GenerateKubeSphereYaml(repo, version)
if err != nil {
return err
@ -61,7 +55,19 @@ func DeployKubeSphere(version, repo, kubeconfig string) error {
}
installerYaml = str
default:
return errors.New(fmt.Sprintf("Unsupported version: %s", strings.TrimSpace(version)))
// make it be convenient to have a nightly build of KubeSphere
if strings.HasPrefix(version, "nightly-") {
// this is not the perfect solution here, but it's not necessary to track down the exact version between the
// nightly build and a released. So please keep update it with the latest release here.
kubesphereConfig = kubesphere.V3_0_0
str, err := kubesphere.GenerateKubeSphereYaml(repo, version)
if err != nil {
return err
}
installerYaml = str
} else {
return errors.New(fmt.Sprintf("Unsupported version: %s", strings.TrimSpace(version)))
}
}
b1 := bufio.NewReader(bytes.NewReader([]byte(installerYaml)))

24
version/k8s.go Normal file
View File

@ -0,0 +1,24 @@
package version
// SupportedK8sVersionList returns the supported list of Kubernetes
func SupportedK8sVersionList() []string {
return []string{
"v1.15.12",
"v1.16.8",
"v1.16.10",
"v1.16.12",
"v1.16.13",
"v1.17.0",
"v1.17.4",
"v1.17.5",
"v1.17.6",
"v1.17.7",
"v1.17.8",
"v1.17.9",
"v1.18.3",
"v1.18.5",
"v1.18.6",
"v1.18.8",
"v1.19.0",
}
}