cli

package
v0.0.27 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2021 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Overview

Package cli contains all definitions pertaining to the user-visible commands of the epinio client

Index

Constants

View Source
const (
	DefaultOrganization = "workspace"
)

Variables

View Source
var CmdApp = &cobra.Command{
	Use:           "app",
	Aliases:       []string{"apps"},
	Short:         "Epinio application features",
	Long:          `Manage epinio application`,
	SilenceErrors: true,
	SilenceUsage:  true,
	Args:          cobra.MinimumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		if err := cmd.Usage(); err != nil {
			return err
		}
		return fmt.Errorf(`Unknown method "%s"`, args[0])
	},
}

CmdApp implements the command: epinio app

View Source
var CmdAppCreate = &cobra.Command{
	Use:   "create NAME",
	Short: "Create just the app, without creating a workload",
	Args:  cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := clients.NewEpinioClient(cmd.Context())

		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.AppCreate(args[0])
		if err != nil {
			return errors.Wrap(err, "error creating app")
		}

		return nil
	},
	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		if len(args) != 0 {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		app, err := clients.NewEpinioClient(context.Background())
		if err != nil {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		matches := app.AppsMatching(context.Background(), toComplete)

		return matches, cobra.ShellCompDirectiveNoFileComp
	},
}

CmdAppCreate implements the command: epinio apps create

View Source
var CmdAppEnv = &cobra.Command{
	Use:           "env",
	Short:         "Epinio application configuration",
	Long:          `Manage epinio application environment variables`,
	SilenceErrors: true,
	SilenceUsage:  true,
	Args:          cobra.MinimumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		if err := cmd.Usage(); err != nil {
			return err
		}
		return fmt.Errorf(`Unknown method "%s"`, args[0])
	},
}

CmdAppEnv implements the command: epinio app env

View Source
var CmdAppList = &cobra.Command{
	Use:   "list",
	Short: "Lists all applications",
	Args:  cobra.ExactArgs(0),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := clients.NewEpinioClient(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.Apps()
		if err != nil {
			return errors.Wrap(err, "error listing apps")
		}

		return nil
	},
}

CmdAppList implements the command: epinio app list

View Source
var CmdAppLogs = &cobra.Command{
	Use:   "logs NAME",
	Short: "Streams the logs of the application",
	Args:  cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := clients.NewEpinioClient(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		follow, err := cmd.Flags().GetBool("follow")
		if err != nil {
			return errors.Wrap(err, "error reading option --follow")
		}

		staging, err := cmd.Flags().GetBool("staging")
		if err != nil {
			return errors.Wrap(err, "error reading option --staging")
		}

		stageID, err := client.AppStageID(args[0])
		if err != nil {
			return errors.Wrap(err, "error checking app")
		}
		if staging {
			follow = false
		} else {
			stageID = ""
		}

		err = client.AppLogs(args[0], stageID, follow, nil)
		if err != nil {
			return errors.Wrap(err, "error streaming application logs")
		}

		return nil
	},
}

CmdAppLogs implements the command: epinio apps logs

View Source
var CmdAppShow = &cobra.Command{
	Use:   "show NAME",
	Short: "Describe the named application",
	Args:  cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := clients.NewEpinioClient(cmd.Context())

		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.AppShow(args[0])
		if err != nil {
			return errors.Wrap(err, "error showing app")
		}

		return nil
	},
	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		if len(args) != 0 {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		app, err := clients.NewEpinioClient(context.Background())
		if err != nil {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		matches := app.AppsMatching(context.Background(), toComplete)

		return matches, cobra.ShellCompDirectiveNoFileComp
	},
}

CmdAppShow implements the command: epinio apps show

View Source
var CmdAppUpdate = &cobra.Command{
	Use:   "update NAME",
	Short: "Update the named application",
	Long:  "Update the running application's attributes (e.g. instances)",
	Args:  cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := clients.NewEpinioClient(cmd.Context())

		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		i, err := instances(cmd)
		if err != nil {
			return errors.Wrap(err, "trouble with instances")
		}
		if i == nil {
			d := v1.DefaultInstances
			i = &d
		}
		err = client.AppUpdate(args[0], *i)
		if err != nil {
			return errors.Wrap(err, "error updating the app")
		}

		return nil
	},
	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		if len(args) != 0 {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		app, err := clients.NewEpinioClient(context.Background())
		if err != nil {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		matches := app.AppsMatching(context.Background(), toComplete)

		return matches, cobra.ShellCompDirectiveNoFileComp
	},
}

