utils

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2020 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Checkout

func Checkout(gitHubOrg string, project string, branch string) (*git.Repository, error)

Checkout clons a GitHub repo and checks out the specified branch

func CheckoutPrevCommit

func CheckoutPrevCommit(repo *git.Repository) (*plumbing.Reference, error)

CheckoutPrevCommit moves the HEAD pointer to the previous commit. It returns the original HEAD.

func CheckoutReference

func CheckoutReference(repo *git.Repository, ref *plumbing.Reference) error

CheckoutReference moves the HEAD pointer to the specified reference.

func CreateNamespace added in v0.6.0

func CreateNamespace(useInClusterConfig bool, namespace string) error

CreateNamespace creates a new Kubernetes namespace with the provided name

func DoHelmUpgrade

func DoHelmUpgrade(project string, stage string) error

DoHelmUpgrade executes a helm update and upgrade

func ExecuteCommand

func ExecuteCommand(command string, args []string) (string, error)

ExecuteCommand exectues the command using the args

func ExecuteCommandInDirectory

func ExecuteCommandInDirectory(command string, args []string, directory string) (string, error)

ExecuteCommandInDirectory executes the command using the args within the specified directory

func ExistsNamespace added in v0.6.0

func ExistsNamespace(useInClusterConfig bool, namespace string) (bool, error)

ExistsNamespace checks whether a namespace with the provided name exists

func ExpandTilde

func ExpandTilde(fileName string) string

ExpandTilde expands ~ to HOME

func GetChart

func GetChart(project string, service string, stage string, chartName string, configServiceURL string) (*chart.Chart, error)

GetChart reads the chart from the configuration service

func GetClientset

func GetClientset(useInClusterConfig bool) (*kubernetes.Clientset, error)

GetClientset returns the kubernetes Clientset

func GetFiles

func GetFiles(workingPath string, suffixes ...string) ([]string, error)

GetFiles returns a list of files in a directory filtered by the provided suffix

func GetKeptnDirectory

func GetKeptnDirectory() (string, error)

GetKeptnDirectory returns a path, which is used to store logs and possibly creds

func GetKeptnDomain

func GetKeptnDomain(useInClusterConfig bool) (string, error)

GetKeptnDomain reads the configmap keptn-domain in namespace keptn and returns the contained app_domain

func GetKubeAPI

func GetKubeAPI(useInClusterConfig bool) (v1.CoreV1Interface, error)

GetKubeAPI returns the CoreV1Interface

func GetRenderedDeployments

func GetRenderedDeployments(ch *chart.Chart) ([]*appsv1.Deployment, error)

GetRenderedDeployments returns all deployments contained in the provided chart

func GetRenderedServices

func GetRenderedServices(ch *chart.Chart) ([]*corev1.Service, error)

GetRenderedServices returns all services contained in the provided chart

func IsDeployment

func IsDeployment(dpl *appsv1.Deployment) bool

IsDeployment tests whether the provided struct is a deployment

func IsService

func IsService(svc *corev1.Service) bool

IsService tests whether the provided struct is a service

func LoadChart

func LoadChart(data []byte) (*chart.Chart, error)

LoadChart converts a byte array into a Chart

func LoadChartFromPath

func LoadChartFromPath(path string) (*chart.Chart, error)

LoadChartFromPath loads a directory or Helm chart into a Chart

func OpenWS

func OpenWS(connData ConnectionData, apiEndPoint url.URL) (*websocket.Conn, *http.Response, error)

OpenWS opens a websocket

func PackageChart

func PackageChart(ch *chart.Chart) ([]byte, error)

PackageChart packages the chart and returns it

func RestartPodsWithSelector

func RestartPodsWithSelector(useInClusterConfig bool, namespace string, selector string) error

RestartPodsWithSelector restarts the pods which are found in the provided namespace and selector

func ScaleDeployment

func ScaleDeployment(useInClusterConfig bool, deployment string, namespace string, replicas int32) error

func StoreChart

func StoreChart(project string, service string, stage string, chartName string, helmChart []byte, configServiceURL string) error

StoreChart stores a chart in the configuration service

func UserHomeDir

func UserHomeDir() string

UserHomeDir returns the HOME directory by taking into account the operating system

