common

package
Version: v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultDevfileInitCommand is a predefined devfile command for init
	DefaultDevfileInitCommand PredefinedDevfileCommands = "devinit"

	// DefaultDevfileBuildCommand is a predefined devfile command for build
	DefaultDevfileBuildCommand PredefinedDevfileCommands = "devbuild"

	// DefaultDevfileRunCommand is a predefined devfile command for run
	DefaultDevfileRunCommand PredefinedDevfileCommands = "devrun"

	// DefaultDevfileDebugCommand is a predefined devfile command for debug
	DefaultDevfileDebugCommand PredefinedDevfileCommands = "debugrun"

	// SupervisordInitContainerName The init container name for supervisord
	SupervisordInitContainerName = "copy-supervisord"

	// SupervisordControlCommand sub command which stands for control
	SupervisordControlCommand = "ctl"

	// SupervisordVolumeName Create a custom name and (hope) that users don't use the *exact* same name in their deployment (occlient.go)
	SupervisordVolumeName = "odo-supervisord-shared-data"

	// SupervisordMountPath The supervisord Mount Path for the container mounting the supervisord volume
	SupervisordMountPath = "/opt/odo/"

	// SupervisordBinaryPath The supervisord binary path inside the container volume mount
	SupervisordBinaryPath = "/opt/odo/bin/supervisord"

	// SupervisordConfFile The supervisord configuration file inside the container volume mount
	SupervisordConfFile = "/opt/odo/conf/devfile-supervisor.conf"

	// OdoInitImageContents The path to the odo init image contents
	OdoInitImageContents = "/opt/odo-init/."

	// BinBash The path to sh executable
	BinBash = "/bin/sh"

	// Default volume size for volumes defined in a devfile
	DefaultVolumeSize = "1Gi"

	// EnvProjectsRoot is the env defined for /projects where component mountSources=true
	EnvProjectsRoot = "PROJECTS_ROOT"

	// EnvOdoCommandRunWorkingDir is the env defined in the runtime component container which holds the work dir for the run command
	EnvOdoCommandRunWorkingDir = "ODO_COMMAND_RUN_WORKING_DIR"

	// EnvOdoCommandRun is the env defined in the runtime component container which holds the run command to be executed
	EnvOdoCommandRun = "ODO_COMMAND_RUN"

	// EnvOdoCommandDebugWorkingDir is the env defined in the runtime component container which holds the work dir for the debug command
	EnvOdoCommandDebugWorkingDir = "ODO_COMMAND_DEBUG_WORKING_DIR"

	// EnvOdoCommandDebug is the env defined in the runtime component container which holds the debug command to be executed
	EnvOdoCommandDebug = "ODO_COMMAND_DEBUG"

	// EnvDebugPort is the env defined in the runtime component container which holds the debug port for remote debugging
	EnvDebugPort = "DEBUG_PORT"

	// ShellExecutable is the shell executable
	ShellExecutable = "/bin/sh"

	// SupervisordCtlSubCommand is the supervisord sub command ctl
	SupervisordCtlSubCommand = "ctl"

	// PreStart is a devfile event
	PreStart DevfileEventType = "preStart"

	// PostStart is a devfile event
	PostStart DevfileEventType = "postStart"

	// PreStop is a devfile event
	PreStop DevfileEventType = "preStop"

	// PostStop is a devfile event
	PostStop DevfileEventType = "postStop"
)

Variables

This section is empty.

Functions

func CreateConsoleOutputWriterAndChannel added in v1.2.6

func CreateConsoleOutputWriterAndChannel() (*io.PipeWriter, chan []string)

CreateConsoleOutputWriterAndChannel is a utility function that returns a pipeWriter and a channel; any strings written to that PipeWriter will be output to the channel (as lines) when the writer closes. This is used to retrieve the stdout/stderr output from the container exec commands.

The io.PipeWriter can be passed to ExecuteCommand(...) above, in order to receive the full stderr/stdout output from the process. See calling functions of CreateConsoleOutputWriterAndChannel for examples of usage.

func ExecuteCommand added in v1.2.6

