diff --git a/cmd/manage/upgrade.go b/cmd/manage/upgrade.go index df870895..54e47eb5 100644 --- a/cmd/manage/upgrade.go +++ b/cmd/manage/upgrade.go @@ -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" ) @@ -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 @@ -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) @@ -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 } diff --git a/cmd/upgrade/q.go b/cmd/upgrade/q.go index 6d75f299..4a8c946b 100644 --- a/cmd/upgrade/q.go +++ b/cmd/upgrade/q.go @@ -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" ) @@ -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) } diff --git a/hack/manifests/plugins/plugins.json b/hack/manifests/plugins/plugins.json index 864ffb71..686d45e6 100644 --- a/hack/manifests/plugins/plugins.json +++ b/hack/manifests/plugins/plugins.json @@ -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 } ] }, @@ -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 } ] }, @@ -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 } ] }, @@ -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 } ] } diff --git a/internal/pkg/cluster/cluster.go b/internal/pkg/cluster/cluster.go index 177aef37..6ad1a4f1 100644 --- a/internal/pkg/cluster/cluster.go +++ b/internal/pkg/cluster/cluster.go @@ -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" @@ -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 diff --git a/internal/pkg/cluster/qucheng.go b/internal/pkg/cluster/qucheng.go index 68d56775..c86a2746 100644 --- a/internal/pkg/cluster/qucheng.go +++ b/internal/pkg/cluster/qucheng.go @@ -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} diff --git a/internal/pkg/plugin/plugin.go b/internal/pkg/plugin/plugin.go index e4d2b198..6204fdbb 100644 --- a/internal/pkg/plugin/plugin.go +++ b/internal/pkg/plugin/plugin.go @@ -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 { diff --git a/internal/pkg/plugin/types.go b/internal/pkg/plugin/types.go index 2bc774f5..4609c375 100644 --- a/internal/pkg/plugin/types.go +++ b/internal/pkg/plugin/types.go @@ -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:"-"` } diff --git a/internal/static/stage.go b/internal/static/stage.go index df0b1c5f..e2ec962c 100644 --- a/internal/static/stage.go +++ b/internal/static/stage.go @@ -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" ) @@ -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 +}