cmd

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2020 License: MIT Imports: 71 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApplyAnnotationsFlag = "save-config"
	DefaultErrorExitCode = 1
)

Variables

View Source
var (
	ALL_NAMESPACE              = ""
	NO_STRING                  = ""
	DEFAULT_NODE_LABEL_FILTERS = []string{"app", "env"}
	//STATIS VALUE
	KUBENX_HOMEDIR      = ".kubenx"
	SSH_DEFAULT_PATH    = "ssh"
	TARGET_DEFAULT_PORT = "22"
	AWS_IAM_ANNOTATION  = "eks.amazonaws.com/role-arn"
	AUTH_API_VERSION    = "client.authentication.k8s.io/v1alpha1"
	AUTH_COMMAND        = "aws"

	//Color Definition
	Red    = color.New(color.FgRed).PrintlnFunc()
	Blue   = color.New(color.FgBlue).PrintlnFunc()
	Green  = color.New(color.FgGreen).PrintlnFunc()
	Yellow = color.New(color.FgYellow).PrintlnFunc()
	Cyan   = color.New(color.FgCyan).PrintlnFunc()

	//OPEN_ID_CA_FINGERPRINT
	CA_FINGERPRINT = "9e99a48a9960b14926bb7f3b02e22da2b0ab7280"

	//Error Message
	NO_FILE_EXCEPTION = "No file exists... Please check the file path"
)
View Source
var ErrExit = fmt.Errorf("exit")

ErrExit may be passed to CheckError to instruct it to output nothing but exit with status code 1.

View Source
var FlagRegistry = []Flag{
	{
		Name:          "namespace",
		Shorthand:     "n",
		Usage:         "Run deployments in the specified namespace",
		Value:         aws.String(NO_STRING),
		DefValue:      "",
		FlagAddMethod: "StringVar",
		DefinedOn:     []string{"pod", "deployment", "service", "serviceaccount", "configmap", "ingress", "role", "rolebinding", "secret"},
	},
	{
		Name:          "region",
		Shorthand:     "r",
		Usage:         "Run command to specific region",
		Value:         aws.String(NO_STRING),
		DefValue:      "ap-northeast-2",
		FlagAddMethod: "StringVar",
		DefinedOn:     []string{"cluster", "init", "update"},
	},
	{
		Name:          "all",
		Shorthand:     "A",
		Usage:         "All namespace flag",
		Value:         aws.Bool(false),
		DefValue:      false,
		FlagAddMethod: "BoolVar",
		DefinedOn:     []string{"pod", "deployment", "service", "serviceaccount", "configmap", "ingress", "role", "clusterrole", "rolebinding", "clusterrolebinding", "secret"},
	},
}

FlagRegistry is a list of all Skaffold CLI flags. When adding a new flag to the registry, please specify the command/commands to which the flag belongs in `DefinedOn` field. If the flag is a global flag, or belongs to all the subcommands, / specify "all" FlagAddMethod is method which defines a flag value with specified name, default value, and usage string. e.g. `StringVar`, `BoolVar`

View Source
var (
	TAG_PREFIX = "kubernetes"
)

Functions

func AddApplyAnnotationFlags

func AddApplyAnnotationFlags(cmd *cobra.Command)

func AddApplyAnnotationVarFlags

func AddApplyAnnotationVarFlags(cmd *cobra.Command, applyAnnotation *bool)

func AddDryRunFlag

func AddDryRunFlag(cmd *cobra.Command)

AddDryRunFlag adds dry-run flag to a command. Usually used by mutations.

func AddFilenameOptionFlags

func AddFilenameOptionFlags(cmd *cobra.Command, options *resource.FilenameOptions, usage string)

func AddGeneratorFlags

func AddGeneratorFlags(cmd *cobra.Command, defaultGenerator string)

AddGeneratorFlags adds flags common to resource generation commands TODO: need to take a pass at other generator commands to use this set of flags

func AddIncludeUninitializedFlag

func AddIncludeUninitializedFlag(cmd *cobra.Command)

func AddJsonFilenameFlag

func AddJsonFilenameFlag(flags *pflag.FlagSet, value *[]string, usage string)

func AddKustomizeFlag

func AddKustomizeFlag(flags *pflag.FlagSet, value *string)

AddKustomizeFlag adds kustomize flag to a command

func AddPodRunningTimeoutFlag

