cmd

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const LatestVersion = "latest"

Variables

View Source
var ConfigCmd = &cobra.Command{
	Use:   "config",
	Short: "Show default install config.",
	Example: `
# Show default install config
tkeel config

# Save default install config to file
tkeel config > config.yaml
`,
	PreRun: func(cmd *cobra.Command, args []string) {
	},
	Run: func(cmd *cobra.Command, args []string) {
		configFromat := `host:
  admin: %s
  tenant: %s
middleware:
  cache:
    customized: false
    url: redis://:Biz0P8Xoup@tkeel-middleware-redis-master:6379/0
  database:
    customized: false
    url: mysql://root:a3fks=ixmeb82a@tkeel-middleware-mysql:3306/tkeelauth
  queue:
    customized: false
    url: kafka://tkeel-middleware-kafka-headless:9092
  search:
    customized: false
    url: elasticsearch://admin:admin@tkeel-middleware-elasticsearch-master:9200
  service_registry:
    customized: false
    url: etcd://tkeel-middleware-etcd:2379
port: %s
repo:
  name: tkeel
  url: https://tkeel-io.github.io/helm-charts
plugins:
  - tkeel/console-portal-admin@latest
  - tkeel/console-portal-tenant@latest
  - tkeel/console-plugin-admin-plugins@latest
image_policy: IfNotPresent
`
		config := fmt.Sprintf(configFromat, adminHost, tenantHost, port)
		fmt.Println(config)
	},
}

ConfigCmd is a command from removing a tKeel installation.