CmdAppUpdate implements the command: epinio apps update It scales the named app

View Source
var CmdCompletion = &cobra.Command{
	Use:   "completion [bash|zsh|fish|powershell]",
	Short: "Generate completion script for a shell",
	Long: `To load completions:

Bash:

$ source <(epinio completion bash)

# To load completions for each session, execute once:
Linux:
  $ epinio completion bash > /etc/bash_completion.d/epinio
MacOS:
  $ epinio completion bash > /usr/local/etc/bash_completion.d/epinio

ATTENTION:
    The generated script requires the bash-completion package.
    See https://kubernetes.io/docs/tasks/tools/install-kubectl/#enabling-shell-autocompletion
    for information on how to install and activate it.

Zsh:

# If shell completion is not already enabled in your environment you will need
# to enable it.  You can execute the following once:

$ echo "autoload -U compinit; compinit" >> ~/.zshrc

# To load completions for each session, execute once:
$ epinio completion zsh > "${fpath[1]}/_epinio"

# You will need to start a new shell for this setup to take effect.

Fish:

$ epinio completion fish | source

# To load completions for each session, execute once:
$ epinio completion fish > ~/.config/fish/completions/epinio.fish

Powershell:

PS> epinio completion powershell | Out-String | Invoke-Expression

# To load completions for every new session, run:
PS> epinio completion powershell > epinio.ps1
# and source this file from your powershell profile.
`,
	DisableFlagsInUseLine: true,
	ValidArgs:             []string{"bash", "zsh", "fish", "powershell"},
	Args:                  cobra.ExactValidArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		switch args[0] {
		case "bash":
			return cmd.Root().GenBashCompletion(os.Stdout)
		case "zsh":
			return cmd.Root().GenZshCompletion(os.Stdout)
		case "fish":
			return cmd.Root().GenFishCompletion(os.Stdout, true)
		case "powershell":
			return cmd.Root().GenPowerShellCompletion(os.Stdout)
		}
		return errors.New("Internal error: Invalid shell")
	},
}

CmdCompletion represents the completion command

View Source
var CmdConfig = &cobra.Command{
	Use:           "config",
	Short:         "Epinio config management",
	Long:          `Manage the epinio cli configuration`,
	SilenceErrors: true,
	SilenceUsage:  true,
	Args:          cobra.MinimumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		if err := cmd.Usage(); err != nil {
			return err
		}
		return fmt.Errorf(`Unknown method "%s"`, args[0])
	},
}

CmdConfig implements the command: epinio config

View Source
var CmdConfigColors = &cobra.Command{
	Use:   "colors BOOL",
	Short: "Manage colored output",
	Long:  "Enable/Disable colored output",
	Args: func(cmd *cobra.Command, args []string) error {
		if len(args) != 1 {
			return errors.New("requires a boolean argument")
		}
		_, err := strconv.ParseBool(args[0])
		if err != nil {
			return errors.New("requires a boolean argument")
		}
		return nil
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		ui := termui.NewUI()

		theConfig, err := config.Load()
		if err != nil {
			return errors.Wrap(err, "failed to load configuration")
		}

		ui.Note().WithStringValue("Config", theConfig.Location).Msg("Edit Colorization Flag")

		colors, err := strconv.ParseBool(args[0])

		if err != nil {
			return errors.Wrap(err, "unexpected bool parsing error")
		}

		theConfig.Colors = colors
		if err := theConfig.Save(); err != nil {
			return err
		}

		ui.Success().WithBoolValue("Colors", theConfig.Colors).Msg("Ok")
		return nil
	},
}

CmdConfigColors implements the command: epinio config colors