func AddPodRunningTimeoutFlag(cmd *cobra.Command, defaultTimeout time.Duration)

func AddServerSideApplyFlags

func AddServerSideApplyFlags(cmd *cobra.Command)

func AddSourceToErr

func AddSourceToErr(verb string, source string, err error) error

AddSourceToErr adds handleResourcePrefix and source string to error message. verb is the string like "creating", "deleting" etc. source is the filename or URL to the template file(*.json or *.yaml), or stdin to use to handle the resource.

func AddValidateFlags

func AddValidateFlags(cmd *cobra.Command)

func AddValidateOptionFlags

func AddValidateOptionFlags(cmd *cobra.Command, options *ValidateOptions)

func BehaviorOnFatal

func BehaviorOnFatal(f func(string, int))

BehaviorOnFatal allows you to override the default behavior when a fatal error occurs, which is to call os.Exit(code). You can pass 'panic' as a function here if you prefer the panic() over os.Exit(1).

func BytesToString

func BytesToString(bytes []byte) (s string)

func CheckErr

func CheckErr(err error)

CheckErr prints a user friendly error to STDERR and exits with a non-zero exit code. Unrecognized errors will be printed with an "error: " prefix.

This method is generic to the command in use and may be used by non-Kubectl commands.

func DefaultBehaviorOnFatal

func DefaultBehaviorOnFatal()

DefaultBehaviorOnFatal allows you to undo any previous override. Useful in tests.

func DefaultSubCommandRun

func DefaultSubCommandRun(out io.Writer) func(c *cobra.Command, args []string)

DefaultSubCommandRun prints a command's help string to the specified output if no arguments (sub-commands) are provided, or a usage error otherwise.

func DumpReaderToFile

func DumpReaderToFile(reader io.Reader, filename string) error

DumpReaderToFile writes all data from the given io.Reader to the specified file (usually for temporary use).

func GetCurrentCluster

func GetCurrentCluster() (string, error)

Get Current Cluster

func GetDryRunFlag

func GetDryRunFlag(cmd *cobra.Command) bool

func GetFieldManagerFlag

func GetFieldManagerFlag(cmd *cobra.Command) string

func GetFlagBool

func GetFlagBool(cmd *cobra.Command, flag string) bool

func GetFlagDuration

func GetFlagDuration(cmd *cobra.Command, flag string) time.Duration

func GetFlagInt

func GetFlagInt(cmd *cobra.Command, flag string) int

Assumes the flag has a default value.

func GetFlagInt32

func GetFlagInt32(cmd *cobra.Command, flag string) int32

Assumes the flag has a default value.

func GetFlagInt64

func GetFlagInt64(cmd *cobra.Command, flag string) int64

Assumes the flag has a default value.

func GetFlagString

func GetFlagString(cmd *cobra.Command, flag string) string

func GetFlagStringArray

func GetFlagStringArray(cmd *cobra.Command, flag string) []string

GetFlagStringArray can be used to accept multiple argument with flag repetition (e.g. -f arg1 -f arg2 ...)

func GetFlagStringSlice

func GetFlagStringSlice(cmd *cobra.Command, flag string) []string

GetFlagStringSlice can be used to accept multiple argument with flag repetition (e.g. -f arg1,arg2 -f arg3 ...)

func GetForceConflictsFlag

func GetForceConflictsFlag(cmd *cobra.Command) bool

func GetPodRunningTimeoutFlag

func GetPodRunningTimeoutFlag(cmd *cobra.Command) (time.Duration, error)

func GetResourcesAndPairs

func GetResourcesAndPairs(args []string, pairType string) (resources []string, pairArgs []string, err error)

GetResourcesAndPairs retrieves resources and "KEY=VALUE or KEY-" pair args from given args

func GetServerSideApplyFlag

func GetServerSideApplyFlag(cmd *cobra.Command) bool

func IsFilenameSliceEmpty

func IsFilenameSliceEmpty(filenames []string, directory string) bool

func IsSiblingCommandExists

func IsSiblingCommandExists(cmd *cobra.Command, targetCmdName string) bool

IsSiblingCommandExists receives a pointer to a cobra command and a target string. Returns true if the target string is found in the list of sibling commands.

func ManualStrip

func ManualStrip(file []byte) []byte

ManualStrip is used for dropping comments from a YAML file

func Merge