func ExecuteCommand(client ExecClient, compInfo ComponentInfo, command []string, show bool, consoleOutputStdout *io.PipeWriter, consoleOutputStderr *io.PipeWriter) (err error)

ExecuteCommand executes the given command in the pod's container

func GetBootstrapperImage added in v1.1.2

func GetBootstrapperImage() string

GetBootstrapperImage returns the odo-init bootstrapper image

func GetBuildCommand added in v1.1.2

func GetBuildCommand(data data.DevfileData, devfileBuildCmd string) (buildCommand common.DevfileCommand, err error)

GetBuildCommand iterates through the components in the devfile and returns the build command

func GetComponentEnvVar added in v1.2.5

func GetComponentEnvVar(env string, envs []common.Env) string

GetComponentEnvVar returns true if a list of env vars contains the specified env var If the env exists, it returns the value of it

func GetDebugCommand added in v1.2.3

func GetDebugCommand(data data.DevfileData, devfileDebugCmd string) (debugCommand common.DevfileCommand, err error)

GetDebugCommand iterates through the components in the devfile and returns the debug command

func GetDevfileContainerComponents added in v1.2.5

func GetDevfileContainerComponents(data data.DevfileData) []common.DevfileComponent

GetDevfileContainerComponents iterates through the components in the devfile and returns a list of devfile container components

func GetDevfileVolumeComponents added in v1.2.5

func GetDevfileVolumeComponents(data data.DevfileData) map[string]common.DevfileComponent

GetDevfileVolumeComponents iterates through the components in the devfile and returns a map of devfile volume components

func GetInitCommand added in v1.2.1

func GetInitCommand(data data.DevfileData, devfileInitCmd string) (initCommand common.DevfileCommand, err error)

GetInitCommand iterates through the components in the devfile and returns the init command

func GetRunCommand added in v1.1.2

func GetRunCommand(data data.DevfileData, devfileRunCmd string) (runCommand common.DevfileCommand, err error)

GetRunCommand iterates through the components in the devfile and returns the run command

func GetTestCommand added in v1.2.4

func GetTestCommand(data data.DevfileData, devfileTestCmd string) (runCommand common.DevfileCommand, err error)

GetTestCommand iterates through the components in the devfile and returns the test command

func GetVolumes added in v1.2.0

func GetVolumes(devfileObj devfileParser.DevfileObj) map[string][]DevfileVolume

GetVolumes iterates through the components in the devfile and returns a map of container name to the devfile volumes

func IsEnvPresent added in v1.2.0

func IsEnvPresent(envVars []common.Env, envVarName string) bool

IsEnvPresent checks if the env variable is present in an array of env variables

func IsPortPresent added in v1.2.0

func IsPortPresent(endpoints []common.Endpoint, port int) bool

IsPortPresent checks if the port is present in the endpoints array

func IsRestartRequired added in v1.2.1

func IsRestartRequired(hotReload bool, runModeChanged bool) bool

IsRestartRequired checks if restart required for run command

func New added in v1.2.6

func New(devfile common.DevfileCommand, knowCommands map[string]common.DevfileCommand, executor commandExecutor) (command, error)

New returns a new command implementation based on the specified devfile command and the known commands

func ValidateAndGetDebugDevfileCommands added in v1.2.3

func ValidateAndGetDebugDevfileCommands(data data.DevfileData, devfileDebugCmd string) (pushDebugCommand common.DevfileCommand, err error)

ValidateAndGetDebugDevfileCommands validates the debug command

func ValidateAndGetTestDevfileCommands added in v1.2.4

func ValidateAndGetTestDevfileCommands(data data.DevfileData, devfileTestCmd string) (testCommand common.DevfileCommand, err error)

ValidateAndGetTestDevfileCommands validates the test command

func ValidateCommand added in v1.2.6

func ValidateCommand(data data.DevfileData, command common.DevfileCommand) (err error)

ValidateCommand validates the given command 1. command has to be of type exec or composite, if composite command is validated further 2. component should be present 3. commandline should be present 4. command must map to a valid container component

Types

type AdapterContext

