Skip to content

Commit

Permalink
feat(version): support qucheng 1.1.1 (#39)
Browse files Browse the repository at this point in the history
feat(version): support qucheng 1.1.1
  • Loading branch information
ysicing authored Jul 18, 2022
1 parent dc9137c commit 14a4598
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ build: ## build binary
generate: ## generate
go generate ./...

dev: ## dev test
dev: generate ## dev test
GO_ENABLED=1 gox -osarch="linux/amd64" \
-output="dist/{{.Dir}}_{{.OS}}_{{.Arch}}" \
-ldflags ${LDFLAGS}
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.7
1.0.8
3 changes: 2 additions & 1 deletion cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import (
func newCmdUpgrade(f factory.Factory) *cobra.Command {
up := &cobra.Command{
Use: "upgrade",
Short: "Upgrades the Q CLI to the newest version",
Short: "Upgrades the Qucheng cli or plugin to the newest version",
Aliases: []string{"ug", "ugc"},
}
up.AddCommand(upgrade.NewUpgradeQ(f))
up.AddCommand(upgrade.NewUpgradeOperator(f))
return up
}
38 changes: 38 additions & 0 deletions cmd/upgrade/operator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) 2021-2022 北京渠成软件有限公司(Beijing Qucheng Software Co., Ltd. www.qucheng.com) All rights reserved.
// Use of this source code is covered by the following dual licenses:
// (1) Z PUBLIC LICENSE 1.2 (ZPL 1.2)
// (2) Affero General Public License 3.0 (AGPL 3.0)
// license that can be found in the LICENSE file.

package upgrade

import (
"os"

qcexec "github.com/easysoft/qcadmin/internal/pkg/util/exec"
"github.com/easysoft/qcadmin/internal/pkg/util/factory"
"github.com/spf13/cobra"
)

func NewUpgradeOperator(f factory.Factory) *cobra.Command {
up := option{
log: f.GetLog(),
}
upq := &cobra.Command{
Use: "operator",
Short: "upgrade operator to the newest version",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
up.DoOperator()
},
}
return upq
}

func (up option) DoOperator() {
qcexec.CommandRun(os.Args[0], "manage", "plugins", "sync")
if err := qcexec.CommandRun(os.Args[0], "manage", "plugins", "enable", "cne-operator"); err != nil {
up.log.Errorf("upgrade plugin cne-operator err: %v", err)
return
}
}
49 changes: 24 additions & 25 deletions common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,30 @@ const (
)

