crossplane

package
v0.12.3 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: BSD-3-Clause Imports: 32 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// SynToolsBase is the base domain
	SynToolsBase = "service.syn.tools"
	AppcatBase   = "appcat.vshn.io"

	// DescriptionAnnotation of the instance
	DescriptionAnnotation = SynToolsBase + "/description"
	// MetadataAnnotation of the instance
	MetadataAnnotation = SynToolsBase + "/metadata"
	// DeletionTimestampAnnotation marks when an object got deleted
	DeletionTimestampAnnotation = SynToolsBase + "/deletionTimestamp"
	// TagsAnnotation of the instance
	TagsAnnotation = SynToolsBase + "/tags"
)
View Source
const (
	// ServiceNameLabel of the instance
	ServiceNameLabel = SynToolsBase + "/name"
	// ServiceIDLabel of the instance
	ServiceIDLabel = SynToolsBase + "/id"
	// PlanNameLabel of the instance
	PlanNameLabel = SynToolsBase + "/plan"
	// ClusterLabel name of the cluster this instance is deployed to
	ClusterLabel = SynToolsBase + "/cluster"
	// SLALabel SLA level for this instance
	SLALabel = SynToolsBase + "/sla"
	// InstanceIDLabel of the instance
	InstanceIDLabel = SynToolsBase + "/instance"
	// ParentIDLabel of the instance
	ParentIDLabel = SynToolsBase + "/parent"
	// BindableLabel of the instance
	BindableLabel = SynToolsBase + "/bindable"
	// UpdatableLabel of the instance
	UpdatableLabel = SynToolsBase + "/updatable"
	// DeletedLabel marks an object as deleted to clean up
	DeletedLabel = SynToolsBase + "/deleted"
	// PrincipalLabel stores the username of the entity (person or system) that created the respective resource
	PrincipalLabel = SynToolsBase + "/principal"

	//OwnerApiVersionLabel stores the apiVersion of the composite
	OwnerApiVersionLabel = AppcatBase + "/ownerapiversion"
	//OwnerGroupLabel stores the group of the composite
	OwnerGroupLabel = AppcatBase + "/ownergroup"
	//OwnerKindLabel stores the kind of the composite
	OwnerKindLabel = AppcatBase + "/ownerkind"
)
View Source
const (
	// SLAPremium represents the string for the premium SLA
	SLAPremium = "premium"
	// SLAStandard represents the string for the standard SLA
	SLAStandard = "standard"
	// SizeXSmall represents the string for the xsmall plan size
	SizeXSmall = "xsmall"
	// SizeSmall represents the string for the small plan size
	SizeSmall = "small"
	// SizeMedium represents the string for the medium plan size
	SizeMedium = "medium"
	// SizeLarge represents the string for the large plan size
	SizeLarge = "large"
	// SizeXLarge represents the string for the xlarge plan size
	SizeXLarge = "xlarge"
)
View Source
const SentinelPortKey = "sentinelPort"

SentinelPortKey is the key in the connection secret that contains the port to Redis Sentinel

Variables

View Source
var (
	// ErrInstanceNotReady is returned if credentials are fetched for an instance which is still provisioning.
	ErrInstanceNotReady = errors.New("instance not ready")
	// ErrBindingNotReady is returned if the binding is still being provisioned.
	ErrBindingNotReady = errors.New("binding not ready")
)

Functions

func Register

func Register(scheme *runtime.Scheme) error

Register configures the given runtime.Scheme with all required resources

Types

type Credentials

type Credentials map[string]interface{}

Credentials contain connection information for accessing a service.

type Crossplane

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

Crossplane client to access crossplane resources.

func New

func New(brokerConfig *config.Config, restConfig *rest.Config) (*Crossplane, error)

New instantiates a crossplane client.

func (Crossplane) CreateInstance

func (cp Crossplane) CreateInstance(rctx *reqcontext.ReqContext, id string, plan *Plan, params map[string]interface{}) error

CreateInstance sets a new composite with assigned plan and params up.

func (*Crossplane) DeleteInstance

func (cp *Crossplane) DeleteInstance(rctx *reqcontext.ReqContext, instanceName string, plan *Plan) error

DeleteInstance deletes a service instance

func (Crossplane) FindInstanceWithoutPlan

func (cp Crossplane) FindInstanceWithoutPlan(rctx *reqcontext.ReqContext, id string) (inst *Instance, p *Plan, ok bool, err error)

FindInstanceWithoutPlan is used for retrieving an instance when the plan is unknown. It needs to iterate through all plans and fetch the instance using the supplied GVK. There's probably an optimization to be done here, as this seems fairly shitty, but for now it works.

func (*Crossplane) GetConnectionDetails added in v0.2.0

func (cp *Crossplane) GetConnectionDetails(ctx context.Context, instance *composite.Unstructured) (*corev1.Secret, error)

GetConnectionDetails returns the connection details of an instance

func (Crossplane) Instance

