cli

package module
v0.1.3-elotl1 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

README

Virtual-Kubelet CLI

This project provides a library for rapid prototyping of a virtual-kubelet node. It is not intended for production use and may have breaking changes, but takes as much as made sense from the old command line code from github.com/virtual-kubelet/virtual-kubelet.

Usage

package main

import (
	"context"
	"errors"

	"github.com/sirupsen/logrus"
	cli "github.com/virtual-kubelet/node-cli"
	logruscli "github.com/virtual-kubelet/node-cli/logrus"
	"github.com/virtual-kubelet/node-cli/provider"
	"github.com/virtual-kubelet/virtual-kubelet/log"
	logruslogger "github.com/virtual-kubelet/virtual-kubelet/log/logrus"
)

func main() {
	ctx := cli.ContextWithCancelOnSignal(context.Background())
	logger := logrus.StandardLogger()

	log.L = logruslogger.FromLogrus(logrus.NewEntry(logger))
	logConfig := &logruscli.Config{LogLevel: "info"}

	node, err := cli.New(
		cli.WithProvider("demo", func(cfg provider.InitConfig) (provider.Provider, error) {
			return nil, errors.New("your implementation goes here")
		}),
		// Adds flags and parsing for using logrus as the configured logger
		cli.WithPersistentFlags(logConfig.FlagSet()),
		cli.WithPersistentPreRunCallback(func() error {
			return logruscli.Configure(logConfig, logger)
		}),
	)

	if err != nil {
		panic(err)
	}
	// Args can be specified here, or os.Args[1:] will be used.
	if err := node.Run(ctx); err != nil {
		panic(err)
	}
}

Documentation

Overview

Package cli contains a reusable implemetation for a daemon that acts as a single node on the cluster.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithCancelOnSignal

func ContextWithCancelOnSignal(ctx context.Context, signals ...os.Signal) context.Context

ContextWithCancelOnSignal returns a context which will be cancelled when receiving one of the passed in signals. If no signals are passed in, the default signals SIGTERM and SIGINT are used.

Types

type Command

type Command struct {
	// contains filtered or unexported fields
}

Command builds the CLI command

func New

func New(ctx context.Context, options ...Option) (*Command, error)

New creates a new command. Call `Run()` on the returned object to run the command.

func (*Command) Run

func (c *Command) Run(ctx context.Context, args ...string) error

Run executes the command with the provided args. If args is nil then os.Args[1:] is used

type Option

type Option func(*Command)

Option sets an option on the command.

func WithBaseOpts

func WithBaseOpts(o *opts.Opts) Option

WithBaseOpts sets the base options used

func WithCLIBaseName

func WithCLIBaseName(n string) Option

WithCLIBaseName sets the name of the command. This is used for things like help output.

If not set, the name is taken from `filepath.Base(os.Args[0])`

func WithCLIVersion

func WithCLIVersion(version, buildTime string) Option

WithCLIVersion sets the version details for the `version` subcommand.

func WithKubernetesNodeVersion

func WithKubernetesNodeVersion(v string) Option

WithKubernetesNodeVersion sets the version of kubernetes this should report as to the Kubernetes API server.

func WithPersistentFlags

func WithPersistentFlags(flags *pflag.FlagSet) Option

WithPersistentFlagsAllows you to attach custom, persitent flags to the command. The flags are added to the main command and all sub commands.

func WithPersistentPreRunCallback

func WithPersistentPreRunCallback(f func() error) Option

WithPersistentPreRunCallback adds a callback which is called after flags are processed but before running the command or any sub-command

func WithProvider

func WithProvider(name string, f provider.InitFunc) Option

WithProvider registers a provider which the cli can be initialized with.

Directories

Path Synopsis
internal
Package provider has the interfaces used by the the cli implementing a node
Package provider has the interfaces used by the the cli implementing a node

Jump to

Keyboard shortcuts

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