common

package
v0.0.0-...-1af24f0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2019 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// ErrorResponse for http request
	ErrorResponse = "Error"

	// StandardTimeFormat is time format reference for golang
	StandardTimeFormat = "2006-01-02 15:04:05"

	// StandardYYYYMMDDFormat formats date in yyyy-mm-dd format
	StandardYYYYMMDDFormat = "2006-01-02"

	// DefaultControllerNamespace is the default namespace where the sensor and gateways controllers are installed
	DefaultControllerNamespace = "argo-events"
)
View Source
const (
	// EnvVarKubeConfig is the path to the Kubernetes configuration
	EnvVarKubeConfig = "KUBE_CONFIG"

	// EnvVarDebugLog is the env var to turn on the debug mode for logging
	EnvVarDebugLog = "DEBUG_LOG"
)

ENV VARS

View Source
const (
	// LabelOperation is a label for an operation in framework
	LabelOperation = "operation"

	// LabelEventSource is label for event name
	LabelEventSource = "event-source"
)

LABELS

View Source
const (
	// env variables constants
	//LabelKeySensorControllerInstanceID is the label which allows to separate application among multiple running sensor controllers.
	LabelKeySensorControllerInstanceID = sensor.FullName + "/sensor-controller-instanceid"

	// LabelSensorKeyPhase is a label applied to sensors to indicate the current phase of the sensor (for filtering purposes)
	LabelSensorKeyPhase = sensor.FullName + "/phase"

	// LabelSensorKeyComplete is the label to mark sensors as complete
	LabelSensorKeyComplete = sensor.FullName + "/complete"

	// EnvVarSensorControllerConfigMap is the name of the configmap to use for the sensor-controller
	EnvVarSensorControllerConfigMap = "SENSOR_CONFIG_MAP"

	// labels constants
	// LabelSensorControllerName is the default deployment name of the sensor-controller
	LabelSensorControllerName = "sensor-controller"

	LabelArgoEventsSensorVersion = "argo-events-sensor-version"

	// SensorControllerConfigMapKey is the key in the configmap to retrieve sensor configuration from.
	// Content encoding is expected to be YAML.
	SensorControllerConfigMapKey = "config"

	// miscellaneous constants
	// AnnotationSensorResourceSpecHashName is the annotation of a sensor resource spec hash
	AnnotationSensorResourceSpecHashName = sensor.FullName + "/resource-spec-hash"
)

SENSOR CONTROLLER CONSTANTS

View Source
const (
	// SensorServiceEndpoint is the endpoint to dispatch the event to
	SensorServiceEndpoint = "/"

	// SensorName refers env var for name of sensor
	SensorName = "SENSOR_NAME"

	// SensorNamespace is used to get namespace where sensors are deployed
	SensorNamespace = "SENSOR_NAMESPACE"

	// LabelSensorName is label for sensor name
	LabelSensorName = "sensor-name"

	// EnvVarSensorControllerInstanceID is used to get sensor controller instance id
	EnvVarSensorControllerInstanceID = "SENSOR_CONTROLLER_INSTANCE_ID"
)

SENSOR CONSTANTS

View Source
const (
	// env variables
	// EnvVarGatewayControllerConfigMap contains name of the configmap to retrieve gateway-controller configuration from
	EnvVarGatewayControllerConfigMap = "GATEWAY_CONTROLLER_CONFIG_MAP"

	// EnvVarGatewayControllerInstanceID is used to get gateway controller instance id
	EnvVarGatewayControllerInstanceID = "GATEWAY_CONTROLLER_INSTANCE_ID"

	// EnvVarGatewayControllerName is used to get name of gateway controller
	EnvVarGatewayControllerName = "GATEWAY_CONTROLLER_NAME"

	// EnvVarGatewayName refers env var for name of gateway
	EnvVarGatewayName = "GATEWAY_NAME"

	// EnvVarGatewayNamespace is namespace where gateway controller is deployed
	EnvVarGatewayNamespace = "GATEWAY_NAMESPACE"

	// labels
	// LabelGatewayControllerName is the default deployment name of the gateway-controller-controller
	LabelGatewayControllerName = "gateway-controller"

	//LabelKeyGatewayControllerInstanceID is the label which allows to separate application among multiple running gateway-controller controllers.
	LabelKeyGatewayControllerInstanceID = gateway.FullName + "/gateway-controller-instanceid"

	// LabelGatewayKeyPhase is a label applied to gateways to indicate the current phase of the gateway-controller (for filtering purposes)
	LabelGatewayKeyPhase = gateway.FullName + "/phase"

	// LabelGatewayName is the label for gateway name
	LabelGatewayName = "gateway-name"

	// LabelArgoEventsGatewayVersion is the label for the gateway version
	LabelArgoEventsGatewayVersion = "argo-events-gateway-version"

	// AnnotationGatewayResourceSpecHashName is the annotation of a gateway resource spec hash
	AnnotationGatewayResourceSpecHashName = gateway.FullName + "/resource-spec-hash"

	// GatewayControllerConfigMapKey is the key in the configmap to retrieve gateway-controller configuration from.
	// Content encoding is expected to be YAML.
	GatewayControllerConfigMapKey = "config"
)

GATEWAY CONTROLLER CONSTANTS