func ValidateKeptnEntityName added in v0.6.0

func ValidateKeptnEntityName(name string) bool

ValidateKeptnEntityName checks whether the provided name represents a valid project, service, or stage name

func WaitForDeploymentToBeRolledOut

func WaitForDeploymentToBeRolledOut(useInClusterConfig bool, deploymentName string, namespace string) error

WaitForDeploymentToBeRolledOut waits until the deployment is Available

func WaitForDeploymentsInNamespace

func WaitForDeploymentsInNamespace(useInClusterConfig bool, namespace string) error

WaitForDeploymentsInNamespace waits until all deployments in a namespace are available

func WaitForPodsWithSelector

func WaitForPodsWithSelector(useInClusterConfig bool, namespace string, selector string,
	retries int, waitingTime time.Duration) error

func WriteLog

func WriteLog(ws *websocket.Conn, logData LogData, shkeptnContext string) error

WriteLog writes the logData to the websocket connection

func WriteWSLog

func WriteWSLog(ws *websocket.Conn, logEvent cloudevents.Event, message string, terminate bool, logLevel string) error

WriteWSLog writes the log event to the websocket

Types

type CombinedLogger

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

CombinedLogger logs messages to the logger as well as to the websocket

func NewCombinedLogger

func NewCombinedLogger(logger *Logger, ws *websocket.Conn, shKeptnContext string) *CombinedLogger

NewCombinedLogger creates a new CombinedLogger which writes log messages to the logger as well as to the websocket

func (*CombinedLogger) Debug

func (l *CombinedLogger) Debug(message string)

Debug logs a debug message

func (*CombinedLogger) Error

func (l *CombinedLogger) Error(message string)

Error logs an error message

func (*CombinedLogger) Info

func (l *CombinedLogger) Info(message string)

Info logs an info message

func (*CombinedLogger) Terminate

func (l *CombinedLogger) Terminate()

Terminate sends a terminate message to the websocket

type ConnectionData

type ConnectionData struct {
	EventContext apimodels.EventContext `json:"eventContext"`
}

ConnectionData stores EventContext and Success data

type IncompleteCE

type IncompleteCE struct {
	ConnData ConnectionData `json:"data"`
}

IncompleteCE is a helper type for unmarshalling the CE data

type KeptnHandler

type KeptnHandler struct {
	ResourceHandler *utils.ResourceHandler
}

KeptnHandler provides an interface to keptn resources

func NewKeptnHandler

func NewKeptnHandler(rh *utils.ResourceHandler) *KeptnHandler

NewKeptnHandler returns a new KeptnHandler instance

func (*KeptnHandler) GetShipyard

func (k *KeptnHandler) GetShipyard(project string) (*models.Shipyard, error)

GetShipyard returns the shipyard definition of a project

type LogData

type LogData struct {
	Message   string `json:"message"`
	Terminate bool   `json:"terminate"`
	LogLevel  string `json:"loglevel"`
}

LogData represents log data

type Logger

type Logger struct {
	KeptnContext string `json:"keptnContext"`
	EventID      string `json:"eventId"`
	ServiceName  string `json:"keptnService"`
}

Logger contains data for logging

func NewLogger

func NewLogger(keptnContext string, eventID string, serviceName string) *Logger

NewLogger creates a new Logger

func (*Logger) Debug

func (l *Logger) Debug(message string)

Debug logs a debug message

func (*Logger) Error

func (l *Logger) Error(message string)

Error logs an error message

func (*Logger) Info

func (l *Logger) Info(message string)

Info logs an info message

type LoggerInterface

type LoggerInterface interface {
	Info(message string)
	Error(message string)
	Debug(message string)
}

LoggerInterface collects signatures of the logger

type MyCloudEvent

type MyCloudEvent struct {
	SpecVersoin    string          `json:"specversion"`
	ContentType    string          `json:"contentType"`
	Data           json.RawMessage `json:"data"`
	ID             string          `json:"id"`
	Time           string          `json:"time"`
	Type           string          `json:"type"`
	Source         string          `json:"source"`
	ShKeptnContext string          `json:"shkeptncontext"`
}

MyCloudEvent represents a keptn cloud event

Jump to

Keyboard shortcuts

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