type AdapterContext struct {
	ComponentName string                   // ComponentName is the odo component name, it is NOT related to any devfile components
	Context       string                   // Context is the given directory containing the source code and configs
	AppName       string                   // the application name associated to a component
	Devfile       devfileParser.DevfileObj // Devfile is the object returned by the Devfile parser
}

AdapterContext is a construct that is common to all adapters

type CommandNames added in v1.2.1

type CommandNames struct {
	DefaultName string
	AdapterName string
}

CommandNames is a struct to store the default and adapter names for devfile commands

type ComponentAdapter

type ComponentAdapter interface {
	Push(parameters PushParameters) error
	DoesComponentExist(cmpName string) (bool, error)
	Delete(labels map[string]string, show bool) error
	Test(testCmd string, show bool) error
	Log(follow, debug bool) (io.ReadCloser, error)
	Exec(command []string) error
	// contains filtered or unexported methods
}

ComponentAdapter defines the functions that platform-specific adapters must implement

type ComponentInfo added in v1.2.0

type ComponentInfo struct {
	PodName       string
	ContainerName string
	SourceMount   string
}

ComponentInfo is a struct that holds information about a component i.e.; pod name, container name, and source mount (if applicable)

func (ComponentInfo) IsEmpty added in v1.2.6

func (ci ComponentInfo) IsEmpty() bool

type ComponentInfoFactory added in v1.2.6

type ComponentInfoFactory func(command common.DevfileCommand) (ComponentInfo, error)

ComponentInfoFactory defines a type for a function which creates a ComponentInfo based on the information provided by the specified DevfileCommand. This is used by adapters to provide the proper ComponentInfo identifying which component (including supervisor) to target when executing the command.

type DevfileEventType added in v1.2.6

type DevfileEventType string

DevfileEventType encapsulates constants for devfile events

type DevfileVolume

type DevfileVolume struct {
	Name          string
	ContainerPath string
	Size          string
}

DevfileVolume is a struct for Devfile volume that is common to all the adapters

type ExecClient added in v1.2.6

type ExecClient interface {
	ExecCMDInContainer(ComponentInfo, []string, io.Writer, io.Writer, io.Reader, bool) error
}

ExecClient is a wrapper around ExecCMDInContainer which executes a command in a specific container of a pod.

type GenericAdapter added in v1.2.6

type GenericAdapter struct {
	AdapterContext
	// contains filtered or unexported fields
}

GenericAdapter provides common code that can be reused by adapters allowing them to focus on more specific behavior

func NewGenericAdapter added in v1.2.6

func NewGenericAdapter(client ExecClient, context AdapterContext) *GenericAdapter

NewGenericAdapter creates a new GenericAdapter instance based on the provided parameters. Client code must call InitWith on the newly created instance to finish the setup, providing the child implementation as parameter

func (GenericAdapter) ComponentInfo added in v1.2.6

func (a GenericAdapter) ComponentInfo(command common.DevfileCommand) (ComponentInfo, error)

func (GenericAdapter) ExecCMDInContainer added in v1.2.6

func (a GenericAdapter) ExecCMDInContainer(info ComponentInfo, cmd []string, stdOut io.Writer, stdErr io.Writer, stdIn io.Reader, show bool) error

func (GenericAdapter) ExecDevfile added in v1.2.6

func (a GenericAdapter) ExecDevfile(commandsMap PushCommandsMap, componentExists bool, params PushParameters) (err error)

ExecDevFile executes all the commands from the devfile in order: init and build - which are both optional, and a compulsory run. Init only runs once when the component is created.

func (GenericAdapter) ExecDevfileEvent added in v1.2.6

func (a GenericAdapter) ExecDevfileEvent(events []string, eventType DevfileEventType, show bool) error

ExecDevfileEvent receives a Devfile Event (PostStart, PreStop etc.) and loops through them Each Devfile Command associated with the given event is retrieved, and executed in the container specified in the command

func (GenericAdapter) ExecuteCommand added in v1.2.6

func (a GenericAdapter) ExecuteCommand(compInfo ComponentInfo, command []string, show bool, consoleOutputStdout *io.PipeWriter, consoleOutputStderr *io.PipeWriter) (err error)

ExecuteCommand simply calls exec.ExecuteCommand using the GenericAdapter's client

