utils

package
v0.0.0-...-f5c220b Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2019 License: Apache-2.0 Imports: 44 Imported by: 1

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 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 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 ResolveXipIo

func ResolveXipIo(network, addr string) (net.Conn, error)

ResolveXipIo resolves a xip io address

func ResolveXipIoWithContext

func ResolveXipIoWithContext(ctx context.Context, network, addr string) (net.Conn, error)

ResolveXipIoWithContext resolves a xip io address

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 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 ChannelInfo

type ChannelInfo struct {
	Token     string `json:"token"`
	ChannelID string `json:"channelID"`
}

ChannelInfo stores a token and a channelID used for opening the websocket

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 ConfigService

type ConfigService interface {
	// contains filtered or unexported methods
}

ConfigService represents the interface for accessing the configuration service

type ConnectionData

type ConnectionData struct {
	ChannelInfo ChannelInfo `json:"channelInfo"`
}

ConnectionData stores ChannelInfo 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 *ResourceHandler
}

KeptnHandler provides an interface to keptn resources

func NewKeptnHandler

func NewKeptnHandler(rh *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

type ProjectHandler

type ProjectHandler struct {
	BaseURL    string
	AuthToken  string
	AuthHeader string
	HTTPClient *http.Client
	Scheme     string
}

ProjectHandler handles projects

func NewAuthenticatedProjectHandler

func NewAuthenticatedProjectHandler(baseURL string, authToken string, authHeader string, httpClient *http.Client, scheme string) *ProjectHandler

NewAuthenticatedProjectHandler returns a new ProjectHandler that authenticates at the endpoint via the provided token

func NewProjectHandler

func NewProjectHandler(baseURL string) *ProjectHandler

NewProjectHandler returns a new ProjectHandler

func (*ProjectHandler) CreateProject

func (p *ProjectHandler) CreateProject(project models.Project) (*models.Error, error)

CreateProject creates a new project

func (*ProjectHandler) DeleteProject

func (p *ProjectHandler) DeleteProject(project models.Project) (*models.Error, error)

DeleteProject deletes a project

func (*ProjectHandler) GetProject

func (p *ProjectHandler) GetProject(project models.Project) (*models.Project, *models.Error)

GetProject returns a project

type ResourceHandler

type ResourceHandler struct {
	BaseURL    string
	AuthToken  string
	AuthHeader string
	HTTPClient *http.Client
	Scheme     string
}

ResourceHandler handles resources

func NewAuthenticatedResourceHandler

func NewAuthenticatedResourceHandler(baseURL string, authToken string, authHeader string, httpClient *http.Client, scheme string) *ResourceHandler

NewAuthenticatedResourceHandler returns a new ResourceHandler that authenticates at the endpoint via the provided token

func NewResourceHandler

func NewResourceHandler(baseURL string) *ResourceHandler

NewResourceHandler returns a new ResourceHandler

func (*ResourceHandler) CreateProjectResources

func (r *ResourceHandler) CreateProjectResources(project string, resources []*models.Resource) (string, error)

CreateProjectResources creates multiple project resources

func (*ResourceHandler) CreateServiceResources

func (r *ResourceHandler) CreateServiceResources(project string, stage string, service string, resources []*models.Resource) (string, error)

CreateServiceResources creates a service resource

func (*ResourceHandler) CreateStageResources

func (r *ResourceHandler) CreateStageResources(project string, stage string, resources []*models.Resource) (string, error)

CreateStageResources creates a stage resource

func (*ResourceHandler) DeleteProjectResource

func (r *ResourceHandler) DeleteProjectResource(project string, resourceURI string) error

DeleteProjectResource deletes a project resource

func (*ResourceHandler) DeleteServiceResource

func (r *ResourceHandler) DeleteServiceResource(project string, stage string, service string, resourceURI string) error

DeleteServiceResource deletes a service resource

func (*ResourceHandler) DeleteStageResource

func (r *ResourceHandler) DeleteStageResource(project string, stage string, resourceURI string) error

DeleteStageResource deletes a stage resource

func (*ResourceHandler) GetAllStageResources

func (r *ResourceHandler) GetAllStageResources(project string, stage string) ([]*models.Resource, error)

GetAllStageResources returns a list of all resources.

func (*ResourceHandler) GetProjectResource

func (r *ResourceHandler) GetProjectResource(project string, resourceURI string) (*models.Resource, error)

GetProjectResource retrieves a project resource from the configuration service

func (*ResourceHandler) GetServiceResource

func (r *ResourceHandler) GetServiceResource(project string, stage string, service string, resourceURI string) (*models.Resource, error)

GetServiceResource retrieves a service resource from the configuration service

func (*ResourceHandler) GetStageResource

func (r *ResourceHandler) GetStageResource(project string, stage string, resourceURI string) (*models.Resource, error)

GetStageResource retrieves a stage resource from the configuration service

func (*ResourceHandler) UpdateProjectResource

func (r *ResourceHandler) UpdateProjectResource(project string, resource *models.Resource) (string, error)

UpdateProjectResource updates a project resource

func (*ResourceHandler) UpdateProjectResources

func (r *ResourceHandler) UpdateProjectResources(project string, resources []*models.Resource) (string, error)

UpdateProjectResources updates multiple project resources

func (*ResourceHandler) UpdateServiceResource

func (r *ResourceHandler) UpdateServiceResource(project string, stage string, service string, resource *models.Resource) (string, error)

UpdateServiceResource updates a service resource

func (*ResourceHandler) UpdateServiceResources

func (r *ResourceHandler) UpdateServiceResources(project string, stage string, service string, resources []*models.Resource) (string, error)

UpdateServiceResources updates multiple service resources

func (*ResourceHandler) UpdateStageResource

func (r *ResourceHandler) UpdateStageResource(project string, stage string, resource *models.Resource) (string, error)

UpdateStageResource updates a stage resource

func (*ResourceHandler) UpdateStageResources

func (r *ResourceHandler) UpdateStageResources(project string, stage string, resources []*models.Resource) (string, error)

UpdateStageResources updates multiple stage resources

type ServiceHandler

type ServiceHandler struct {
	BaseURL    string
	AuthToken  string
	AuthHeader string
	HTTPClient *http.Client
	Scheme     string
}

ServiceHandler handles services

func NewAuthenticatedServiceHandler

func NewAuthenticatedServiceHandler(baseURL string, authToken string, authHeader string, httpClient *http.Client, scheme string) *ServiceHandler

NewAuthenticatedServiceHandler returns a new ServiceHandler that authenticates at the endpoint via the provided token

func NewServiceHandler

func NewServiceHandler(baseURL string) *ServiceHandler

NewServiceHandler returns a new ServiceHandler

func (*ServiceHandler) CreateService

func (s *ServiceHandler) CreateService(project string, stage string, serviceName string) (*models.Error, error)

CreateService creates a new service

func (*ServiceHandler) GetAllServices

func (s *ServiceHandler) GetAllServices(project string, stage string) ([]*models.Service, error)

GetAllServices returns a list of all services.

type StageHandler

type StageHandler struct {
	BaseURL    string
	AuthToken  string
	AuthHeader string
	HTTPClient *http.Client
	Scheme     string
}

StageHandler handles stages

func NewAuthenticatedStageHandler

func NewAuthenticatedStageHandler(baseURL string, authToken string, authHeader string, httpClient *http.Client, scheme string) *StageHandler

NewAuthenticatedStageHandler returns a new StageHandler that authenticates at the endpoint via the provided token

func NewStageHandler

func NewStageHandler(baseURL string) *StageHandler

NewStageHandler returns a new StageHandler

func (*StageHandler) CreateStage

func (s *StageHandler) CreateStage(project string, stageName string) (*models.Error, error)

CreateStage creates a new stage with the provided name

func (*StageHandler) GetAllStages

func (s *StageHandler) GetAllStages(project string) ([]*models.Stage, error)

GetAllStages returns a list of all stages.

Jump to

Keyboard shortcuts

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