plugin

package
v0.4.3-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PluginCmd = &cobra.Command{
	Use:     "plugin",
	Short:   "manage plugins.",
	Example: PluginHelpExample,
	Run: func(cmd *cobra.Command, args []string) {

		if len(args) == 0 {
			cmd.Help()
			return
		}
	},
}
View Source
var PluginDisableCmd = &cobra.Command{
	Use:     "disable",
	Short:   "disable plugins of tenant.",
	Example: PluginHelpExample,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			print.PendingStatusEvent(os.Stdout, "PluginID not fount ...\n # Manager plugins. \n tkeel plugin register pluginId")
			return
		}
		pluginID := args[0]
		if err := kubernetes.DisablePlugin(pluginID, tenant); err != nil {
			print.FailureStatusEvent(os.Stdout, err.Error())
			os.Exit(1)
		}
		print.SuccessStatusEvent(os.Stdout, fmt.Sprintf("Success! Plugin<%s> has been disabled for tenant<%s>.", pluginID, tenant))
	},
}
View Source
var PluginEnableCmd = &cobra.Command{
	Use:     "enable",
	Short:   "enable plugins of tenant.",
	Example: PluginHelpExample,
	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 pluginID")
			return
		}

		pluginID := args[0]
		err := kubernetes.EnablePlugin(pluginID, tenant)
		if err != nil {
			print.FailureStatusEvent(os.Stdout, err.Error())
			os.Exit(1)
		}
		print.SuccessStatusEvent(os.Stdout, fmt.Sprintf("Success! Plugin<%s> has been enabled for tenant<%s>.", pluginID, tenant))
	},
}
View Source
var PluginHelpExample = `` /* 350-byte string literal not displayed */
View Source
var PluginInfoCmd = &cobra.Command{
	Use:     "show",
	Short:   "show plugin info.",
	Example: PluginHelpExample,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			print.PendingStatusEvent(os.Stdout, "PluginID not fount ...\n # Manager plugins. \n tkeel plugin register pluginID")
			return
		}

		pluginID := args[0]
		status, err := kubernetes.PluginInfo(pluginID)
		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 plugins not install in your cluster?")
			os.Exit(1)
		}

		outputList(status, len(status))
	},
}
View Source
var PluginInstallCmd = &cobra.Command{
	Use:     "install",
	Short:   "Install the plugin which you want",
	Example: PluginHelpExample,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) != 2 {
			cmd.Help()
			print.PendingStatusEvent(os.Stdout, "please input the plugin which you want and the name you want")
			return
		}
		var configb []byte
		var err error
		name := args[1]
		repo, plugin, version := utils.ParseInstallArg(args[0], officialRepo)
		if configFile != "" {
			configFile, err = filepath.Abs(configFile)
			if err != nil {
				print.FailureStatusEvent(os.Stdout, "unable to read config file")
				return
			}
			configb, err = ioutil.ReadFile(configFile)
			if err != nil {
				print.FailureStatusEvent(os.Stdout, "unable to read config file")
				return
			}
		}

		if err := kubernetes.Install(repo, plugin, version, name, configb); 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 PluginStatusCmd = &cobra.Command{
	Use:     "list",
	Short:   "Show the health status of tKeel plugins.",
	Example: PluginHelpExample,
	Run: func(cmd *cobra.Command, args []string) {
		if repo != "" {
			list, err := kubernetes.ListPluginsFromRepo(repo)
			if err != nil {
				print.FailureStatusEvent(os.Stdout, "unable to list plugins:%s", err.Error())
				return
			}
			outputList(list, len(list))
			return
		}

		if tenant != "" {
			list, err := kubernetes.ListPluginsFromTenant(tenant)
			if err != nil {
				print.FailureStatusEvent(os.Stdout, "unable to list plugins:%s", err.Error())
				return
			}
			outputList(list, len(list))
			return
		}

		status, err := kubernetes.InstalledList()
		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 plugins not install in your cluster?")
			os.Exit(1)
		}

		outputList(status, len(status))
	},
}
View Source
var PluginUninstallCmd = &cobra.Command{
	Use:     "uninstall",
	Short:   "uninstall the plugin which you want",
	Example: PluginHelpExample,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) != 1 {
			print.PendingStatusEvent(os.Stdout, "please input the plugin name what you installed.")
			return
		}
		pluginID := args[0]
		if err := kubernetes.UninstallPlugin(pluginID); 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