View Source
var CmdConfigShow = &cobra.Command{
	Use:   "show",
	Short: "Show the current configuration",
	Args:  cobra.ExactArgs(0),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		ui := termui.NewUI()

		theConfig, err := config.Load()
		if err != nil {
			return errors.Wrap(err, "failed to load configuration")
		}

		ui.Note().WithStringValue("Config", theConfig.Location).Msg("Show Configuration")

		certInfo := color.CyanString("None defined")
		if theConfig.Certs != "" {
			certInfo = color.BlueString("Present")
		}

		ui.Success().
			WithTable("Key", "Value").
			WithTableRow("Colorized Output", color.MagentaString("%t", theConfig.Colors)).
			WithTableRow("Current Namespace", color.CyanString(theConfig.Org)).
			WithTableRow("API User Name", color.BlueString(theConfig.User)).
			WithTableRow("API Password", color.BlueString(theConfig.Password)).
			WithTableRow("API Url", color.BlueString(theConfig.API)).
			WithTableRow("WSS Url", color.BlueString(theConfig.WSS)).
			WithTableRow("Certificates", certInfo).
			Msg("Ok")

		return nil
	},
}

CmdConfigShow implements the command: epinio config show

View Source
var CmdConfigUpdate = &cobra.Command{
	Use:   "update",
	Short: "Update the api location & stored credentials",
	Long:  "Update the api location and stored credentials from the current cluster",
	Args:  cobra.ExactArgs(0),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := clients.NewEpinioClient(cmd.Context())

		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.ConfigUpdate(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "failed to update the configuration")
		}

		return nil
	},
}

CmdConfigUpdate implements the command: epinio config update

View Source
var CmdDebug = &cobra.Command{
	Hidden:        true,
	Use:           "debug",
	Short:         "Dev Tools",
	Long:          `Developer Tools. Hidden From Regular User.`,
	SilenceErrors: true,
	SilenceUsage:  true,
	Args:          cobra.MinimumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		if err := cmd.Usage(); err != nil {
			return err
		}
		return fmt.Errorf(`Unknown method "%s"`, args[0])
	},
}

CmdDebug implements the command: epinio debug

View Source
var CmdDebugTTY = &cobra.Command{
	Use:   "tty",
	Short: "Running In a Terminal?",
	Long:  `Running In a Terminal?`,
	Args:  cobra.ExactArgs(0),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true
		if isatty.IsTerminal(os.Stdout.Fd()) {
			fmt.Println("Is Terminal")
		} else if isatty.IsCygwinTerminal(os.Stdout.Fd()) {
			fmt.Println("Is Cygwin/MSYS2 Terminal")
		} else {
			fmt.Println("Is Not Terminal")
		}
		return nil
	},
}

CmdDebug implements the command: epinio debug tty

View Source
var CmdDeleteApp = &cobra.Command{
	Use:   "delete NAME",
	Short: "Deletes an application",
	Args:  cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := clients.NewEpinioClient(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.Delete(cmd.Context(), args[0])
		if err != nil {
			return errors.Wrap(err, "error deleting app")
		}

		return nil
	},
	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		if len(args) != 0 {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}
		app, err := clients.NewEpinioClient(context.Background())
		if err != nil {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		matches := app.AppsMatching(context.Background(), toComplete)

		return matches, cobra.ShellCompDirectiveNoFileComp
	},
}

CmdDeleteApp implements the command: epinio app delete

View Source
var CmdDisable = &cobra.Command{
	Use:           "disable",
	Short:         "disable Epinio features",
	Long:          `disable Epinio features which where enabled with "epinio enable"`,
	SilenceErrors: true,
	SilenceUsage:  true,
	Args:          cobra.MinimumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		if err := cmd.Usage(); err != nil {
			return err
		}
		return fmt.Errorf(`Unknown method "%s"`, args[0])
	},
}
View Source
var CmdDisableGoogle = &cobra.Command{
	Use:   "services-google",
	Short: "disable Google Cloud service in Epinio",
	Long:  `disable Google Cloud services in Epinio which will disable the provisioning of those services. Doesn't delete already provisioned services by default.`,
	Args:  cobra.ExactArgs(0),
	RunE:  DisableGoogle,
}
View Source
var CmdDisableInCluster = &cobra.Command{
	Use:   "services-incluster",
	Short: "disable in-cluster services in Epinio",
	Long:  `disable in-cluster services in Epinio which will disable provisioning services on the same cluster as Epinio. Doesn't delete already provisioned services by default.`,
	Args:  cobra.ExactArgs(0),
	RunE:  DisableInCluster,
}

TODO: Implement a flag to also delete provisioned services [TBD]