const (
DefaultQuchengVersion = "stable-1.1.0"
K3sBinName = "k3s"
K3sBinPath = "/usr/local/bin/k3s"
HelmBinName = "helm"
HelmBinPath = "/usr/local/bin/helm"
K3sBinVersion = "v1.23.5+k3s1"
K3sBinURL = "https://github.com/k3s-io/k3s/releases/download"
K3sAgentEnv = "/etc/systemd/system/k3s-agent.service.env"
K3sKubeConfig = "/etc/rancher/k3s/k3s.yaml"
KubeQPS = 5.0
KubeBurst = 10
KubectlBinPath = "/usr/local/bin/kubectl"
QcAdminBinPath = "/usr/local/bin/qcadmin"
StatusWaitDuration = 5 * time.Minute
WaitRetryInterval = 5 * time.Second
DefaultHelmRepoName = "install"
DefaultSystem = "cne-system"
DefaultChartName = "qucheng"
DefaultAPIChartName = "cne-api"
DefaultQuchengName = "qucheng"
DefaultCneAPIName = "cne-api"
DefaultDBName = "qucheng-mysql"
InitFileName = ".initdone"
InitLockFileName = ".qlock"
InitModeCluster = ".incluster"
DefaultQuchengVersion = "stable-1.1.1"
K3sBinName = "k3s"
K3sBinPath = "/usr/local/bin/k3s"
HelmBinName = "helm"
HelmBinPath = "/usr/local/bin/helm"
K3sBinVersion = "v1.23.8+k3s1"
K3sBinURL = "https://github.com/k3s-io/k3s/releases/download"
K3sAgentEnv = "/etc/systemd/system/k3s-agent.service.env"
K3sKubeConfig = "/etc/rancher/k3s/k3s.yaml"
KubeQPS = 5.0
KubeBurst = 10
KubectlBinPath = "/usr/local/bin/kubectl"
QcAdminBinPath = "/usr/local/bin/qcadmin"
StatusWaitDuration = 5 * time.Minute
WaitRetryInterval = 5 * time.Second
DefaultHelmRepoName = "install"
DefaultSystem = "cne-system"
DefaultQuchengName = "qucheng"
DefaultCneOperatorName = "cne-operator"
DefaultIngressName = "nginx-ingress-controller"
DefaultDBName = "qucheng-mysql"
InitFileName = ".initdone"
InitLockFileName = ".qlock"
InitModeCluster = ".incluster"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions hack/manifests/plugins/plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@
{
"name": "cne-operator",
"description": "渠成云原生应用交付平台控制器",
"version": "0.1.0",
"version": "1.1.1",
"home": "https://www.qucheng.com",
"appversion": "0.1.0",
"appversion": "1.1.1",
"path": "cne-operator",
"tool": "helm",
"builtin": true
Expand Down
8 changes: 1 addition & 7 deletions internal/pkg/cluster/qucheng.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (p *Cluster) InstallQuCheng() error {
}
helmchan := common.GetChannel(p.QuchengVersion)
// helm upgrade -i nginx-ingress-controller bitnami/nginx-ingress-controller -n kube-system
helmargs := []string{"experimental", "helm", "upgrade", "--name", common.DefaultChartName, "--repo", common.DefaultHelmRepoName, "--chart", common.DefaultChartName, "--namespace", common.DefaultSystem, "--set", fmt.Sprintf("ingress.host=console.%s", p.Domain), "--set", "env.APP_DOMAIN=" + p.Domain, "--set", "env.CNE_API_TOKEN=" + token, "--set", "cloud.defaultChannel=" + helmchan}
helmargs := []string{"experimental", "helm", "upgrade", "--name", common.DefaultQuchengName, "--repo", common.DefaultHelmRepoName, "--chart", common.DefaultQuchengName, "--namespace", common.DefaultSystem, "--set", fmt.Sprintf("ingress.host=console.%s", p.Domain), "--set", "env.APP_DOMAIN=" + p.Domain, "--set", "env.CNE_API_TOKEN=" + token, "--set", "cloud.defaultChannel=" + helmchan}
if helmchan != "stable" {
helmargs = append(helmargs, "--set", "env.PHP_DEBUG=2")
}
Expand All @@ -156,12 +156,6 @@ func (p *Cluster) InstallQuCheng() error {
p.Log.Errorf("upgrade install qucheng web failed: %s", string(output))
return err
}
// Deprecated CNE_API_TOKEN
// output, err = qcexec.Command(os.Args[0], "experimental", "helm", "upgrade", "--name", common.DefaultCneAPIName, "--repo", common.DefaultHelmRepoName, "--chart", common.DefaultAPIChartName, "--namespace", common.DefaultSystem, "--set", "env.CNE_TOKEN="+token, "--set", "env.CNE_API_TOKEN="+token, "--set", "cloud.defaultChannel="+common.GetChannel(p.QuchengVersion)).CombinedOutput()
// if err != nil {
// p.Log.Errorf("upgrade install qucheng api failed: %s", string(output))
// return err
// }
p.Log.Done("install qucheng done")
p.Ready()
initfile := common.GetCustomConfig(common.InitFileName)
Expand Down
46 changes: 33 additions & 13 deletions internal/pkg/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"os"
"strings"

gv "github.com/Masterminds/semver/v3"
"github.com/easysoft/qcadmin/common"
qcexec "github.com/easysoft/qcadmin/internal/pkg/util/exec"
"github.com/easysoft/qcadmin/internal/pkg/util/log"
Expand Down Expand Up @@ -131,14 +132,23 @@ func (p *Item) UnInstall() error {

func (p *Item) Install() error {
pluginName := fmt.Sprintf("qc-plugin-%s", p.Type)
_, err := p.Client.GetSecret(context.TODO(), common.DefaultSystem, pluginName, metav1.GetOptions{})
oldSecret, err := p.Client.GetSecret(context.TODO(), common.DefaultSystem, pluginName, metav1.GetOptions{})
updatestatus := false
if err == nil {
p.log.Warnf("plugin %s is already installed", p.Type)
return nil
}
if !errors.IsNotFound(err) {
p.log.Debugf("get plugin secret failed: %v", err)
return fmt.Errorf("plugin %s install failed", p.Name)
nowversion := gv.MustParse(strings.TrimPrefix(p.Version, "v"))
oldversion := string(oldSecret.Data["version"])
p.log.Debugf("type: %s, old version: %s, now version: %s", p.Type, oldversion, nowversion)
needupgrade := nowversion.GreaterThan(gv.MustParse(oldversion))
if !needupgrade {
p.log.Warnf("plugin %s is the latest version", p.Type)
return nil
}
updatestatus = true
} else {
if !errors.IsNotFound(err) {
p.log.Debugf("get plugin secret failed: %v", err)
return fmt.Errorf("plugin %s install failed", p.Name)
}
}
if p.Tool == "helm" {
applycmd := qcexec.Command(os.Args[0], "experimental", "helm", "upgrade", "--name", p.Type, "--repo", common.DefaultHelmRepoName, "--chart", p.Path, "--namespace", common.DefaultSystem)
Expand All @@ -162,11 +172,21 @@ func (p *Item) Install() error {
"version": p.Version,
"cliversion": common.Version,
}
_, err = p.Client.CreateSecret(context.TODO(), common.DefaultSystem, &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: pluginName,
},
StringData: plugindata,
}, metav1.CreateOptions{})
if updatestatus {
_, err = p.Client.UpdateSecret(context.TODO(), common.DefaultSystem, &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: pluginName,
},
StringData: plugindata,
}, metav1.UpdateOptions{})
} else {
_, err = p.Client.CreateSecret(context.TODO(), common.DefaultSystem, &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: pluginName,
},
StringData: plugindata,
}, metav1.CreateOptions{})
}

return err
}
7 changes: 5 additions & 2 deletions internal/pkg/status/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ func (k *K8sStatusCollector) quchengStatus(ctx context.Context, status *Status)
k.deploymentStatus(ctx, "kube-system", "local-path-provisioner", "k8s", status)
// 业务层
k.deploymentStatus(ctx, common.DefaultSystem, common.DefaultQuchengName, "", status)
// 平台层
// k.deploymentStatus(ctx, common.DefaultSystem, common.DefaultCneAPIName, "", status)
// 数据库
k.deploymentStatus(ctx, common.DefaultSystem, common.DefaultDBName, "", status)

Expand All @@ -173,6 +171,11 @@ func (k *K8sStatusCollector) quchengPluginStatus(ctx context.Context, p plugin.M
stateCount.Disabled = true
} else {
stateCount.Disabled = false
if p.Type == "ingress" {
k.deploymentStatus(ctx, common.DefaultSystem, common.DefaultIngressName, "", status)
} else if p.Type == "cne-operator" {
k.deploymentStatus(ctx, common.DefaultSystem, common.DefaultCneOperatorName, "", status)
}
}
status.QStatus.PluginState[p.Type] = stateCount
return nil
Expand Down

0 comments on commit 14a4598

Please sign in to comment.