mirror of https://github.com/kubevela/kubevela.git
fix vela system:init info
This commit is contained in:
parent
85be1ef738
commit
6c1ad6c516
2
Makefile
2
Makefile
|
|
@ -18,7 +18,7 @@ test: fmt vet
|
|||
|
||||
# Build manager binary
|
||||
build: fmt vet
|
||||
go build -ldflags "-X main.VelaVersion=${VELA_VERSION} -X main.GitRevision=${GIT_COMMIT}" -o bin/vela cmd/vela/main.go
|
||||
go build -ldflags "-X github.com/cloud-native-application/rudrx/version.VelaVersion=${VELA_VERSION} -X github.com/cloud-native-application/rudrx/version.GitRevision=${GIT_COMMIT}" -o bin/vela cmd/vela/main.go
|
||||
|
||||
# Run against the configured Kubernetes cluster in ~/.kube/config
|
||||
run: fmt vet
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/cloud-native-application/rudrx/version"
|
||||
|
||||
"github.com/gosuri/uitable"
|
||||
|
||||
"k8s.io/klog"
|
||||
|
|
@ -36,12 +38,6 @@ type noUsageError struct{ error }
|
|||
|
||||
var (
|
||||
scheme = k8sruntime.NewScheme()
|
||||
|
||||
// VelaVersion is the version of cli.
|
||||
VelaVersion = "UNKNOWN"
|
||||
|
||||
// GitRevision is the commit of repo
|
||||
GitRevision = "UNKNOWN"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
|
@ -95,12 +91,15 @@ func newCommand() *cobra.Command {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Getting Start
|
||||
cmd.EnvCommandGroup(cmds, commandArgs, ioStream)
|
||||
// Others
|
||||
cmd.AddonCommandGroup(cmds, commandArgs, ioStream)
|
||||
// System
|
||||
cmd.SystemCommandGroup(cmds, commandArgs, ioStream)
|
||||
|
||||
cmds.AddCommand(
|
||||
// Getting Start
|
||||
cmd.NewEnvInitCommand(commandArgs, ioStream),
|
||||
cmd.NewEnvSwitchCommand(ioStream),
|
||||
cmd.NewEnvDeleteCommand(ioStream),
|
||||
cmd.NewEnvCommand(ioStream),
|
||||
NewVersionCommand(),
|
||||
|
||||
// Apps
|
||||
|
|
@ -109,13 +108,7 @@ func newCommand() *cobra.Command {
|
|||
cmd.NewAppStatusCommand(commandArgs, ioStream),
|
||||
cmd.NewAppShowCommand(commandArgs, ioStream),
|
||||
|
||||
// Others
|
||||
cmd.NewAddonConfigCommand(ioStream),
|
||||
cmd.NewAddonListCommand(commandArgs, ioStream),
|
||||
|
||||
// System
|
||||
cmd.NewAdminInitCommand(commandArgs, ioStream),
|
||||
cmd.NewAdminInfoCommand(VelaVersion, ioStream),
|
||||
cmd.NewRefreshCommand(commandArgs, ioStream),
|
||||
cmd.NewCompletionCommand(),
|
||||
|
||||
|
|
@ -190,8 +183,8 @@ func NewVersionCommand() *cobra.Command {
|
|||
GitRevision: %v
|
||||
GolangVersion: %v
|
||||
`,
|
||||
VelaVersion,
|
||||
GitRevision,
|
||||
version.VelaVersion,
|
||||
version.GitRevision,
|
||||
runtime.Version())
|
||||
},
|
||||
Annotations: map[string]string{
|
||||
|
|
|
|||
|
|
@ -44,6 +44,12 @@ type Plugin struct {
|
|||
ApplesTo string `json:"applies_to"`
|
||||
}
|
||||
|
||||
func AddonCommandGroup(parentCmd *cobra.Command, c types.Args, ioStream cmdutil.IOStreams) {
|
||||
parentCmd.AddCommand(NewAddonConfigCommand(ioStream),
|
||||
NewAddonListCommand(c, ioStream),
|
||||
)
|
||||
}
|
||||
|
||||
func NewAddonConfigCommand(ioStreams cmdutil.IOStreams) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "addon:config",
|
||||
|
|
|
|||
|
|
@ -21,6 +21,14 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func EnvCommandGroup(parentCmd *cobra.Command, c types.Args, ioStream cmdutil.IOStreams) {
|
||||
parentCmd.AddCommand(NewEnvInitCommand(c, ioStream),
|
||||
NewEnvSwitchCommand(ioStream),
|
||||
NewEnvDeleteCommand(ioStream),
|
||||
NewEnvCommand(ioStream),
|
||||
)
|
||||
}
|
||||
|
||||
func NewEnvCommand(ioStreams cmdutil.IOStreams) *cobra.Command {
|
||||
ctx := context.Background()
|
||||
cmd := &cobra.Command{
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/cloud-native-application/rudrx/pkg/builtin"
|
||||
|
||||
|
|
@ -42,7 +43,7 @@ var (
|
|||
|
||||
type initCmd struct {
|
||||
namespace string
|
||||
out io.Writer
|
||||
ioStreams cmdutil.IOStreams
|
||||
client client.Client
|
||||
version string
|
||||
}
|
||||
|
|
@ -68,7 +69,13 @@ var (
|
|||
}
|
||||
)
|
||||
|
||||
func NewAdminInfoCommand(version string, ioStreams cmdutil.IOStreams) *cobra.Command {
|
||||
func SystemCommandGroup(parentCmd *cobra.Command, c types.Args, ioStream cmdutil.IOStreams) {
|
||||
parentCmd.AddCommand(NewAdminInitCommand(c, ioStream),
|
||||
NewAdminInfoCommand(ioStream),
|
||||
)
|
||||
}
|
||||
|
||||
func NewAdminInfoCommand(ioStreams cmdutil.IOStreams) *cobra.Command {
|
||||
i := &infoCmd{out: ioStreams.Out}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
|
|
@ -76,7 +83,7 @@ func NewAdminInfoCommand(version string, ioStreams cmdutil.IOStreams) *cobra.Com
|
|||
Short: "show vela client and cluster version",
|
||||
Long: "show vela client and cluster version",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return i.run(version, ioStreams)
|
||||
return i.run(ioStreams)
|
||||
},
|
||||
Annotations: map[string]string{
|
||||
types.TagCommandType: types.TypeSystem,
|
||||
|
|
@ -85,22 +92,22 @@ func NewAdminInfoCommand(version string, ioStreams cmdutil.IOStreams) *cobra.Com
|
|||
return cmd
|
||||
}
|
||||
|
||||
func (i *infoCmd) run(version string, ioStreams cmdutil.IOStreams) error {
|
||||
func (i *infoCmd) run(ioStreams cmdutil.IOStreams) error {
|
||||
clusterVersion, err := GetOAMReleaseVersion()
|
||||
if err != nil {
|
||||
ioStreams.Errorf("fail to get cluster version, err: %v \n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
ioStreams.Infof("cluster version: %s \n", clusterVersion)
|
||||
ioStreams.Infof("client version: %s \n", version)
|
||||
ioStreams.Info("Versions:")
|
||||
ioStreams.Infof("oam-kubernetes-runtime: %s \n", clusterVersion)
|
||||
// TODO(wonderflow): we should print all helm charts installed by vela, including plugins
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewAdminInitCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
|
||||
|
||||
i := &initCmd{out: ioStreams.Out}
|
||||
i := &initCmd{ioStreams: ioStreams}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "system:init",
|
||||
|
|
@ -128,10 +135,6 @@ func NewAdminInitCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Comma
|
|||
|
||||
func (i *initCmd) run(ioStreams cmdutil.IOStreams) error {
|
||||
|
||||
if err := cmdutil.GetKubeClient(); err != nil {
|
||||
return fmt.Errorf("could not get kubernetes client: %s", err)
|
||||
}
|
||||
|
||||
if !cmdutil.IsNamespaceExist(i.client, types.DefaultOAMNS) {
|
||||
if err := cmdutil.NewNamespace(i.client, types.DefaultOAMNS); err != nil {
|
||||
return err
|
||||
|
|
@ -139,7 +142,7 @@ func (i *initCmd) run(ioStreams cmdutil.IOStreams) error {
|
|||
}
|
||||
|
||||
if i.IsOamRuntimeExist() {
|
||||
fmt.Println("Successfully initialized.")
|
||||
i.ioStreams.Info("Vela system along with OAM runtime already exist.")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -161,7 +164,17 @@ func (i *initCmd) IsOamRuntimeExist() bool {
|
|||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
releases, err := GetHelmRelease()
|
||||
if err != nil {
|
||||
i.ioStreams.Error("get helm release err", err)
|
||||
return false
|
||||
}
|
||||
for _, r := range releases {
|
||||
if strings.Contains(r.Chart.ChartFullPath(), types.DefaultOAMRuntimeName) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func InstallOamRuntime(ioStreams cmdutil.IOStreams, version string) error {
|
||||
|
|
@ -291,7 +304,7 @@ func GetHelmRelease() ([]*release.Release, error) {
|
|||
actionConfig := new(action.Configuration)
|
||||
client := action.NewList(actionConfig)
|
||||
|
||||
if err := actionConfig.Init(settings.RESTClientGetter(), "", os.Getenv("HELM_DRIVER"), debug); err != nil {
|
||||
if err := actionConfig.Init(settings.RESTClientGetter(), types.DefaultOAMNS, os.Getenv("HELM_DRIVER"), debug); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
results, err := client.Run()
|
||||
|
|
@ -313,7 +326,7 @@ func GetOAMReleaseVersion() (string, error) {
|
|||
return result.Chart.AppVersion(), nil
|
||||
}
|
||||
}
|
||||
return "", errors.New("oam-kubernetes-runtime not found in your kubernetes cluster, please use `ruder admin:init` to install.")
|
||||
return "", errors.New("oam-kubernetes-runtime not found in your kubernetes cluster, try `vela system:init` to install.")
|
||||
}
|
||||
|
||||
func filterRepos(repos []*repo.Entry) []*repo.Entry {
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package version
|
||||
|
||||
// GitRevision is the commit of repo
|
||||
var GitRevision = "UNKNOWN"
|
||||
|
||||
// VelaVersion is the version of cli.
|
||||
var VelaVersion = "UNKNOWN"
|
||||
Loading…
Reference in New Issue