View Source
var CmdEnable = &cobra.Command{
	Use:           "enable",
	Short:         "enable Epinio features",
	Long:          `enable Epinio features that are not enabled by default`,
	SilenceErrors: true,
	SilenceUsage:  true,
	Args:          cobra.MinimumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		if err := cmd.Usage(); err != nil {
			return err
		}
		return fmt.Errorf(`Unknown method "%s"`, args[0])
	},
}
View Source
var CmdEnableGoogle = &cobra.Command{
	Use:   "services-google",
	Short: "enable Google Cloud services in Epinio",
	Long:  `enable Google Cloud services in Epinio which allows provisioning those kind of services.`,
	Args:  cobra.ExactArgs(0),
	RunE:  EnableGoogle,
}
View Source
var CmdEnableInCluster = &cobra.Command{
	Use:   "services-incluster",
	Short: "enable in-cluster services in Epinio",
	Long:  `enable in-cluster services in Epinio which allows provisioning services which run on the same cluster as Epinio. Should be used mostly for development.`,
	Args:  cobra.ExactArgs(0),
	RunE:  EnableInCluster,
}
View Source
var CmdEnvList = &cobra.Command{
	Use:   "list APPNAME",
	Short: "Lists application environment",
	Long:  "Lists environment variables of named application",
	Args:  cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := clients.NewEpinioClient(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.EnvList(cmd.Context(), args[0])
		if err != nil {
			return errors.Wrap(err, "error listing app environment")
		}

		return nil
	},
	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		if len(args) != 0 {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		app, err := clients.NewEpinioClient(context.Background())
		if err != nil {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		matches := app.AppsMatching(context.Background(), toComplete)

		return matches, cobra.ShellCompDirectiveNoFileComp
	},
}

CmdEnvList implements the command: epinio app env list

View Source
var CmdEnvSet = &cobra.Command{
	Use:   "set APPNAME NAME VALUE",
	Short: "Extend application environment",
	Long:  "Add or change environment variable of named application",
	Args:  cobra.ExactArgs(3),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := clients.NewEpinioClient(cmd.Context())

		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.EnvSet(cmd.Context(), args[0], args[1], args[2])
		if err != nil {
			return errors.Wrap(err, "error setting into app environment")
		}

		return nil
	},
	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {

		if len(args) > 1 {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		app, err := clients.NewEpinioClient(context.Background())
		if err != nil {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		matches := app.AppsMatching(context.Background(), toComplete)

		return matches, cobra.ShellCompDirectiveNoFileComp
	},
}

CmdEnvSet implements the command: epinio app env set

View Source
var CmdEnvShow = &cobra.Command{
	Use:   "show APPNAME NAME",
	Short: "Describe application's environment variable",
	Args:  cobra.ExactArgs(2),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := clients.NewEpinioClient(cmd.Context())

		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.EnvShow(cmd.Context(), args[0], args[1])
		if err != nil {
			return errors.Wrap(err, "error accessing app environment")
		}

		return nil
	},
	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		if len(args) > 2 {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		app, err := clients.NewEpinioClient(context.Background())
		if err != nil {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		if len(args) == 1 {

			matches := app.EnvMatching(context.Background(), args[0], toComplete)
			return matches, cobra.ShellCompDirectiveNoFileComp
		}

		matches := app.AppsMatching(context.Background(), toComplete)

		return matches, cobra.ShellCompDirectiveNoFileComp
	},
}

CmdEnvShow implements the command: epinio app env show

View Source
var CmdEnvUnset = &cobra.Command{
	Use:   "unset APPNAME NAME",
	Short: "Shrink application environment",
	Long:  "Remove environment variable from named application",
	Args:  cobra.ExactArgs(2),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := clients.NewEpinioClient(cmd.Context())

		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.EnvUnset(cmd.Context(), args[0], args[1])
		if err != nil {
			return errors.Wrap(err, "error removing from app environment")
		}

		return nil
	},
	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		if len(args) != 0 {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		app, err := clients.NewEpinioClient(context.Background())
		if err != nil {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		matches := app.AppsMatching(context.Background(), toComplete)

		return matches, cobra.ShellCompDirectiveNoFileComp
	},
}

CmdEnvUnset implements the command: epinio app env unset

View Source
var CmdInfo = &cobra.Command{
	Use:   "info",
	Short: "Shows information about the Epinio environment",
	Long:  `Shows status and version for Kubernetes, Gitea, Tekton and Eirini.`,
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := clients.NewEpinioClient(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.Info()
		if err != nil {
			return errors.Wrap(err, "error retrieving Epinio environment information")
		}

		return nil
	},
}

CmdInfo implements the command: epinio info

View Source
var CmdInstall = &cobra.Command{
	Use:   "install",
	Short: "install Epinio in your configured kubernetes cluster",
	Long:  `install Epinio PaaS in your configured kubernetes cluster`,
	Args:  cobra.ExactArgs(0),
	RunE:  install,
}

CmdInstall implements the command: epinio install

View Source
var CmdInstallCertManager = &cobra.Command{
	Use:   "install-cert-manager",
	Short: "install Epinio's cert-manager in your configured kubernetes cluster",
	Long:  `install Epinio cert-manager controller in your configured kubernetes cluster`,
	Args:  cobra.ExactArgs(0),
	RunE:  installCertManager,
}

CmdInstallCertManager implements the command: epinio install-cert-manager

View Source
var CmdInstallIngress = &cobra.Command{
	Use:   "install-ingress",
	Short: "install Epinio's Ingress in your configured kubernetes cluster",
	Long:  `install Epinio Ingress controller in your configured kubernetes cluster`,
	Args:  cobra.ExactArgs(0),
	RunE:  installIngress,
}

CmdInstallIngress implements the command: epinio install-ingress

View Source
var CmdOrg = &cobra.Command{
	Use:           "namespace",
	Aliases:       []string{"namespaces"},
	Short:         "Epinio-controlled namespaces",
	Long:          `Manage epinio-controlled namespaces`,
	SilenceErrors: true,
	SilenceUsage:  true,
	Args:          cobra.MinimumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		if err := cmd.Usage(); err != nil {
			return err
		}
		return fmt.Errorf(`Unknown method "%s"`, args[0])
	},
}

CmdOrg implements the command: epinio namespace

View Source
var CmdOrgCreate = &cobra.Command{
	Use:   "create NAME",
	Short: "Creates an epinio-controlled namespace",
	Args:  cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := clients.NewEpinioClient(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.CreateOrg(args[0])
		if err != nil {
			return errors.Wrap(err, "error creating epinio-controlled namespace")
		}

		return nil
	},
}

CmdOrgCreate implements the command: epinio namespace create

View Source
var CmdOrgDelete = &cobra.Command{
	Use:   "delete NAME",
	Short: "Deletes an epinio-controlled namespace",
	Args:  cobra.ExactArgs(1),
	PreRunE: func(cmd *cobra.Command, args []string) error {
		force, err := cmd.Flags().GetBool("force")
		if err != nil {
			return err
		}
		if !force {
			cmd.Printf("You are about to delete namespace %s and everything it includes, i.e. applications, services, etc. Are you sure? (y/n): ", args[0])
			if !askConfirmation(cmd) {
				return errors.New("Cancelled by user")
			}
		}

		return nil
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := clients.NewEpinioClient(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.DeleteOrg(args[0])
		if err != nil {
			return errors.Wrap(err, "error deleting epinio-controlled namespace")
		}

		return nil
	},
}

CmdOrgDelete implements the command: epinio namespace delete

View Source
var CmdOrgList = &cobra.Command{
	Use:   "list",
	Short: "Lists all epinio-controlled namespaces",
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := clients.NewEpinioClient(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.Orgs()
		if err != nil {
			return errors.Wrap(err, "error listing epinio-controlled namespaces")
		}

		return nil
	},
}

CmdOrgs implements the command: epinio namespace list

View Source
var CmdPush = &cobra.Command{
	Use:   "push NAME [URL|PATH_TO_APPLICATION_SOURCES]",
	Short: "Push an application from the specified directory, or the current working directory",
	Args:  cobra.RangeArgs(1, 2),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := clients.NewEpinioClient(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		gitRevision, err := cmd.Flags().GetString("git")
		if err != nil {
			return errors.Wrap(err, "could not read option --git")
		}

		dockerImageURL, err := cmd.Flags().GetString("docker-image-url")
		if err != nil {
			return errors.Wrap(err, "could not read option --docker-image-url")
		}

		if gitRevision != "" && dockerImageURL != "" {
			return errors.Wrap(err, "cannot use both, git and docker image url")
		}

		builderImage, err := cmd.Flags().GetString("builder-image")
		if err != nil {
			return errors.Wrap(err, "could not read option --builder-image")
		}

		var path string
		if len(args) == 1 {
			if gitRevision != "" {

				cmd.SilenceUsage = false
				return errors.New("app name or git repository url missing")
			}

			path, err = os.Getwd()
			if err != nil {
				return errors.Wrap(err, "working directory not accessible")
			}
		} else {
			path = args[1]
		}

		if dockerImageURL != "" {
			path = ""
		}

		if gitRevision == "" && dockerImageURL == "" {
			if _, err := os.Stat(path); err != nil {

				cmd.SilenceUsage = false
				return errors.Wrap(err, "path not accessible")
			}
		}

		i, err := instances(cmd)
		if err != nil {
			return errors.Wrap(err, "trouble with instances")
		}
		params := clients.PushParams{
			Name:         args[0],
			Instances:    i,
			GitRev:       gitRevision,
			Docker:       dockerImageURL,
			Path:         path,
			BuilderImage: builderImage,
		}

		services, err := cmd.Flags().GetStringSlice("bind")
		if err != nil {
			return errors.Wrap(err, "failed to read option --bind")
		}
		params.Services = services

		err = client.Push(cmd.Context(), params)
		if err != nil {
			return errors.Wrap(err, "error pushing app to server")
		}

		return nil
	},
}

CmdPush implements the command: epinio app push

View Source
var CmdServer = &cobra.Command{
	Use:   "server",
	Short: "Starts the Epinio server.",
	Long:  "This command starts the Epinio server. `epinio install` ensures the server is running inside your cluster. Normally you don't need to run this command manually.",
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true
		httpServerWg := &sync.WaitGroup{}
		httpServerWg.Add(1)
		port := viper.GetInt("port")
		ui := termui.NewUI()
		logger := tracelog.NewServerLogger()
		_, listeningPort, err := startEpinioServer(httpServerWg, port, ui, logger)
		if err != nil {
			return errors.Wrap(err, "failed to start server")
		}
		ui.Normal().Msg("listening on localhost on port " + listeningPort)
		httpServerWg.Wait()

		return nil
	},
}

CmdServer implements the command: epinio server

View Source
var CmdService = &cobra.Command{
	Use:           "service",
	Aliases:       []string{"services"},
	Short:         "Epinio service features",
	Long:          `Handle service features with Epinio`,
	SilenceErrors: true,
	SilenceUsage:  true,
	Args:          cobra.MinimumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		if err := cmd.Usage(); err != nil {
			return err
		}
		return fmt.Errorf(`Unknown method "%s"`, args[0])
	},
}

