plugin

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PluginCmd = &cobra.Command{
	Use:   "plugin",
	Short: "Manager plugins. Supported platforms: Kubernetes",
	Example: `
# Manager plugins. in Kubernetes mode
tkeel plugin list -k
tkeel plugin delete -k
tkeel plugin register -k
`,
	Run: func(cmd *cobra.Command, args []string) {

		if len(args) == 0 {
			cmd.Help()
			return
		}
	},
}
View Source
var PluginInstallCmd = &cobra.Command{
	Use:   "install",
	Short: "Install the plugin which you want",
	Example: `
# Get status of tKeel plugins from Kubernetes
tkeel plugin list -k
tkeel plugin list --installable || -i
tkeel plugin delete -k pluginID
tkeel plugin register -k pluginID
tkeel plugin install https://tkeel-io.github.io/helm-charts/auth auth
tkeel plugin install https://tkeel-io.github.io/helm-charts/auth@v0.1.0 auth
`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) != 2 {
			print.PendingStatusEvent(os.Stdout, "please input the plugin which you want and the name you want")
			return
		}
		pluginFormInput, name := args[0], args[1]
		plugin := pluginFormInput
		version := "latest"
		if sp := strings.Split(pluginFormInput, "@"); len(sp) == 2 {
			plugin, version = sp[0], sp[1]
		}
		urls := strings.Split(plugin, "/")
		if len(urls) < 2 {
			print.PendingStatusEvent(os.Stdout, "please input the plugin which you want and the name you want")
			return
		}
		repo := strings.Join(urls[:len(urls)-1], "/")
		plugin = urls[len(urls)-1]

		config := kubernetes.InitConfiguration{
			Wait:      wait,
			Timeout:   timeout,
			DebugMode: debugMode,
		}

		if err := kubernetes.InstallPlugin(config, name, repo, plugin, version); err != nil {
			log.Warn("install failed", err)
			print.FailureStatusEvent(os.Stdout, "Install %q failed, Because: %s", plugin, err.Error())
			return
		}
		print.SuccessStatusEvent(os.Stdout, "Install %q success! It's named %q in k8s", plugin, name)
	},
}
View Source
var PluginRegisterCmd = &cobra.Command{
	Use:   "register",
	Short: "Register plugins. Supported platforms: Kubernetes",
	Example: `
# Manager plugins. in Kubernetes mode
tkeel plugin list -k
tkeel plugin delete -k pluginID
tkeel plugin register -k pluginID
`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			print.PendingStatusEvent(os.Stdout, "PluginID not fount ...\n # Manager plugins. in Kubernetes mode \n tkeel plugin register -k pluginID")
			return
		}
		if kubernetesMode {
			pluginID := args[0]
			err := kubernetes.Register(pluginID)
			if err != nil {
				print.FailureStatusEvent(os.Stdout, err.Error())
				os.Exit(1)
			}
			print.SuccessStatusEvent(os.Stdout, fmt.Sprintf("Success! Plugin<%s> has been Registered to tKeel Platform . To verify, run `tkeel plugin list -k' in your terminal. ", pluginID))
		}
	},
}
View Source
var PluginRemoveCmd = &cobra.Command{
	Use:   "remove",
	Short: "Unregister plugins from tKeel. Supported platforms: Kubernetes",
	Example: `
# Manager plugins. in Kubernetes mode
tkeel plugin list -k
tkeel plugin delete -k pluginID
tkeel plugin register -k pluginID
`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			print.PendingStatusEvent(os.Stdout, "PluginID not fount ...\n # Manager plugins. in Kubernetes mode \n tkeel plugin register -k pluginID")
			return
		}
		if kubernetesMode {
			pluginID := args[0]
			err := kubernetes.Remove(pluginID)
			if err != nil {
				print.FailureStatusEvent(os.Stdout, err.Error())
				os.Exit(1)
			}
			print.SuccessStatusEvent(os.Stdout, fmt.Sprintf("Success! Plugin<%s> has been Registered to tKeel Platform . To verify, run `tkeel plugin list -k' in your terminal. ", pluginID))
		}
	},
}
View Source
var PluginStatusCmd = &cobra.Command{
	Use:   "list",
	Short: "Show the health status of tKeel plugins. Supported platforms: Kubernetes",
	Example: `
# Get status of tKeel plugins from Kubernetes
tkeel plugin list -k
tkeel plugin list --installable || -i
tkeel plugin delete -k pluginID
tkeel plugin register -k pluginID
`,
	Run: func(cmd *cobra.Command, args []string) {
		if installable {
			if update {
				print.PendingStatusEvent(os.Stdout, "updating repo list")
			}
			list, err := helm.ListInstallable("table", update)
			if err != nil {
				log.Warn("list installable plugin failed.")
				print.FailureStatusEvent(os.Stdout, "list installable plugin failed. Because: %s", err.Error())
				return
			}
			fmt.Println(string(list))
			return
		}

		status, err := kubernetes.List()
		if err != nil {
			print.FailureStatusEvent(os.Stdout, err.Error())
			os.Exit(1)
		}
		if len(status) == 0 {
			print.FailureStatusEvent(os.Stdout, "No status returned. Is tKeel initialized in your cluster?")
			os.Exit(1)
		}
		csv, err := gocsv.MarshalString(status)
		if err != nil {
			print.FailureStatusEvent(os.Stdout, err.Error())
			os.Exit(1)
		}

		fmtutil.PrintTable(csv)
	},
}
View Source
var PluginUninstallCmd = &cobra.Command{
	Use:   "uninstall",
	Short: "uninstall the plugin which you want",
	Example: `
# Get status of tKeel plugins from Kubernetes
tkeel plugin list -k
tkeel plugin list --installable || -i
tkeel plugin delete -k pluginID
tkeel plugin register -k pluginID
tkeel plugin remove pluginName
`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) != 1 {
			print.PendingStatusEvent(os.Stdout, "please input the plugin name what you installed.")
			return
		}
		if err := helm.Uninstall(context.Background(), args...); err != nil {
			log.Warn("remove the plugin failed", err)
			print.FailureStatusEvent(os.Stdout, "Try to remove installed plugin %q failed, Because: %s", strings.Join(args, ","), err.Error())
			return
		}
		print.SuccessStatusEvent(os.Stdout, "Remove %q success!", strings.Join(args, ","))
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL