From 0745cd92c2c09599c370660e43019a13fb6d0a49 Mon Sep 17 00:00:00 2001 From: ysicing Date: Tue, 29 Aug 2023 15:07:08 +0800 Subject: [PATCH] feat(devops): update devops init update devops init Signed-off-by: ysicing --- .github/workflows/check.yml | 6 ++ .github/workflows/release.yml | 2 + .github/workflows/test.yml | 3 +- Makefile | 117 ------------------------------- cmd/flags/common.go | 2 + cmd/init.go | 3 - cmd/quickon/quickon.go | 4 -- common/const.go | 6 +- common/func.go | 38 ++++------ common/vars.go | 10 ++- go.mod | 16 ++--- go.sum | 32 ++++----- pkg/cluster/cluster.go | 8 +-- pkg/providers/devops/devops.go | 8 +-- pkg/providers/quickon/quickon.go | 6 +- pkg/quickon/quickon.go | 57 +++++++++------ 16 files changed, 109 insertions(+), 209 deletions(-) delete mode 100644 Makefile diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index c8ec4aca..5a560732 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -35,6 +35,7 @@ jobs: uses: actions/setup-go@v4 with: go-version: ${{ env.GO_VERSION }} + check-latest: true - name: Cache Go Dependencies uses: magnetikonline/action-golang-cache@v4 with: @@ -65,6 +66,7 @@ jobs: uses: actions/setup-go@v4 with: go-version: ${{ env.GO_VERSION }} + check-latest: true - name: Cache Go Dependencies uses: magnetikonline/action-golang-cache@v4 with: @@ -93,6 +95,7 @@ jobs: uses: actions/setup-go@v4 with: go-version: ${{ env.GO_VERSION }} + check-latest: true - name: Cache Go Dependencies uses: magnetikonline/action-golang-cache@v4 with: @@ -116,6 +119,9 @@ jobs: uses: actions/checkout@v3 - name: Setup Golang uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} + check-latest: true - name: Run Coverage run: make coverage - name: Upload Coverage to Codecov diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 11c28ae8..7d6fbb98 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,6 +22,7 @@ jobs: uses: actions/setup-go@v4 with: go-version: ${{ env.GO_VERSION }} + check-latest: true - name: install task run: | echo "install task" @@ -77,6 +78,7 @@ jobs: uses: actions/setup-go@v4 with: go-version: ${{ env.GO_VERSION }} + check-latest: true - name: install task run: | echo "install task" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9479eb9a..f2750134 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,7 +2,7 @@ name: build for test env: # Common versions - GO_VERSION: '1.20' + GO_VERSION: '1.21' TZ: Asia/Shanghai permissions: write-all @@ -39,6 +39,7 @@ jobs: uses: actions/setup-go@v4 with: go-version: ${{ env.GO_VERSION }} + check-latest: true - name: install gox run: | echo "install gox" diff --git a/Makefile b/Makefile deleted file mode 100644 index 6145c9ec..00000000 --- a/Makefile +++ /dev/null @@ -1,117 +0,0 @@ -########################################### -.EXPORT_ALL_VARIABLES: -VERSION_PKG := github.com/easysoft/qcadmin/common -ROOT_DIR := $(CURDIR) -BUILD_DIR := $(ROOT_DIR)/_output -BIN_DIR := $(BUILD_DIR)/bin -LOCAL_OS := $(shell go version | awk '{print \$NF}') - -GO111MODULE = on -GOPROXY = https://goproxy.cn,direct -GOSUMDB = sum.golang.google.cn - -BUILD_RELEASE ?= v$(shell cat VERSION || echo "0.0.1") -BUILD_DATE := $(shell date "+%Y%m%d") -GIT_BRANCH := $(shell git branch -r --contains | head -1 | sed -E -e "s%(HEAD ->|origin|upstream)/?%%g" | xargs) -GIT_COMMIT := $(shell git rev-parse --short HEAD || echo "abcdefgh") -APP_VERSION := ${BUILD_RELEASE}-${BUILD_DATE}-${GIT_COMMIT} - -LDFLAGS := "-w -s \ - -X '$(VERSION_PKG).Version=$(BUILD_RELEASE)' \ - -X '$(VERSION_PKG).BuildDate=$(BUILD_DATE)' \ - -X '$(VERSION_PKG).GitCommitHash=$(GIT_COMMIT)' \ - -X 'k8s.io/client-go/pkg/version.gitVersion=${BUILD_RELEASE}' \ - -X 'k8s.io/client-go/pkg/version.gitCommit=${GIT_COMMIT}' \ - -X 'k8s.io/client-go/pkg/version.gitTreeState=dirty' \ - -X 'k8s.io/client-go/pkg/version.buildDate=${BUILD_DATE}' \ - -X 'k8s.io/client-go/pkg/version.gitMajor=1' \ - -X 'k8s.io/client-go/pkg/version.gitMinor=24' \ - -X 'k8s.io/component-base/version.gitVersion=${BUILD_RELEASE}' \ - -X 'k8s.io/component-base/version.gitCommit=${GIT_COMMIT}' \ - -X 'k8s.io/component-base/version.gitTreeState=dirty' \ - -X 'k8s.io/component-base/version.gitMajor=1' \ - -X 'k8s.io/component-base/version.gitMinor=24' \ - -X 'k8s.io/component-base/version.buildDate=${BUILD_DATE}'" - -########################################################################## - -help: ## this help - @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) - -gencopyright: ## add copyright - @bash hack/scripts/gencopyright.sh - -doc: ## gen docs - rm -rf ./docs/*.md - go run ./docs/docs.go - cp -a README.md docs/index.md - -fmt: ## fmt code - gofmt -s -w . - goimports -w . - @echo gofmt -l - @OUTPUT=`gofmt -l . 2>&1`; \ - if [ "$$OUTPUT" ]; then \ - echo "gofmt must be run on the following files:"; \ - echo "$$OUTPUT"; \ - exit 1; \ - fi - -lint: ## lint code - @echo golangci-lint run -v ./... - @OUTPUT=`command -v golangci-lint >/dev/null 2>&1 && golangci-lint run -v ./... 2>&1`; \ - if [ "$$OUTPUT" ]; then \ - echo "go lint errors:"; \ - echo "$$OUTPUT"; \ - fi - -default: gencopyright fmt lint ## fmt code - -coverage: generate ## coverage - go test -race -failfast -coverprofile=coverage.out -covermode=atomic `go list ./... | grep -vE '(internal/static)'` - -build: ## build binary - @echo "build bin ${GIT_VERSION} $(GIT_COMMIT) $(GIT_BRANCH) $(BUILD_DATE) $(GIT_TREE_STATE)" - @GO_ENABLED=1 gox -osarch="linux/amd64 linux/arm64" \ - -output="dist/{{.Dir}}_{{.OS}}_{{.Arch}}" \ - -ldflags ${LDFLAGS} - -generate: ## generate - go generate ./... - -dev: generate ## dev test - GO_ENABLED=1 gox -osarch="linux/amd64" \ - -output="dist/{{.Dir}}_{{.OS}}_{{.Arch}}" \ - -ldflags ${LDFLAGS} - -local: ## dev test - GO_ENABLED=1 gox -osarch="darwin/arm64" -output="dist/{{.Dir}}_{{.OS}}_{{.Arch}}" -ldflags ${LDFLAGS} - -clean: ## clean - rm -rf dist - -upx: ## upx - upx dist/* - -fixme: ## fixme check - grep -rnw "FIXME" internal - -todo: ## todo check - grep -rnw "TODO" internal - -# Legacy code should be removed by the time of release -legacy: # legacy code check - grep -rnw "\(LEGACY\|Deprecated\)" internal - -.PHONY : build prod-docker dev-push clean - -snapshot: ## local test goreleaser - goreleaser release --snapshot --clean --skip-publish - -fix-version: - @echo "fix version" - cat examples/sonar-project.properties.example | sed "s#2.0.0#${APP_VERSION}#g" > sonar-project.properties - -fix-local-version: - @echo "fix version" - cat examples/sonar-project.properties.example | sed "s#2.0.0#${APP_VERSION}#g" | sed "s#quickon#pangu#g" > sonar-project.properties diff --git a/cmd/flags/common.go b/cmd/flags/common.go index 26a76039..497e9b08 100644 --- a/cmd/flags/common.go +++ b/cmd/flags/common.go @@ -12,6 +12,7 @@ import ( "os" "strings" + "github.com/davecgh/go-spew/spew" "github.com/easysoft/qcadmin/internal/pkg/types" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -66,6 +67,7 @@ func ConvertFlags(cmd *cobra.Command, fs []types.Flag) *pflag.FlagSet { case int: pf.IntVar(f.P.(*int), f.Name, t, f.Usage) default: + spew.Dump(t) continue } if f.Required { diff --git a/cmd/init.go b/cmd/init.go index 3e1a72a6..0bdc1e47 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -112,9 +112,6 @@ func newCmdInit(f factory.Factory) *cobra.Command { log.Errorf("init quickon failed, reason: %v", err) return } - if !meta.QuickonOSS { - meta.QuickonType = common.QuickonEEType - } if len(meta.IP) == 0 { // TODO fix ip, not allow PublicIP cfg, _ := config.LoadConfig() diff --git a/cmd/quickon/quickon.go b/cmd/quickon/quickon.go index 25ed39fe..3d5b3830 100644 --- a/cmd/quickon/quickon.go +++ b/cmd/quickon/quickon.go @@ -8,7 +8,6 @@ package quickon import ( "github.com/easysoft/qcadmin/cmd/flags" - "github.com/easysoft/qcadmin/common" "github.com/easysoft/qcadmin/internal/app/config" "github.com/easysoft/qcadmin/internal/pkg/types" "github.com/easysoft/qcadmin/internal/pkg/util/factory" @@ -55,9 +54,6 @@ func InitCommand(f factory.Factory) *cobra.Command { } initCmd.RunE = func(cmd *cobra.Command, args []string) error { - if !meta.QuickonOSS { - meta.QuickonType = common.QuickonEEType - } if err := cp.GetKubeClient(); err != nil { return err } diff --git a/common/const.go b/common/const.go index 76832128..a28713ab 100644 --- a/common/const.go +++ b/common/const.go @@ -64,7 +64,10 @@ const ( const ( DefaultQuickonOSSVersion = "stable-2.6" // 开源版本 DefaultQuickonEEVersion = "stable-1.0" - DefaultZentaoDevOPSOSSVersion = "stable-1.0" + DefaultZentaoDevOPSOSSVersion = "18.6" + DefaultZentaoDevOPSMaxVersion = "4.6" + DefaultZentaoDevOPSBizVersion = "8.6" + DefaultZentaoDevOPSIPDVersion = "1.0.1" K3sBinName = "k3s" K3sBinPath = "/usr/local/bin/k3s" HelmBinName = "helm" @@ -94,6 +97,7 @@ const ( DefaultCneOperatorName = "cne-operator" DefaultIngressName = "nginx-ingress-controller" DefaultDBName = "qucheng-mysql" + DefaultKubeAPIDomain = "kubeapi.k7s.local" InitFileName = ".initdone" InitLockFileName = ".qlock" InitModeCluster = ".incluster" diff --git a/common/func.go b/common/func.go index e42dae20..85b09239 100644 --- a/common/func.go +++ b/common/func.go @@ -81,29 +81,26 @@ func GetChannel(p string) string { return p } -// GetVersion 获取chartRepo channel地址 -func GetVersion(p string, qt QuickonType) string { - v := strings.Split(p, "-") +// GetVersion 获取版本地址 +func GetVersion(version string) string { + v := strings.Split(version, "-") if len(v) != 2 { - if qt == QuickonOSSType { - return GetVersion(DefaultQuickonOSSVersion, qt) - } - return GetVersion(DefaultQuickonEEVersion, qt) + return version } return v[1] } // GetZenTaoVersion 获取chartRepo channel地址 -func GetZenTaoVersion(p string, qt QuickonType) string { - v := strings.Split(p, "-") - if len(v) != 2 { - if qt == QuickonOSSType { - return GetVersion(DefaultZentaoDevOPSOSSVersion, qt) - } - return GetVersion(DefaultZentaoDevOPSOSSVersion, qt) - } - return v[1] -} +// func GetZenTaoVersion(p string, qt QuickonType) string { +// v := strings.Split(p, "-") +// if len(v) != 2 { +// if qt == QuickonOSSType { +// return GetVersion(DefaultZentaoDevOPSOSSVersion, qt) +// } +// return GetVersion(DefaultZentaoDevOPSOSSVersion, qt) +// } +// return v[1] +// } func GetDefaultConfig() string { home := zos.GetHomeDir() @@ -181,13 +178,6 @@ func GetDefaultQuickONNamespace() []string { return ns } -func GetQuickONName(devops bool, t QuickonType) string { - if t == QuickonOSSType { - return GetReleaseName(devops) - } - return fmt.Sprintf("%s-biz", GetReleaseName(devops)) -} - func GetCustomScripts(path string) string { return fmt.Sprintf("%s/%s", GetDefaultDataDir(), path) } diff --git a/common/vars.go b/common/vars.go index 07e71682..ccc2f213 100644 --- a/common/vars.go +++ b/common/vars.go @@ -23,10 +23,16 @@ type cloudAPIS struct { type QuickonType string var ( - QuickonOSSType QuickonType = "oss" // 开源版 - QuickonEEType QuickonType = "ee" // 企业版 + ZenTaoOSSType QuickonType = "oss" // 开源版 + ZenTaoMaxType QuickonType = "max" // 旗舰版 + ZenTaoBizType QuickonType = "biz" // 企业版 + ZenTaoIPDType QuickonType = "ipd" // IPD版 ) +func (q QuickonType) String() string { + return string(q) +} + type InstallType string var ( diff --git a/go.mod b/go.mod index d9caf426..bbd59c76 100644 --- a/go.mod +++ b/go.mod @@ -47,13 +47,13 @@ require ( gopkg.in/natefinch/lumberjack.v2 v2.2.1 gotest.tools v2.2.0+incompatible helm.sh/helm/v3 v3.12.3 - k8s.io/api v0.28.0 - k8s.io/apimachinery v0.28.0 - k8s.io/cli-runtime v0.28.0 - k8s.io/client-go v0.28.0 - k8s.io/component-base v0.28.0 - k8s.io/kubectl v0.28.0 - k8s.io/metrics v0.28.0 + k8s.io/api v0.28.1 + k8s.io/apimachinery v0.28.1 + k8s.io/cli-runtime v0.28.1 + k8s.io/client-go v0.28.1 + k8s.io/component-base v0.28.1 + k8s.io/kubectl v0.28.1 + k8s.io/metrics v0.28.1 k8s.io/system-validators v1.7.0 k8s.io/utils v0.0.0-20230726121419-3b25d923346b sigs.k8s.io/yaml v1.3.0 @@ -217,7 +217,7 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/apiextensions-apiserver v0.28.0 // indirect k8s.io/apiserver v0.28.0 // indirect - k8s.io/component-helpers v0.28.0 // indirect + k8s.io/component-helpers v0.28.1 // indirect k8s.io/klog/v2 v2.100.1 // indirect k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect oras.land/oras-go v1.2.3 // indirect diff --git a/go.sum b/go.sum index 27b955c3..7147400b 100644 --- a/go.sum +++ b/go.sum @@ -1299,30 +1299,30 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= -k8s.io/api v0.28.0 h1:3j3VPWmN9tTDI68NETBWlDiA9qOiGJ7sdKeufehBYsM= -k8s.io/api v0.28.0/go.mod h1:0l8NZJzB0i/etuWnIXcwfIv+xnDOhL3lLW919AWYDuY= +k8s.io/api v0.28.1 h1:i+0O8k2NPBCPYaMB+uCkseEbawEt/eFaiRqUx8aB108= +k8s.io/api v0.28.1/go.mod h1:uBYwID+66wiL28Kn2tBjBYQdEU0Xk0z5qF8bIBqk/Dg= k8s.io/apiextensions-apiserver v0.28.0 h1:CszgmBL8CizEnj4sj7/PtLGey6Na3YgWyGCPONv7E9E= k8s.io/apiextensions-apiserver v0.28.0/go.mod h1:uRdYiwIuu0SyqJKriKmqEN2jThIJPhVmOWETm8ud1VE= -k8s.io/apimachinery v0.28.0 h1:ScHS2AG16UlYWk63r46oU3D5y54T53cVI5mMJwwqFNA= -k8s.io/apimachinery v0.28.0/go.mod h1:X0xh/chESs2hP9koe+SdIAcXWcQ+RM5hy0ZynB+yEvw= +k8s.io/apimachinery v0.28.1 h1:EJD40og3GizBSV3mkIoXQBsws32okPOy+MkRyzh6nPY= +k8s.io/apimachinery v0.28.1/go.mod h1:X0xh/chESs2hP9koe+SdIAcXWcQ+RM5hy0ZynB+yEvw= k8s.io/apiserver v0.28.0 h1:wVh7bK6Xj7hq+5ntInysTeQRAOqqFoKGUOW2yj8DXrY= k8s.io/apiserver v0.28.0/go.mod h1:MvLmtxhQ0Tb1SZk4hfJBjs8iqr5nhYeaFSaoEcz7Lk4= -k8s.io/cli-runtime v0.28.0 h1:Tcz1nnccXZDNIzoH6EwjCs+7ezkUGhorzCweEvlVOFg= -k8s.io/cli-runtime v0.28.0/go.mod h1:U+ySmOKBm/JUCmebhmecXeTwNN1RzI7DW4+OM8Oryas= -k8s.io/client-go v0.28.0 h1:ebcPRDZsCjpj62+cMk1eGNX1QkMdRmQ6lmz5BLoFWeM= -k8s.io/client-go v0.28.0/go.mod h1:0Asy9Xt3U98RypWJmU1ZrRAGKhP6NqDPmptlAzK2kMc= -k8s.io/component-base v0.28.0 h1:HQKy1enJrOeJlTlN4a6dU09wtmXaUvThC0irImfqyxI= -k8s.io/component-base v0.28.0/go.mod h1:Yyf3+ZypLfMydVzuLBqJ5V7Kx6WwDr/5cN+dFjw1FNk= -k8s.io/component-helpers v0.28.0 h1:ubHUiEF7H/DOx4471pHHsLlH3EGu8jlEvnld5PS4KdI= -k8s.io/component-helpers v0.28.0/go.mod h1:i7hJ/oFhZImqUWwjLFG/yGkLpJ3KFoirY2DLYIMql6Q= +k8s.io/cli-runtime v0.28.1 h1:7Njc4eD5kaO4tYdSYVJJEs54koYD/vT6gxOq8dEVf9g= +k8s.io/cli-runtime v0.28.1/go.mod h1:yIThSWkAVLqeRs74CMkq6lNFW42GyJmvMtcNn01SZho= +k8s.io/client-go v0.28.1 h1:pRhMzB8HyLfVwpngWKE8hDcXRqifh1ga2Z/PU9SXVK8= +k8s.io/client-go v0.28.1/go.mod h1:pEZA3FqOsVkCc07pFVzK076R+P/eXqsgx5zuuRWukNE= +k8s.io/component-base v0.28.1 h1:LA4AujMlK2mr0tZbQDZkjWbdhTV5bRyEyAFe0TJxlWg= +k8s.io/component-base v0.28.1/go.mod h1:jI11OyhbX21Qtbav7JkhehyBsIRfnO8oEgoAR12ArIU= +k8s.io/component-helpers v0.28.1 h1:ts/vykhyUmPLhUl/hdLdf+a4BWA0giQ3f25HAIhl+RI= +k8s.io/component-helpers v0.28.1/go.mod h1:rHFPj33uXNbgppg+ilmjJ4oR73prZQNRRmg+utVOAb0= k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg= k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 h1:LyMgNKD2P8Wn1iAwQU5OhxCKlKJy0sHc+PcDwFB24dQ= k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9/go.mod h1:wZK2AVp1uHCp4VamDVgBP2COHZjqD1T68Rf0CM3YjSM= -k8s.io/kubectl v0.28.0 h1:qhfju0OaU+JGeBlToPeeIg2UJUWP++QwTkpio6nlPKg= -k8s.io/kubectl v0.28.0/go.mod h1:1We+E5nSX3/TVoSQ6y5Bzld5OhTBHZHlKEYl7g/NaTk= -k8s.io/metrics v0.28.0 h1:rO+zfTT2A5GvCdRD44vFAQgdz8Sa6OMsNYkEGpBQz0k= -k8s.io/metrics v0.28.0/go.mod h1:0RSSFOwf1qlDU54bLMDEDa81cz02mNlG4mxitIRsQCs= +k8s.io/kubectl v0.28.1 h1:jAq4yKEqQL+fwkWcEsUWxhJ7uIRcOYQraJxx4SyAMTY= +k8s.io/kubectl v0.28.1/go.mod h1:a0nk/lMMeKBulp0lMTJAKbkjZg1ykqfLfz/d6dnv1ak= +k8s.io/metrics v0.28.1 h1:Q0AsAEZKlAzhqrvfoGyHjz2qAFlef0SqfGJ1YWJ+ITU= +k8s.io/metrics v0.28.1/go.mod h1:8lKkAajigcZWu0o9XCEBr++YVCzT48q1ck+f9CEBhZY= k8s.io/system-validators v1.7.0 h1:tYD3hojdYc58CKtiEsh7BWW6Pg0x6xbclUiwjaIiiYo= k8s.io/system-validators v1.7.0/go.mod h1:gP1Ky+R9wtrSiFbrpEPwWMeYz9yqyy1S/KOh0Vci7WI= k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI= diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index 564d6173..dbda2f0b 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -234,10 +234,10 @@ func (c *Cluster) preinit(mip, ip string, sshClient ssh.Interface) error { c.log.StopWait() c.log.Donef("%s run init script success", ip) // add master0 ip - hostsArgs := fmt.Sprintf("/usr/bin/qcadmin exp tools hosts add --domain kubeapi.k7s.local --ip %s", mip) + hostsArgs := fmt.Sprintf("/usr/bin/qcadmin exp tools hosts add --domain %s --ip %s", common.DefaultKubeAPIDomain, mip) if err := sshClient.CmdAsync(ip, hostsArgs); err != nil { c.log.Debugf("cmd: %s", hostsArgs) - return errors.Errorf("%s add master0 (kubeapi.k7s.local --> %s) failed, reason: %v", ip, mip, err) + return errors.Errorf("%s add master0 (%s --> %s) failed, reason: %v", ip, common.DefaultKubeAPIDomain, mip, err) } if err := sshClient.CmdAsync(ip, common.GetCustomScripts("hack/manifests/scripts/node.sh")); err != nil { return errors.Errorf("%s run init script failed, reason: %v", ip, err) @@ -250,7 +250,7 @@ func (c *Cluster) initMaster0(cfg *config.Config, sshClient ssh.Interface) error k3sargs := k3stpl.K3sArgs{ Master0: true, TypeMaster: true, - KubeAPI: "kubeapi.k7s.local", + KubeAPI: common.DefaultKubeAPIDomain, KubeToken: expass.PwGenAlphaNum(16), DataDir: c.DataDir, PodCIDR: c.PodCIDR, @@ -338,7 +338,7 @@ func (c *Cluster) joinNode(ip string, master bool, cfg *config.Config, sshClient Master0: false, TypeMaster: master, CNI: cfg.Cluster.CNI, - KubeAPI: "kubeapi.k7s.local", + KubeAPI: common.DefaultKubeAPIDomain, KubeToken: cfg.Cluster.Token, DataDir: cfg.DataDir, PodCIDR: cfg.Cluster.PodCIDR, diff --git a/pkg/providers/devops/devops.go b/pkg/providers/devops/devops.go index df89b3ab..ddb30539 100644 --- a/pkg/providers/devops/devops.go +++ b/pkg/providers/devops/devops.go @@ -35,10 +35,10 @@ func init() { func newProvider() *Devops { return &Devops{ MetaData: &quickon.Meta{ - Log: log.GetInstance(), - DevopsMode: true, - QuickonType: common.QuickonOSSType, - Version: common.GetZenTaoVersion("", common.QuickonOSSType), + Log: log.GetInstance(), + DevopsMode: true, + Type: common.ZenTaoOSSType.String(), + Version: common.DefaultZentaoDevOPSOSSVersion, }, } } diff --git a/pkg/providers/quickon/quickon.go b/pkg/providers/quickon/quickon.go index 9a137519..63d15128 100644 --- a/pkg/providers/quickon/quickon.go +++ b/pkg/providers/quickon/quickon.go @@ -42,8 +42,8 @@ func newProvider() *Quickon { Log: log.GetInstance(), DevopsMode: false, ConsolePassword: expass.PwGenAlphaNum(32), - QuickonType: common.QuickonOSSType, - Version: common.GetVersion("", common.QuickonOSSType), + Type: common.ZenTaoOSSType.String(), + Version: common.DefaultQuickonOSSVersion, App: "zentao", }, } @@ -62,7 +62,7 @@ func (q *Quickon) GetFlags() []types.Flag { V: q.MetaData.ConsolePassword, }, types.Flag{ Name: "version", - Usage: fmt.Sprintf("quickon version(oss: %s/ee: %s)", common.DefaultQuickonOSSVersion, common.DefaultQuickonEEVersion), + Usage: "quickon version", P: &q.MetaData.Version, V: q.MetaData.Version, }, types.Flag{ diff --git a/pkg/quickon/quickon.go b/pkg/quickon/quickon.go index 53b7ece7..ebaf72c9 100644 --- a/pkg/quickon/quickon.go +++ b/pkg/quickon/quickon.go @@ -43,8 +43,7 @@ type Meta struct { ConsolePassword string DevopsMode bool OffLine bool - QuickonOSS bool - QuickonType common.QuickonType + Type string App string kubeClient *k8s.Client Log log.Logger @@ -55,7 +54,7 @@ func New(f factory.Factory) *Meta { Log: f.GetLog(), // Version: common.DefaultQuickonOSSVersion, ConsolePassword: expass.PwGenAlphaNum(32), - QuickonType: common.QuickonOSSType, + Type: common.ZenTaoOSSType.String(), } } @@ -75,10 +74,11 @@ func (m *Meta) GetCustomFlags() []types.Flag { Hidden: true, }, { - Name: "oss", - Usage: "type, oss or ee, default: oss", - P: &m.QuickonOSS, - V: m.QuickonType == common.QuickonOSSType, + Name: "type", + Usage: "type", + P: &m.Type, + V: common.ZenTaoOSSType.String(), + ShortHand: "t", }, { Name: "offline", @@ -215,17 +215,16 @@ func (m *Meta) Init() error { return err } } - m.Log.Debugf("version: %v, type: %v", m.Version, m.QuickonType) - chartVersion := common.GetVersion(m.Version, m.QuickonType) + m.Log.Debugf("version: %v, type: %v", m.Version, m.Type) + if m.DevopsMode { // TODO: 获取zentao devops chart version - chartVersion = common.GetZenTaoVersion(m.Version, m.QuickonType) - m.Log.Debugf("start init zentao devops, version: %s", chartVersion) - cfg.Quickon.Type = m.QuickonType + m.Log.Debugf("start init zentao devops") + cfg.Quickon.Type = common.QuickonType(m.Type) cfg.Quickon.DevOps = true } else { - m.Log.Debugf("start init quickon %v, version: %s", m.QuickonType, chartVersion) - cfg.Quickon.Type = m.QuickonType + m.Log.Debugf("start init quickon") + cfg.Quickon.Type = common.QuickonType(m.Type) } if m.Domain == "" { err := retry.Retry(time.Second*1, 3, func() (bool, error) { @@ -310,7 +309,7 @@ func (m *Meta) Init() error { } helmchan := common.GetChannel(m.Version) - helmargs := []string{"experimental", "helm", "upgrade", "--name", common.DefaultQuchengName, "--repo", common.DefaultHelmRepoName, "--chart", common.GetQuickONName(m.DevopsMode, m.QuickonType), "--namespace", common.GetDefaultSystemNamespace(true), "--set", "env.APP_DOMAIN=" + m.Domain, "--set", "env.CNE_API_TOKEN=" + token, "--set", "cloud.defaultChannel=" + helmchan} + helmargs := []string{"experimental", "helm", "upgrade", "--name", common.GetReleaseName(m.DevopsMode), "--repo", common.DefaultHelmRepoName, "--chart", common.GetReleaseName(m.DevopsMode), "--namespace", common.GetDefaultSystemNamespace(true), "--set", "env.APP_DOMAIN=" + m.Domain, "--set", "env.CNE_API_TOKEN=" + token, "--set", "cloud.defaultChannel=" + helmchan} if helmchan != "stable" { helmargs = append(helmargs, "--set", "env.PHP_DEBUG=2") helmargs = append(helmargs, "--set", "cloud.switchChannel=true") @@ -336,9 +335,23 @@ func (m *Meta) Init() error { } helmargs = append(helmargs, "--set", fmt.Sprintf("ingress.host=%s", hostdomain)) - - if len(chartVersion) > 0 { - helmargs = append(helmargs, "--version", chartVersion) + installVersion := common.GetVersion(m.Version) + if m.DevopsMode { + // 指定类型 + helmargs = append(helmargs, "--set", fmt.Sprintf("deploy.product=%s", m.Type)) + // 指定版本 + deployVersion := fmt.Sprintf("deploy.versions.%s=%s.k8s", m.Type, installVersion) + if m.Type == common.ZenTaoOSSType.String() { + deployVersion = fmt.Sprintf("deploy.versions.%s=%s", m.Type, installVersion) + } + helmargs = append(helmargs, "--set", deployVersion) + if helmchan != "stable" { + helmargs = append(helmargs, "--set", "image.repository=test/zentao") + } + } else { + if len(installVersion) > 0 { + helmargs = append(helmargs, "--version", installVersion) + } } output, err := qcexec.Command(os.Args[0], helmargs...).CombinedOutput() @@ -346,10 +359,10 @@ func (m *Meta) Init() error { m.Log.Errorf("upgrade install web failed: %s", string(output)) return err } - m.Log.Donef("install %s success", common.GetQuickONName(m.DevopsMode, m.QuickonType)) + m.Log.Donef("install %s success", common.GetReleaseName(m.DevopsMode)) if m.OffLine { // patch quickon - cmfileName := fmt.Sprintf("%s-%s-files", common.DefaultQuchengName, common.GetQuickONName(m.DevopsMode, m.QuickonType)) + cmfileName := fmt.Sprintf("%s-%s-files", common.DefaultQuchengName, common.GetReleaseName(m.DevopsMode)) m.Log.Debugf("fetch quickon files from %s", cmfileName) for i := 0; i < 20; i++ { time.Sleep(5 * time.Second) @@ -374,11 +387,11 @@ repositories: } // 重建pod pods, _ := m.kubeClient.ListPods(ctx, common.GetDefaultSystemNamespace(true), metav1.ListOptions{}) - podName := fmt.Sprintf("%s-%s", common.DefaultQuchengName, common.GetQuickONName(m.DevopsMode, m.QuickonType)) + podName := fmt.Sprintf("%s-%s", common.DefaultQuchengName, common.GetReleaseName(m.DevopsMode)) for _, pod := range pods.Items { if strings.HasPrefix(pod.Name, podName) { if err := m.kubeClient.DeletePod(ctx, pod.Name, common.GetDefaultSystemNamespace(true), metav1.DeleteOptions{}); err != nil { - m.Log.Warnf("recreate %s pods", common.GetQuickONName(m.DevopsMode, m.QuickonType)) + m.Log.Warnf("recreate %s pods", common.GetReleaseName(m.DevopsMode)) } } }