func Merge(codec runtime.Codec, dst runtime.Object, fragment string) (runtime.Object, error)

Merge requires JSON serialization TODO: merge assumes JSON serialization, and does not properly abstract API retrieval

func MultilineError

func MultilineError(prefix string, err error) string

MultilineError returns a string representing an error that splits sub errors into their own lines. The returned string will end with a newline.

func MultipleErrors

func MultipleErrors(prefix string, errs []error) string

MultipleErrors returns a newline delimited string containing the prefix and referenced errors in standard form.

func NewCmdCluster

func NewCmdCluster() *cobra.Command

Get new get function

func NewCmdCompletion

func NewCmdCompletion() *cobra.Command

Create Command for get pod

func NewCmdConfig

func NewCmdConfig() *cobra.Command

Create Command for get pod

func NewCmdConfigDelete

func NewCmdConfigDelete() *cobra.Command

Delete config command

func NewCmdConfigInit

func NewCmdConfigInit() *cobra.Command

Init config command

func NewCmdConfigUpdate

func NewCmdConfigUpdate() *cobra.Command

Update config command

func NewCmdContext

func NewCmdContext() *cobra.Command

Create Command for get pod

func NewCmdGet

func NewCmdGet() *cobra.Command

Get new get function

func NewCmdGetCluster

func NewCmdGetCluster() *cobra.Command

Get new get function

func NewCmdGetClusterRole

func NewCmdGetClusterRole() *cobra.Command

Create Command for get cluster role

func NewCmdGetClusterRoleBinding

func NewCmdGetClusterRoleBinding() *cobra.Command

Create Command for get cluster role

func NewCmdGetConfigMap

func NewCmdGetConfigMap() *cobra.Command

Create Command for get pod

func NewCmdGetDeployment

func NewCmdGetDeployment() *cobra.Command

Create Command for get service

func NewCmdGetIngress

func NewCmdGetIngress() *cobra.Command

Create Command for get service

func NewCmdGetNode

func NewCmdGetNode() *cobra.Command

Create Command for get pod

func NewCmdGetPod

func NewCmdGetPod() *cobra.Command

Create Command for get pod

func NewCmdGetRole

func NewCmdGetRole() *cobra.Command

Create Command for get pod

func NewCmdGetRolebinding

func NewCmdGetRolebinding() *cobra.Command

Create Command for get pod

func NewCmdGetSecret

func NewCmdGetSecret() *cobra.Command

Create Command for get pod

func NewCmdGetService

func NewCmdGetService() *cobra.Command

Create Command for get service

func NewCmdGetServiceAccount

func NewCmdGetServiceAccount() *cobra.Command

Create Command for get pod

func NewCmdInitCluster

func NewCmdInitCluster() *cobra.Command

Init Cluster

func NewCmdInspect

func NewCmdInspect() *cobra.Command

Create Command for get pod

func NewCmdInspectNode

func NewCmdInspectNode() *cobra.Command

Create Command for get pod

func NewCmdNamespace

func NewCmdNamespace() *cobra.Command

Create Command for get pod

func NewCmdPortForward

func NewCmdPortForward() *cobra.Command

Start Port Forwarding

func NewCmdSearch

func NewCmdSearch() *cobra.Command

Create Command for get pod

func NewCmdSearchLabel

func NewCmdSearchLabel() *cobra.Command

Search Label command

func NewCmdVersion

func NewCmdVersion() *cobra.Command

Create Command for get pod

func NewKubenxCommand

func NewKubenxCommand(out, err io.Writer) *cobra.Command

Get New Kubenx Command

func ParsePairs

func ParsePairs(pairArgs []string, pairType string, supportRemove bool) (newPairs map[string]string, removePairs []string, err error)

ParsePairs retrieves new and remove pairs (if supportRemove is true) from "KEY=VALUE or KEY-" pair args

func PrintErrorWithCauses

func PrintErrorWithCauses(err error, errOut io.Writer) bool

PrintErrorWithCauses prints an error's kind, name, and each of the error's causes in a new line. The returned string will end with a newline. Returns true if a case exists to handle the error type, or false otherwise.

func RequireNoArguments

func RequireNoArguments(c *cobra.Command, args []string)

RequireNoArguments exits with a usage error if extra arguments are provided.

func RunCompletion

func RunCompletion(out io.Writer, boilerPlate string, cmd *cobra.Command, args []string) error