func (cp Crossplane) Instance(rctx *reqcontext.ReqContext, id string, plan *Plan) (inst *Instance, ok bool, err error)

Instance retrieves an instance based on the given instanceID and plan. Besides the instanceID, the planName has to match. The `ok` parameter is *only* set to true if no error is returned and the instance already exists. Normal errors are returned as-is. FIXME(mw): is it correct to return `false, errInstanceNotFound` if PlanNameLabel does not match? And how should that be handled?

Ported from PoC code as-is, and errInstanceNotFound is handled as instance really not found, however as the ID exists, how
can we speak about having no instance with that name? It's a UUID after all.

func (Crossplane) Plan

func (cp Crossplane) Plan(rctx *reqcontext.ReqContext, planID string) (*Plan, error)

Plan retrieves a single plan as deployed using a Composition. The planID corresponds to the Compositions name.

func (Crossplane) Plans

func (cp Crossplane) Plans(rctx *reqcontext.ReqContext, serviceIDs []string) ([]*Plan, error)

Plans retrieves all plans per passed service. Plans are deployed Compositions with the ServiceIDLabel assigned. The plans are ordered by name.

func (Crossplane) ServiceXRDs

func (cp Crossplane) ServiceXRDs(rctx *reqcontext.ReqContext) ([]*ServiceXRD, error)

ServiceXRDs retrieves all defined services (defined by XRDs with the ServiceIDLabel) on the cluster.

func (*Crossplane) UpdateInstance

func (cp *Crossplane) UpdateInstance(rctx *reqcontext.ReqContext, instance *Instance, plan *Plan) error

UpdateInstance updates `instance` on k8s.

type Endpoint

type Endpoint struct {
	Host     string
	Port     int32
	Protocol string
}

Endpoint describes available service endpoints.

type Instance

type Instance struct {
	Composite *composite.Unstructured
	Labels    *Labels
}

Instance is a wrapper around a specific instance (a composite).

func (Instance) GetClusterName added in v0.9.0

func (instance Instance) GetClusterName() string

GetClusterName returns the cluster name of the instance

func (Instance) ID

func (i Instance) ID() string

ID returns the instance name.

func (Instance) Parameters

func (i Instance) Parameters() map[string]interface{}

Parameters returns the specified parameters if available.

func (Instance) ParentReference added in v0.2.0

func (i Instance) ParentReference() (string, error)

ParentReference returns the parent reference

func (Instance) Ready

func (i Instance) Ready() bool

Ready returns if the instance contains a ready = true status.

type Labels

type Labels struct {
	ServiceName     ServiceName
	ServiceID       string
	PlanName        string
	PlanSize        string
	InstanceID      string
	ParentID        string
	SLA             string
	Bindable        bool
	Updatable       bool
	Deleted         bool
	OwnerApiVersion string
	OwnerGroup      string
	OwnerKind       string
}

Labels provides uniform access to parsed labels.

type MariadbDatabaseServiceBinder

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

MariadbDatabaseServiceBinder defines a specific Mariadb service with enough data to retrieve connection credentials.

func NewMariadbDatabaseServiceBinder

func NewMariadbDatabaseServiceBinder(c *Crossplane, instance *Instance, logger lager.Logger) *MariadbDatabaseServiceBinder

NewMariadbDatabaseServiceBinder instantiates a Mariadb service instance based on the given CompositeMariadbInstance.

func (MariadbDatabaseServiceBinder) Bind

Bind creates a MariaDB binding composite.

func (MariadbDatabaseServiceBinder) Deprovisionable

func (msb MariadbDatabaseServiceBinder) Deprovisionable(_ context.Context) error

Deprovisionable always returns nil for MariadbDatabase instances.

func (MariadbDatabaseServiceBinder) GetBinding

func (msb MariadbDatabaseServiceBinder) GetBinding(ctx context.Context, bindingID string) (Credentials, error)

GetBinding returns credentials for MariaDB

func (MariadbDatabaseServiceBinder) Unbind

func (msb MariadbDatabaseServiceBinder) Unbind(ctx context.Context, bindingID string) error

Unbind deletes the created User and Grant.

func (MariadbDatabaseServiceBinder) ValidateProvisionParams

func (msb MariadbDatabaseServiceBinder) ValidateProvisionParams(ctx context.Context, params json.RawMessage) (map[string]interface{}, error)

ValidateProvisionParams ensures the passed parent reference is an existing mariadb instance.

type MariadbServiceBinder

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

MariadbServiceBinder defines a specific Mariadb service with enough data to retrieve connection credentials.

func NewMariadbServiceBinder

func NewMariadbServiceBinder(c *Crossplane, instance *Instance, logger lager.Logger) *MariadbServiceBinder

NewMariadbServiceBinder instantiates a Mariadb service instance based on the given CompositeMariadbInstance.

func (MariadbServiceBinder) Bind

Bind on a MariaDB instance is not supported - only a database referencing an instance can be bound.

