cmd

package
v1.18.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: Apache-2.0 Imports: 24 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "csc",
	Short: "a command line container storage interface (CSI) client",
	PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {

		if debug {

			root.logLevel.Set(log.DebugLevel.String())
			root.withReqLogging = true
			root.withReqLogging = true
		}

		lvl, _ := root.logLevel.Val()
		log.SetLevel(lvl)

		if debug {
			log.Warn("debug mode enabled")
		}

		root.ctx = context.Background()
		log.Debug("assigned the root context")

		if root.format == "" {
			switch cmd.Name() {
			case listVolumesCmd.Name():
				if listVolumes.paging {
					root.format = volumeInfoFormat
				} else {
					root.format = listVolumesFormat
				}
			case listSnapshotsCmd.Name():
				if listSnapshots.paging {
					root.format = snapshotInfoFormat
				} else {
					root.format = listSnapshotsFormat
				}
			case createSnapshotCmd.Name():
				root.format = snapshotInfoFormat
			case createVolumeCmd.Name():
				root.format = volumeInfoFormat
			case pluginInfoCmd.Name():
				root.format = pluginInfoFormat
			case pluginCapsCmd.Name():
				root.format = pluginCapsFormat
			case probeCmd.Name():
				root.format = probeFormat
			case nodeGetVolumeStatsCmd.Name():
				root.format = statsFormat
			case nodeGetInfoCmd.Name():
				root.format = nodeInfoFormat
			}
		}
		if root.format != "" {
			tpl, err := template.New("t").Funcs(template.FuncMap{
				"isa": func(o interface{}, t string) bool {
					return fmt.Sprintf("%T", o) == t
				},
			}).Parse(root.format)
			if err != nil {
				return err
			}
			root.tpl = tpl
		}

		root.secrets = utils.ParseMap(os.Getenv("X_CSI_SECRETS"))

		opts := []grpc.DialOption{
			grpc.WithContextDialer(
				func(_ context.Context, addr string) (net.Conn, error) {
					proto, addr, err := utils.ParseProtoAddr(root.endpoint)
					log.WithFields(log.Fields{
						"proto":   proto,
						"addr":    addr,
						"timeout": root.timeout,
					}).Debug("parsed endpoint info")
					if err != nil {
						return nil, err
					}
					return net.DialTimeout(proto, addr, root.timeout)
				}),
		}

		if root.insecure {
			opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
		}

		if o := getClientInterceptorsDialOpt(); o != nil {
			opts = append(opts, o)
		}

		client, err := grpc.NewClient(root.endpoint, opts...)
		if err != nil {
			return err
		}
		root.client = client

		return nil
	},
}

RootCmd represents the base command when called without any subcommands

Functions

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

Types

This section is empty.

Jump to

Keyboard shortcuts

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