RunCompletion checks given arguments and executes command

func SetCommandFlags

func SetCommandFlags(cmd *cobra.Command)

Add command flags

func StandardErrorMessage

func StandardErrorMessage(err error) (string, bool)

StandardErrorMessage translates common errors into a human readable message, or returns false if the error is not one of the recognized types. It may also log extended information to klog.

This method is generic to the command in use and may be used by non-Kubectl commands.

func StringToBytes

func StringToBytes(str string) []byte

func StripComments

func StripComments(file []byte) []byte

StripComments will transform a YAML file into JSON, thus dropping any comments in it. Note that if the given file has a syntax error, the transformation will fail and we will manually drop all comments from the file.

func UsageErrorf

func UsageErrorf(cmd *cobra.Command, format string, args ...interface{}) error

func Warning

func Warning(cmdErr io.Writer, newGeneratorName, oldGeneratorName string)

Types

type Bastion

type Bastion struct {
	Servers []Server `json:"bastion"`
}

an array of bastion server

type Builder

type Builder interface {
	WithDescription(description string) Builder
	WithLongDescription(description string) Builder
	SetAliases(alias []string) Builder
	AddCommand(cmd *cobra.Command) Builder
	AddGetGroups() Builder
	AddSearchGroups() Builder
	AddInspectGroups() Builder
	AddConfigGroups() Builder
	SetFlags() Builder
	RunWithNoArgs(action func(context.Context, io.Writer) error) *cobra.Command
	RunWithArgs(action func(context.Context, io.Writer, []string) error) *cobra.Command
	RunWithArgsAndCmd(action func(context.Context, io.Writer, *cobra.Command, []string) error) *cobra.Command
}

func NewCmd

func NewCmd(use string) Builder

NewCmd creates a new command builder.

type Executor

type Executor struct {
	Client       *kubernetes.Clientset
	BetaV1Client *v1beta1.ExtensionsV1beta1Client
	RbacV1Client *rbacv1.RbacV1Client
	EKS          *eks.EKS
	EC2          *ec2.EC2
	IAM          *iam.IAM
	Config       *rest.Config
	Namespace    string
	Context      context.Context
}

type Flag

type Flag struct {
	Name               string
	Shorthand          string
	Usage              string
	Value              interface{}
	DefValue           interface{}
	DefValuePerCommand map[string]interface{}
	FlagAddMethod      string
	DefinedOn          []string
	Hidden             bool
	// contains filtered or unexported fields
}

This part of code comes from skaffold opensource. https://github.com/GoogleContainerTools/skaffold Flag defines a Skaffold CLI flag which contains a list of subcommands the flag belongs to in `DefinedOn` field.

type PortForwardAPodRequest

type PortForwardAPodRequest struct {
	// RestConfig is the kubernetes config
	RestConfig *rest.Config
	// Pod is the selected pod for this port forwarding
	Pod corev1.Pod
	// LocalPort is the local port that will be selected to expose the PodPort
	LocalPort int
	// PodPort is the target port for the pod
	PodPort int
	// Steams configures where to write or read input from
	Streams genericclioptions.IOStreams
	// StopCh is the channel used to manage the port forward lifecycle
	StopCh <-chan struct{}
	// ReadyCh communicates when the tunnel is ready to receive traffic
	ReadyCh chan struct{}
}

Port Forward Request

type SSHClient

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

SSH Client Configuration

func (*SSHClient) Terminal

func (c *SSHClient) Terminal(config *TerminalConfig) *remoteShell

Terminal create a interactive shell on client.

type SSHConfig

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

SSH Configuration

type ScaleClientFunc

ScaleClientFunc provides a ScalesGetter

var ScaleClientFn ScaleClientFunc = scaleClient

ScaleClientFn gives a way to easily override the function for unit testing if needed.

type Server

type Server struct {
	Key     string `json:"key"`
	Addr    string `json:"addr"`
	Port    string `json:"port"`
	User    string `json:"user"`
	KeyFile string `json:"keyfile"`
}

Server Configuration

type TerminalConfig

type TerminalConfig struct {
	Term   string
	Height int
	Weight int
	Modes  ssh.TerminalModes
}

Terminal Configuration

type ValidateOptions

type ValidateOptions struct {
	EnableValidation bool
}

Jump to

Keyboard shortcuts

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