func (MariadbServiceBinder) Deprovisionable

func (msb MariadbServiceBinder) Deprovisionable(ctx context.Context) error

Deprovisionable checks if no DBs exist for this instance anymore.

func (MariadbServiceBinder) GetBinding

func (msb MariadbServiceBinder) GetBinding(_ context.Context, _ string) (Credentials, error)

GetBinding is not implemented.

func (MariadbServiceBinder) Unbind

func (msb MariadbServiceBinder) Unbind(_ context.Context, _ string) error

Unbind on a MariaDB instance is not supported - only a database referencing an instance can be bound.

type Plan

type Plan struct {
	Composition *xv1.Composition
	Labels      *Labels
	Metadata    string
	Tags        string
	Description string
}

Plan is a wrapper around a Composition representing a service plan.

func (Plan) GVK

func (p Plan) GVK() (schema.GroupVersionKind, error)

GVK returns the group, version, kind type for the composite type ref.

type PlanUpdateChecker added in v0.6.0

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

PlanUpdateChecker checks whether an update is valid

func ParsePlanUpdateRules added in v0.6.0

func ParsePlanUpdateRules(sizeRules, slaRules string) (PlanUpdateChecker, error)

ParsePlanUpdateRules parses the rules given as strings and return a PlanUpgradeChecker that implements them. It takes two rule strings. One that defines how plan SLAs can be changed and one that defines how plan sizes are allowed to be changed. Both are a `|` separated list of white-listed changes in the form of `$OLD_PLAN>$NEW_PLAN`.

The example sizeRules `small>medium|medium>large`, will allow updating plans from small to medium and from medium to large and reject all other updates. The slaRules `standard>premium|premium>standard`, will allow switching between standard and premium SLA.

func (PlanUpdateChecker) AllowUpdate added in v0.6.0

func (pc PlanUpdateChecker) AllowUpdate(a, b Plan) bool

AllowUpdate checks whether a plan upgrade from a to b is valid

type ProvisionValidater

type ProvisionValidater interface {
	// ValidateProvisionParams can be used to check the params for validity. If valid, it should return all needed parameters
	// for the composition.
	ValidateProvisionParams(ctx context.Context, params json.RawMessage) (map[string]interface{}, error)
}

ProvisionValidater enables service implementations to check required additional params.

type RedisServiceBinder

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

RedisServiceBinder defines a specific redis service with enough data to retrieve connection credentials.

func NewRedisServiceBinder

func NewRedisServiceBinder(c *Crossplane, instance *Instance, logger lager.Logger) *RedisServiceBinder

NewRedisServiceBinder instantiates a redis service instance based on the given CompositeRedisInstance.

func (RedisServiceBinder) Bind

func (rsb RedisServiceBinder) Bind(ctx context.Context, bindingID string) (Credentials, error)

Bind retrieves the necessary external IP, password and ports.

func (RedisServiceBinder) Deprovisionable

func (rsb RedisServiceBinder) Deprovisionable(ctx context.Context) error

Deprovisionable returns always nil for redis instances.

func (RedisServiceBinder) GetBinding

func (rsb RedisServiceBinder) GetBinding(ctx context.Context, bindingID string) (Credentials, error)

GetBinding always returns the same credentials for Redis

func (RedisServiceBinder) Unbind

func (rsb RedisServiceBinder) Unbind(_ context.Context, _ string) error

Unbind does nothing for redis bindings.

type ServiceBinder

type ServiceBinder interface {
	Bind(ctx context.Context, bindingID string) (Credentials, error)
	Unbind(ctx context.Context, bindingID string) error
	Deprovisionable(ctx context.Context) error
	GetBinding(ctx context.Context, bindingID string) (Credentials, error)
}

ServiceBinder is an interface for service specific implementation for binding, retrieving credentials, etc.

func ServiceBinderFactory

func ServiceBinderFactory(c *Crossplane, serviceName ServiceName, instance *Instance, logger lager.Logger) (ServiceBinder, error)

ServiceBinderFactory reads the composite's labels service name and instantiates an appropriate ServiceBinder. FIXME(mw): determine fate of this. We might not need differentiation anymore, once provider-helm is upgraded.

type ServiceName

type ServiceName string

ServiceName contains all defined service names to handle specific implementations.

var (
	RedisService           ServiceName = "redis-k8s"
	MariaDBService         ServiceName = "mariadb-k8s"
	MariaDBDatabaseService ServiceName = "mariadb-k8s-database"
)

Defined service names

func (ServiceName) IsValid

func (s ServiceName) IsValid() bool

IsValid returns true if the ServiceName is one of the defined ones.

type ServiceXRD

type ServiceXRD struct {
	XRD         xv1.CompositeResourceDefinition
	Labels      *Labels
	Metadata    string
	Tags        string
	Description string
}

ServiceXRD is a wrapper around a CompositeResourceDefinition (XRD) which represents a service.

Jump to

Keyboard shortcuts

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