View Source
var DoctorCmd = &cobra.Command{
	Use:   "doctor",
	Short: "Check tkeel install environment.",
	Example: `
# Check the tkeel installation environment
tkeel doctor
`,
	Run: func(cmd *cobra.Command, args []string) {
		print.PendingStatusEvent(os.Stdout, "Checking the Dapr runtime status...")
		status, err := kubernetes.CheckDapr()
		if err != nil {
			print.FailureStatusEvent(os.Stdout, err.Error())
			os.Exit(1)
		}
		installed := fmt.Sprintf("dapr installed: %v", status.Installed)
		if status.Installed {
			print.SuccessStatusEvent(os.Stdout, installed)
		} else {
			print.FailureStatusEvent(os.Stdout, installed)
		}

		version := fmt.Sprintf("dapr version: %s", status.Version)
		if status.Version != "" {
			print.SuccessStatusEvent(os.Stdout, version)
		} else {
			print.FailureStatusEvent(os.Stdout, version)
		}

		namespace := fmt.Sprintf("dapr namespace: %s", status.Namespace)
		if status.Namespace != "" {
			print.SuccessStatusEvent(os.Stdout, namespace)
		} else {
			print.FailureStatusEvent(os.Stdout, namespace)
		}

		mtlsEnabled := fmt.Sprintf("dapr mtls enabled: %v", status.MTLSEnabled)
		if status.MTLSEnabled {
			print.SuccessStatusEvent(os.Stdout, mtlsEnabled)
		} else {
			print.FailureStatusEvent(os.Stdout, mtlsEnabled)
		}
	},
}
View Source
var InitCmd = &cobra.Command{
	Use:   "init",
	Short: "Install tKeel platform on dapr.",
	PreRun: func(cmd *cobra.Command, args []string) {
		checkDapr()
		initVersion()
		if path, err := utils.GetRealPath(configFile); err != nil {
			print.FailureStatusEvent(os.Stdout, err.Error())
			os.Exit(1)
		} else {
			configFile = path
		}
	},
	Example: `
# Initialize Keel in Kubernetes
tkeel init 

# Initialize Keel in Kubernetes and wait for the installation to complete (default timeout is 300s/5m)
tkeel init --wait --timeout 600
`,
	Run: func(cmd *cobra.Command, args []string) {
		print.PendingStatusEvent(os.Stdout, "Making the jump to hyperspace...")
		config := kubernetes.InitConfiguration{
			Namespace:         daprStatus.Namespace,
			KeelVersion:       keelVersion,
			CoreVersion:       coreVersion,
			RudderVersion:     rudderVersion,
			MiddlewareVersion: middlewareVersion,
			DaprVersion:       daprStatus.Version,
			EnableMTLS:        enableMTLS,
			EnableHA:          enableHA,
			Args:              values,
			Wait:              wait,
			Timeout:           timeout,
			DebugMode:         debugMode,
			Secret:            secret,
			Repo: &kitconfig.Repo{
				Url:  repoURL,
				Name: repoName,
			},
			Password:    password,
			ConfigFile:  configFile,
			ImagePolicy: policy,
		}
		err := kubernetes.Init(config)
		if err != nil {
			print.FailureStatusEvent(os.Stdout, err.Error())
			os.Exit(1)
		}
		successEvent := fmt.Sprintf("Success! tKeel Platform has been installed to namespace %s. To verify, run `tkeel plugin list' in your terminal. To get started, go here: https://tkeel.io/keel-getting-started", config.Namespace)
		print.SuccessStatusEvent(os.Stdout, successEvent)
	},
}
View Source
var InvokeCmd = &cobra.Command{
	Use:   "invoke",
	Short: "Invoke a method on a given tKeel plugin(application).",
	Example: `
# Invoke a sample method on target app with POST Verb
tkeel invoke --plugin-id target --method v1/sample --dao '{"key":"value"}

# Invoke a sample method on target app with GET Verb
tkeel invoke --plugin-id target --method v1/sample --verb GET
`,
	Run: func(cmd *cobra.Command, args []string) {
		bytePayload := []byte{}
		var err error
		if invokeDataFile != "" && invokeData != "" {
			print.FailureStatusEvent(os.Stdout, "Only one of --dao and --dao-file allowed in the same invoke command")
			os.Exit(1)
		}

		if invokeDataFile != "" {
			bytePayload, err = ioutil.ReadFile(invokeDataFile)
			if err != nil {
				print.FailureStatusEvent(os.Stdout, "Error reading payload from '%s'. Error: %s", invokeDataFile, err)
				os.Exit(1)
			}
		} else if invokeData != "" {
			bytePayload = []byte(invokeData)
		}

		response, err := kubernetes.InvokeByPortForward(invokeAppID, invokeAppMethod, bytePayload, invokeVerb)
		if err != nil {
			err = fmt.Errorf("error invoking plugin %s: %w", invokeAppID, err)
			print.FailureStatusEvent(os.Stdout, err.Error())
			os.Exit(1)
		}

		if response != "" {
			fmt.Println(response)
		}

		print.SuccessStatusEvent(os.Stdout, "Plugin invoked successfully")
	},
}
View Source
var RootCmd = &cobra.Command{
	Use:   "tkeel",
	Short: "Keel CLI",
	Long: `
      __             __
     / /_____  ___  / /
    / //_/ _ \/ _ \/ /
   / ,< /  __/  __/ /
  /_/|_|\___/\___/_/
									   
===============================
Things Keel Platform`,
	PersistentPreRun: func(cmd *cobra.Command, args []string) {
	},
	Version: "0.4.0",
}
View Source
var StatusCmd = &cobra.Command{
	Use:   "status",
	Short: "CheckDapr tkeel install status.",
	Example: `
# CheckDapr the tkeel installation environment
tkeel status
`,
	Run: func(cmd *cobra.Command, args []string) {
		print.PendingStatusEvent(os.Stdout, "Checking the Dapr runtime status...")
		status, err := kubernetes.CheckTKeel()
		if err != nil {
			print.FailureStatusEvent(os.Stdout, err.Error())
			os.Exit(1)
		}
		installed := fmt.Sprintf("tkeel installed: %v", status.Installed)
		if status.Installed {
			print.SuccessStatusEvent(os.Stdout, installed)
		} else {
			print.FailureStatusEvent(os.Stdout, installed)
		}

		version := fmt.Sprintf("tkeel version: %s", status.Version)
		if status.Version != "" {
			print.SuccessStatusEvent(os.Stdout, version)
		} else {
			print.FailureStatusEvent(os.Stdout, version)
		}

		namespace := fmt.Sprintf("tkeel namespace: %s", status.Namespace)
		if status.Namespace != "" {
			print.SuccessStatusEvent(os.Stdout, namespace)
		} else {
			print.FailureStatusEvent(os.Stdout, namespace)
		}
	},
}
View Source
var UninstallCmd = &cobra.Command{
	Use:   "uninstall",
	Short: "Uninstall tKeel Platform.",
	Example: `
# Uninstall from kubernetes
tkeel uninstall
`,
	PreRun: func(cmd *cobra.Command, args []string) {
		checkDapr()
	},
	Run: func(cmd *cobra.Command, args []string) {
		var confirm bool
		var err error
		if !yes {
			err = survey.AskOne(&survey.Confirm{Message: "Do you want to uninstall tkeel platform ?"}, &confirm)
			if err != nil {
				os.Exit(1)
			}
			if !confirm {
				os.Exit(0)
			}
		}

		defer func() {
			kubernetes.CleanToken()
		}()

		if uninstallAll {
			print.InfoStatusEvent(os.Stdout, "Removing tKeel plugins from your cluster...")
			err = kubernetes.UninstallAllPlugin()
			if err != nil {
				print.FailureStatusEvent(os.Stdout, fmt.Sprintf("Error removing plugins: %s", err))
				os.Exit(1)
			} else {
				print.SuccessStatusEvent(os.Stdout, "tKeel plugins has been removed successfully")
			}
		}
		print.InfoStatusEvent(os.Stdout, "Removing tKeel Platform from your cluster...")

		err = kubernetes.UninstallPlatform(daprStatus.Namespace, timeout, debugMode)

		if err != nil {
			print.FailureStatusEvent(os.Stdout, fmt.Sprintf("Error removing tKeel: %s", err))
			os.Exit(1)
		} else {
			print.SuccessStatusEvent(os.Stdout, "tKeel Platform has been removed successfully")
		}
	},
}

UninstallCmd is a command from removing a tKeel installation.

Functions

func Execute

func Execute(version, apiVersion string)

Execute adds all child commands to the root command.

Types

This section is empty.

Directories

Path Synopsis
------------------------------------------------------------ Copyright (c) Microsoft Corporation and Dapr Contributors.
------------------------------------------------------------ Copyright (c) Microsoft Corporation and Dapr Contributors.

Jump to

Keyboard shortcuts

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