View Source
const (
	// LabelGatewayEventSourceName is the label for a event source in gateway
	LabelGatewayEventSourceName = "event-source-name"

	// LabelGatewayEventSourceID is the label for gateway configuration ID
	LabelGatewayEventSourceID = "event-source-id"

	// LabelArgoEventsEventSourceVersion is the label for event source version
	LabelArgoEventsEventSourceVersion = "argo-events-event-source-version"

	// EnvVarGatewayEventSourceConfigMap is used to get map containing event sources to run in a gateway
	EnvVarGatewayEventSourceConfigMap = "GATEWAY_EVENT_SOURCE_CONFIG_MAP"

	EnvVarGatewayServerPort = "GATEWAY_SERVER_PORT"

	// Server Connection Timeout, 10 seconds
	ServerConnTimeout = 10
)

GATEWAY CONSTANTS

View Source
const (
	LabelNamespace   = "namespace"
	LabelPhase       = "phase"
	LabelInstanceID  = "instance-id"
	LabelPodName     = "pod-name"
	LabelServiceName = "svc-name"
	LabelEndpoint    = "endpoint"
	LabelPort        = "port"
	LabelURL         = "url"
	LabelNodeName    = "node-name"
	LabelNodeType    = "node-type"
	LabelHTTPMethod  = "http-method"
	LabelClientID    = "client-id"
	LabelVersion     = "version"
	LabelTime        = "time"
	LabelTriggerName = "trigger-name"
)

Logger constants

View Source
const (
	// CloudEventsVersion is the version of the CloudEvents spec targeted+
	// by this library.
	CloudEventsVersion = "0.1"
)

CloudEvents constants

View Source
const (
	// LabelEventType is label for k8 event type
	LabelEventType = "event-type"
)

Variables

View Source
var DefaultRetry = wait.Backoff{
	Steps:    5,
	Duration: 10 * time.Millisecond,
	Factor:   1.0,
	Jitter:   0.1,
}

DefaultRetry is a default retry backoff settings when retrying API calls

Functions

func CheckEventSourceVersion

func CheckEventSourceVersion(cm *corev1.ConfigMap) error

func DefaultConfigMapName

func DefaultConfigMapName(controllerName string) string

DefaultConfigMapName returns a formulated name for a configmap name based on the sensor-controller deployment name

func DefaultEventSourceName

func DefaultEventSourceName(gatewayName string, configurationName string) string

DefaultEventSourceName returns a formulated name for a gateway configuration

func DefaultNatsQueueName

func DefaultNatsQueueName(subject string) string

DefaultNatsQueueName returns a queue name for nats subject

func DefaultServiceName

func DefaultServiceName(serviceName string) string

DefaultServiceName returns a formulated name for a service

func GenerateK8sEvent

func GenerateK8sEvent(clientset kubernetes.Interface, reason string, eventType K8sEventType, action string, name, namespace, instanceId, kind string, labels map[string]string) error

GenerateK8sEvent generates a kubernetes event

func GetClientConfig

func GetClientConfig(kubeconfig string) (*rest.Config, error)

GetClientConfig return rest config, if path not specified, assume in cluster config

func GetObjectHash

func GetObjectHash(obj metav1.Object) (string, error)

GetObjectHash returns hash of a given object

func Hasher

func Hasher(value string) string

Hasher hashes a string

func IsRetryableKubeAPIError

func IsRetryableKubeAPIError(err error) bool

IsRetryableKubeAPIError returns if the error is a retryable kubernetes error

func NewArgoEventsLogger

func NewArgoEventsLogger() *logrus.Logger

NewArgoEventsLogger returns a new ArgoEventsLogger

func ParseExclusionDates

func ParseExclusionDates(vals []string) ([]time.Time, error)

ParseExclusionDates parses the exclusion dates from the vals string according to RFC 5545

func SendErrorResponse

func SendErrorResponse(writer http.ResponseWriter, response string)

SendErrorResponse sends http error response

func SendInternalErrorResponse

func SendInternalErrorResponse(writer http.ResponseWriter, response string)

SendInternalErrorResponse sends http internal error response

func SendSuccessResponse

func SendSuccessResponse(writer http.ResponseWriter, response string)

SendSuccessResponse sends http success response

func ServerResourceForGroupVersionKind

func ServerResourceForGroupVersionKind(disco discovery.DiscoveryInterface, gvk schema.GroupVersionKind) (*metav1.APIResource, error)

ServerResourceForGroupVersionKind finds the API resources that fit the GroupVersionKind schema

func ServiceDNSName

func ServiceDNSName(serviceName, namespace string) string

ServiceDNSName returns a formulated dns name for a service

Types

type Backoff

type Backoff struct {
	Duration time.Duration `json:"duration"` // the base duration
	Factor   float64       `json:"factor"`   // Duration is multiplied by factor each iteration
	Jitter   float64       `json:"jitter"`   // The amount of jitter applied each iteration
	Steps    int           `json:"steps"`    // Exit with error after this many steps
}

Backoff defines an operational backoff

type K8sEventType

type K8sEventType string

K8sEventType is the type of event generated to indicate change in state of resource

var (
	EscalationEventType       K8sEventType = "Escalation"
	StateChangeEventType      K8sEventType = "StateChange"
	OperationFailureEventType K8sEventType = "OperationFailed"
	OperationSuccessEventType K8sEventType = "OperationSuccessful"
)

Possible values for K8sEventType

Jump to

Keyboard shortcuts

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