CmdService implements the command: epinio service

View Source
var CmdServiceBind = &cobra.Command{
	Use:   "bind NAME APP",
	Short: "Bind a service to an application",
	Long:  `Bind service by name, to named application.`,
	Args:  cobra.ExactArgs(2),
	RunE:  ServiceBind,
	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		if len(args) > 1 {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		app, err := clients.NewEpinioClient(context.Background())
		if err != nil {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		if len(args) == 1 {

			matches := app.AppsMatching(context.Background(), toComplete)
			return matches, cobra.ShellCompDirectiveNoFileComp
		}

		matches := app.ServiceMatching(context.Background(), toComplete)

		return matches, cobra.ShellCompDirectiveNoFileComp
	},
}

CmdServiceBind implements the command: epinio service bind

View Source
var CmdServiceCreate = &cobra.Command{
	Use:   "create NAME CLASS PLAN",
	Short: "Create a service",
	Long:  `Create service by name, class, plan, and optional json data.`,
	Args: func(cmd *cobra.Command, args []string) error {
		if len(args) < 3 {
			return errors.New("Not enough arguments, expected name, class, plan")
		}
		return nil
	},
	RunE: ServiceCreate,
	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		if len(args) > 2 {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		if len(args) == 0 {

			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		app, err := clients.NewEpinioClient(context.Background())
		if err != nil {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		if len(args) == 2 {

			matches := app.ServicePlanMatching(context.Background(), args[1], toComplete)
			return matches, cobra.ShellCompDirectiveNoFileComp
		}

		matches := app.ServiceClassMatching(context.Background(), toComplete)
		return matches, cobra.ShellCompDirectiveNoFileComp
	},
}

CmdServiceCreate implements the command: epinio service create

View Source
var CmdServiceCreateCustom = &cobra.Command{
	Use:   "create-custom NAME (KEY VALUE)...",
	Short: "Create a custom service",
	Long:  `Create custom service by name and key/value dictionary.`,
	Args: func(cmd *cobra.Command, args []string) error {
		if len(args) < 3 {
			return errors.New("Not enough arguments, expected name, key, and value")
		}
		if len(args)%2 == 0 {
			return errors.New("Last Key has no value")
		}
		return nil
	},
	RunE: ServiceCreateCustom,
}

CmdServiceCreateCustom implements the command: epinio service create-custom

View Source
var CmdServiceDelete = &cobra.Command{
	Use:   "delete NAME",
	Short: "Delete a service",
	Long:  `Delete service by name.`,
	Args:  cobra.ExactArgs(1),
	RunE:  ServiceDelete,
	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		if len(args) != 0 {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		epinioClient, err := clients.NewEpinioClient(context.Background())
		if err != nil {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		matches := epinioClient.ServiceMatching(context.Background(), toComplete)

		return matches, cobra.ShellCompDirectiveNoFileComp
	},
}

CmdServiceDelete implements the command: epinio service delete

View Source
var CmdServiceList = &cobra.Command{
	Use:   "list",
	Short: "Lists all services",
	RunE:  ServiceList,
}

CmdServiceList implements the command: epinio service list

View Source
var CmdServiceListClasses = &cobra.Command{
	Use:   "list-classes",
	Short: "Lists the available service classes",
	RunE:  ServiceListClasses,
}

CmdServiceListClasses implements the command: epinio service classes

View Source
var CmdServiceListPlans = &cobra.Command{
	Use:   "list-plans CLASS",
	Short: "Lists all plans provided by the named service class",
	Args:  cobra.ExactArgs(1),
	RunE:  ServiceListPlans,
	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		if len(args) != 0 {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		app, err := clients.NewEpinioClient(context.Background())
		if err != nil {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		matches := app.ServiceClassMatching(context.Background(), toComplete)

		return matches, cobra.ShellCompDirectiveNoFileComp
	},
}

CmdServiceListPlans implements the command: epinio service plans

View Source
var CmdServiceShow = &cobra.Command{
	Use:   "show NAME",
	Short: "Service information",
	Long:  `Show detailed information of the named service.`,
	Args:  cobra.ExactArgs(1),
	RunE:  ServiceShow,
	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		if len(args) != 0 {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		app, err := clients.NewEpinioClient(context.Background())
		if err != nil {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		matches := app.ServiceMatching(context.Background(), toComplete)

		return matches, cobra.ShellCompDirectiveNoFileComp
	},
}

CmdServiceShow implements the command: epinio service show

View Source
var CmdServiceUnbind = &cobra.Command{
	Use:   "unbind NAME APP",
	Short: "Unbind service from an application",
	Long:  `Unbind service by name, from named application.`,
	Args:  cobra.ExactArgs(2),
	RunE:  ServiceUnbind,
	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		if len(args) > 1 {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		app, err := clients.NewEpinioClient(context.Background())
		if err != nil {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		if len(args) == 1 {

			matches := app.AppsMatching(context.Background(), toComplete)
			return matches, cobra.ShellCompDirectiveNoFileComp
		}

		matches := app.ServiceMatching(context.Background(), toComplete)

		return matches, cobra.ShellCompDirectiveNoFileComp
	},
}

CmdServiceUnbind implements the command: epinio service unbind

View Source
var CmdTarget = &cobra.Command{
	Use:   "target [namespace]",
	Short: "Targets an epinio-controlled namespace.",
	Args:  cobra.MaximumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := clients.NewEpinioClient(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		org := ""
		if len(args) > 0 {
			org = args[0]
		}

		err = client.Target(org)
		if err != nil {
			return errors.Wrap(err, "failed to set target")
		}

		return nil
	},
	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		if len(args) != 0 {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		app, err := clients.NewEpinioClient(context.Background())
		if err != nil {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		matches := app.OrgsMatching(toComplete)

		return matches, cobra.ShellCompDirectiveNoFileComp
	},
}

CmdTarget implements the command: epinio target

View Source
var CmdUninstall = &cobra.Command{
	Use:   "uninstall",
	Short: "uninstall Epinio from your configured kubernetes cluster",
	Long:  `uninstall Epinio PaaS from your configured kubernetes cluster`,
	Args:  cobra.ExactArgs(0),
	RunE:  Uninstall,
}

Functions

func CreateKubeClient

func CreateKubeClient(configPath string) kubernetes.Interface

CreateKubeClient returns a client for access to kubernetes It is currently not used

func DisableGoogle

func DisableGoogle(cmd *cobra.Command, args []string) error

DisableGoogle implements: epinio disable services-google

func DisableInCluster

func DisableInCluster(cmd *cobra.Command, args []string) error

DisableInCluster implements: epinio disable services-incluster

func EnableGoogle

func EnableGoogle(cmd *cobra.Command, args []string) error

EnableGoogle implements: epinio enable services-google

func EnableInCluster

func EnableInCluster(cmd *cobra.Command, args []string) error

EnableInCluster implements: epinio enable services-incluster

func Execute

func Execute()

Execute executes the root command. This is called by main.main(). It only needs to happen once to the rootCmd.

func ExitIfError

func ExitIfError(err error)

ExitIfError is a short form of ExitfIfError, with a standard message It is currently not used

func ExitfIfError

func ExitfIfError(err error, message string)

ExitfIfError stops the application with an error exit code, after printing error and message, if there is an error.

func ExitfWithMessage

func ExitfWithMessage(message string, args ...interface{})

ExitfWithMessage stops the application with an error exit code, after formatting and printing the message. It is currently not used

func InstallDeployment

func InstallDeployment(cmd *cobra.Command, deployment kubernetes.Deployment, opts kubernetes.InstallationOptions, successMessage string) error

InstallDeployment is a helper which installs the single referenced deployment

func NewEpinioCLI added in v0.0.19

func NewEpinioCLI() *cobra.Command

NewEpinioCLI returns the main `epinio` cli.

func ReadyRouter added in v0.0.23

func ReadyRouter() *httprouter.Router

ReadyRouter constructs and returns the router for the endpoint handling the kube probes (liveness, readiness)

func ServiceBind

func ServiceBind(cmd *cobra.Command, args []string) error

ServiceBind is the backend of command: epinio service bind

func ServiceCreate

func ServiceCreate(cmd *cobra.Command, args []string) error

ServiceCreate is the backend of command: epinio service create

func ServiceCreateCustom

func ServiceCreateCustom(cmd *cobra.Command, args []string) error

ServiceCreateCustom is the backend of command: epinio service create-custom

func ServiceDelete

func ServiceDelete(cmd *cobra.Command, args []string) error

ServiceDelete is the backend of command: epinio service delete

func ServiceList

func ServiceList(cmd *cobra.Command, args []string) error

ServiceList is the backend of command: epinio service list

func ServiceListClasses

func ServiceListClasses(cmd *cobra.Command, args []string) error

ServiceListClasses is the backend of command: epinio service list-classes

func ServiceListPlans

func ServiceListPlans(cmd *cobra.Command, args []string) error

ServiceListPlans is the backend of command: epinio service list-plans

func ServiceShow

func ServiceShow(cmd *cobra.Command, args []string) error

ServiceShow is the backend of command: epinio service show

func ServiceUnbind

func ServiceUnbind(cmd *cobra.Command, args []string) error

ServiceUnbind is the backend of command: epinio service unbind

func Uninstall

func Uninstall(cmd *cobra.Command, args []string) error

Uninstall implement the command: epinio uninstall It removes epinio from a configured cluster

func UninstallDeployment

func UninstallDeployment(cmd *cobra.Command, deployment kubernetes.Deployment, successMessage string) error

UninstallDeployment is a helper which removes the single referenced deployment

Types

This section is empty.

Directories

Path Synopsis
Package clients contains all the CLI commands for the client
Package clients contains all the CLI commands for the client
gitea
Package gitea deals with using gitea as a store for pushed applications and their deployment info
Package gitea deals with using gitea as a store for pushed applications and their deployment info
Package logprinter is used to print container log lines in color
Package logprinter is used to print container log lines in color

Jump to

Keyboard shortcuts

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