func (GenericAdapter) ExecuteDevfileCommand added in v1.2.6

func (a GenericAdapter) ExecuteDevfileCommand(command common.DevfileCommand, show bool) error

ExecuteDevfileCommand executes the devfile init, build and test command actions synchronously

func (*GenericAdapter) InitWith added in v1.2.6

func (a *GenericAdapter) InitWith(executor commandExecutor)

InitWith finishes the GenericAdapter setup after the rest of the adapter is created. This must be called before the adapter implementation is used and the specific implementation must be passed as parameter.

func (GenericAdapter) Logger added in v1.2.6

func (GenericAdapter) SupervisorComponentInfo added in v1.2.6

func (a GenericAdapter) SupervisorComponentInfo(command common.DevfileCommand) (ComponentInfo, error)

type PredefinedDevfileCommands added in v1.1.2

type PredefinedDevfileCommands string

PredefinedDevfileCommands encapsulates constants for predefined devfile commands

type PushCommandsMap added in v1.2.2

PushCommandsMap stores the commands to be executed as per their types.

func NewPushCommandMap added in v1.2.2

func NewPushCommandMap() PushCommandsMap

NewPushCommandMap returns the instance of PushCommandsMap

func ValidateAndGetPushDevfileCommands added in v1.1.2

func ValidateAndGetPushDevfileCommands(data data.DevfileData, devfileInitCmd, devfileBuildCmd, devfileRunCmd string) (commandMap PushCommandsMap, err error)

ValidateAndGetPushDevfileCommands validates the build and the run command, if provided through odo push or else checks the devfile for devBuild and devRun. It returns the build and run commands if its validated successfully, error otherwise.

type PushParameters added in v1.1.2

type PushParameters struct {
	Path                     string                  // Path refers to the parent folder containing the source code to push up to a component
	WatchFiles               []string                // Optional: WatchFiles is the list of changed files detected by odo watch. If empty or nil, odo will check .odo/odo-file-index.json to determine changed files
	WatchDeletedFiles        []string                // Optional: WatchDeletedFiles is the list of deleted files detected by odo watch. If empty or nil, odo will check .odo/odo-file-index.json to determine deleted files
	IgnoredFiles             []string                // IgnoredFiles is the list of files to not push up to a component
	ForceBuild               bool                    // ForceBuild determines whether or not to push all of the files up to a component or just files that have changed, added or removed.
	Show                     bool                    // Show tells whether the devfile command output should be shown on stdout
	DevfileInitCmd           string                  // DevfileInitCmd takes the init command through the command line and overwrites devfile init command
	DevfileBuildCmd          string                  // DevfileBuildCmd takes the build command through the command line and overwrites devfile build command
	DevfileRunCmd            string                  // DevfileRunCmd takes the run command through the command line and overwrites devfile run command
	DevfileDebugCmd          string                  // DevfileDebugCmd takes the debug command through the command line and overwrites the devfile debug command
	DevfileScanIndexForWatch bool                    // DevfileScanIndexForWatch is true if watch's push should regenerate the index file during SyncFiles, false otherwise. See 'pkg/sync/adapter.go' for details
	EnvSpecificInfo          envinfo.EnvSpecificInfo // EnvSpecificInfo contains infomation of env.yaml file
	Debug                    bool                    // Runs the component in debug mode
	DebugPort                int                     // Port used for remote debugging
	RunModeChanged           bool                    // It determines if run mode is changed from run to debug or vice versa
}

PushParameters is a struct containing the parameters to be used when pushing to a devfile component

type Storage

type Storage struct {
	Name   string
	Volume DevfileVolume
}

Storage is a struct that is common to all the adapters

type StorageAdapter

type StorageAdapter interface {
	Create([]Storage) error
}

StorageAdapter defines the storage functions that platform-specific adapters must implement

type SyncParameters added in v1.2.0

type SyncParameters struct {
	PushParams      PushParameters
	CompInfo        ComponentInfo
	PodChanged      bool
	ComponentExists bool
}

SyncParameters is a struct containing the parameters to be used when syncing a devfile component

Jump to

Keyboard shortcuts

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