Skip to content

Commit

Permalink
feat(upgrade): fix upgrade tools
Browse files Browse the repository at this point in the history
fix upgrade tools

Signed-off-by: ysicing <[email protected]>
  • Loading branch information
ysicing committed Jul 6, 2022
1 parent 77f32ca commit 94ff7df
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 14 deletions.
18 changes: 14 additions & 4 deletions cmd/manage/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
qcexec "github.com/easysoft/qcadmin/internal/pkg/util/exec"
"github.com/easysoft/qcadmin/internal/pkg/util/factory"
"github.com/easysoft/qcadmin/internal/pkg/util/log"
"github.com/easysoft/qcadmin/internal/static"
"github.com/easysoft/qcadmin/pkg/qucheng/upgrade"
"github.com/spf13/cobra"
)
Expand All @@ -37,7 +38,7 @@ func NewUpgradeQucheg(f factory.Factory) *cobra.Command {
},
PostRunE: func(cmd *cobra.Command, args []string) error {
// 升级成功
return upcmd.Clean()
return upcmd.CleanOrInstall()
},
}
return up
Expand All @@ -47,6 +48,10 @@ func NewUpgradeQucheg(f factory.Factory) *cobra.Command {
func (cmd *UpgradeCmd) Run() error {
// Run the upgrade command
cmd.log.Info("check update...")
if err := static.UpgradeFiles(); err != nil {
cmd.log.Debugf("gen manifest err: %v", err)
}
cmd.log.Debugf("gen new version manifest")
err := upgrade.Upgrade(cmd.Version, cmd.log)
if err != nil {
return fmt.Errorf("couldn't upgrade: %v", err)
Expand All @@ -55,10 +60,15 @@ func (cmd *UpgradeCmd) Run() error {
}

// Clean executes the command logic
func (cmd *UpgradeCmd) Clean() error {
cmd.log.Debug("cleanup deprecated resources")
func (cmd *UpgradeCmd) CleanOrInstall() error {
cmd.log.Info("cleanup deprecated resources")
if err := qcexec.CommandRun(os.Args[0], "exp", "helm", "uninstall", "--name", "cne-api", "--namespace", common.DefaultSystem); err != nil {
cmd.log.Debugf("clean cne-api err: %v", err)
cmd.log.Errorf("clean cne-api err: %v", err)
}
cmd.log.Info("patch new resources")
cmd.log.Info("start deploy operator plugins: cne-operator")
if err := qcexec.CommandRun(os.Args[0], "manage", "plugins", "enable", "cne-operator"); err != nil {
cmd.log.Errorf("deploy plugin cne-operator err: %v", err)
}
return nil
}
5 changes: 5 additions & 0 deletions cmd/upgrade/q.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/easysoft/qcadmin/common"
"github.com/easysoft/qcadmin/internal/pkg/util/factory"
"github.com/easysoft/qcadmin/internal/pkg/util/log"
"github.com/easysoft/qcadmin/internal/static"
"github.com/easysoft/qcadmin/pkg/selfupdate"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -66,5 +67,9 @@ func (up option) DoQcadmin() {
return
}
up.log.Donef("Successfully updated ergo to version %s", lastversion)
if err := static.UpgradeFiles(); err != nil {
up.log.Debugf("gen manifest err: %v", err)
}
up.log.Debugf("gen new version manifest")
up.log.Infof("Release note: \n\trelease %s ", lastversion)
}
27 changes: 23 additions & 4 deletions hack/manifests/plugins/plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"home": "https://github.com/bitnami/charts/tree/master/bitnami/nginx-ingress-controller",
"appversion": "1.2.1",
"path": "hack/manifests/plugins/nginx-ingress-controller.yaml",
"tool": "kubectl"
"tool": "kubectl",
"builtin": true
}
]
},
Expand All @@ -25,7 +26,8 @@
"home": "https://github.com/bitnami/charts/tree/master/bitnami/kube-prometheus",
"appversion": "0.56.1",
"path": "kube-prometheus",
"tool": "helm"
"tool": "helm",
"builtin": false
}
]
},
Expand All @@ -40,7 +42,8 @@
"home": "https://github.com/openelb/openelb",
"appversion": "0.4.4",
"path": "hack/manifests/plugins/openelb.yaml",
"tool": "kubectl"
"tool": "kubectl",
"builtin": false
}
]
},
Expand All @@ -55,7 +58,23 @@
"home": "https://longhorn.io",
"appversion": "1.3.0",
"path": "hack/manifests/plugins/storage-longhorn.yaml",
"tool": "kubectl"
"tool": "kubectl",
"builtin": false
}
]
}, {
"type": "cne-operator",
"default": "cne-operator",
"item": [
{
"name": "cne-operator",
"description": "渠成云原生应用交付平台控制器",
"version": "0.1.0",
"home": "https://www.qucheng.com",
"appversion": "0.1.0",
"path": "cne-operator",
"tool": "helm",
"builtin": true
}
]
}
Expand Down
17 changes: 11 additions & 6 deletions internal/pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (

"github.com/easysoft/qcadmin/common"
"github.com/easysoft/qcadmin/internal/pkg/k8s"
pluginapi "github.com/easysoft/qcadmin/internal/pkg/plugin"
"github.com/easysoft/qcadmin/internal/pkg/types"
"github.com/easysoft/qcadmin/internal/pkg/util/autodetect"
"github.com/easysoft/qcadmin/internal/pkg/util/binfile"
qcexec "github.com/easysoft/qcadmin/internal/pkg/util/exec"
"github.com/easysoft/qcadmin/internal/pkg/util/initsystem"
"github.com/easysoft/qcadmin/internal/pkg/util/log"
"github.com/easysoft/qcadmin/internal/static/deploy"
Expand Down Expand Up @@ -154,12 +154,17 @@ func (p *Cluster) InitCluster() error {
p.Log.Warn("disable ingress controller")
} else {
p.Log.Debug("start deploy ingress plugins: nginx-ingress-controller")
localp, _ := pluginapi.GetMeta("ingress", "nginx-ingress-controller")
localp.Client = p.KubeClient
if err := localp.Install(); err != nil {
p.Log.Warnf("deploy ingress plugins: nginx-ingress-controller failed, reason: %v", err)
// localp, _ := pluginapi.GetMeta("ingress", "nginx-ingress-controller")
// localp.Client = p.KubeClient
// if err := localp.Install(); err != nil {
// p.Log.Warnf("deploy ingress plugins: nginx-ingress-controller failed, reason: %v", err)
// } else {
// p.Log.Done("deployed ingress plugins: nginx-ingress-controller success")
// }
if err := qcexec.CommandRun(os.Args[0], "manage", "plugins", "enable", "ingress"); err != nil {
p.Log.Errorf("deploy plugin ingress err: %v", err)
} else {
p.Log.Done("deployed ingress plugins: nginx-ingress-controller success")
p.Log.Done("deployed operator plugins: cne-ingress success")
}
}
return nil
Expand Down
6 changes: 6 additions & 0 deletions internal/pkg/cluster/qucheng.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ func (p *Cluster) InstallQuCheng() error {
return err
}
p.Log.Done("update qucheng install repo done")
p.Log.Info("start deploy cne operator")
if err := qcexec.CommandRun(os.Args[0], "manage", "plugins", "enable", "cne-operator"); err != nil {
p.Log.Warnf("deploy cne-operator err: %v", err)
} else {
p.Log.Done("deployed cne-operator success")
}
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}
Expand Down
4 changes: 4 additions & 0 deletions internal/pkg/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ func GetMeta(args ...string) (Item, error) {
}

func (p *Item) UnInstall() error {
if p.BuiltIn {
p.log.Warnf("builtin plugin %s cannot be uninstalled", p.Type)
return nil
}
pluginName := fmt.Sprintf("qc-plugin-%s", p.Type)
_, err := p.Client.GetSecret(context.TODO(), common.DefaultSystem, pluginName, metav1.GetOptions{})
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/plugin/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Item struct {
Type string `json:"type"`
Path string `json:"path"`
Tool string `json:"tool"`
BuiltIn bool `json:"builtin"`
log log.Logger `json:"-"`
}

Expand Down
12 changes: 12 additions & 0 deletions internal/static/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package static
import (
"github.com/easysoft/qcadmin/common"
"github.com/easysoft/qcadmin/internal/static/data"
"github.com/easysoft/qcadmin/internal/static/deploy"
"github.com/easysoft/qcadmin/internal/static/scripts"
)

Expand All @@ -22,3 +23,14 @@ func StageFiles() error {
}
return nil
}

func UpgradeFiles() error {
dataDir := common.GetDefaultDataDir()
if err := deploy.Stage(dataDir); err != nil {
return err
}
if err := scripts.Stage(dataDir); err != nil {
return err
}
return nil
}

0 comments on commit 94ff7df

Please sign in to comment.