broker

package
v0.0.0-...-acc184e Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorAlreadyProvisioned - Error for when an service instance has already been provisioned
	ErrorAlreadyProvisioned = errors.New("already provisioned")
	// ErrorDuplicate - Error for when a duplicate service instance already exists
	ErrorDuplicate = errors.New("duplicate instance")
	// ErrorNotFound  - Error for when a service instance is not found. (either etcd or kubernetes)
	ErrorNotFound = errors.New("not found")
	// ErrorBindingExists - Error for when deprovision is called on a service
	// instance with active bindings, or bind requested for already-existing
	// binding
	ErrorBindingExists = errors.New("binding exists")
	// ErrorProvisionInProgress - Error for when provision is called on a service instance that has a provision job in progress
	ErrorProvisionInProgress = errors.New("provision in progress")
	// ErrorDeprovisionInProgress - Error for when deprovision is called on a service instance that has a deprovision job in progress
	ErrorDeprovisionInProgress = errors.New("deprovision in progress")
	// ErrorUpdateInProgress - Error for when update is called on a service instance that has an update job in progress
	ErrorUpdateInProgress = errors.New("update in progress")
	// ErrorPlanNotFound - Error for when plan for update not found
	ErrorPlanNotFound = errors.New("plan not found")
	// ErrorParameterNotUpdatable - Error for when parameter in update request is not updatable
	ErrorParameterNotUpdatable = errors.New("parameter not updatable")
	// ErrorParameterNotFound - Error for when a parameter for update is not found
	ErrorParameterNotFound = errors.New("parameter not found")
	// ErrorParameterUnknownEnum - Error for when an unknown enum param has been requested
	ErrorParameterUnknownEnum = errors.New("unknown enum parameter value requested")
	// ErrorPlanUpdateNotPossible - Error when a Plan Update request cannot be satisfied
	ErrorPlanUpdateNotPossible = errors.New("plan update not possible")
	// ErrorUnbindingInProgress - Error when unbind is called that has an unbinding job in progress
	ErrorUnbindingInProgress = errors.New("unbinding in progress")
)

Functions

func IsValidWorkTopic

func IsValidWorkTopic(topic WorkTopic) bool

IsValidWorkTopic - Check if WorkTopic is part of acceptable set

Types

type AnsibleBroker

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

AnsibleBroker - Broker using ansible and images to interact with oc/kubernetes/etcd

func NewAnsibleBroker

func NewAnsibleBroker(dao dao.Dao,
	registry []registries.Registry,
	engine WorkEngine,
	brokerConfig *config.Config,
	namespace string,
	workFactory WorkFactory) (*AnsibleBroker, error)

NewAnsibleBroker - Creates a new ansible broker

func (AnsibleBroker) AddSpec

func (a AnsibleBroker) AddSpec(spec bundle.Spec) (*CatalogResponse, error)

AddSpec - adding the spec to the catalog for local development

func (AnsibleBroker) Bind

func (a AnsibleBroker) Bind(instance bundle.ServiceInstance, bindingUUID uuid.UUID, req *BindRequest, async bool, userInfo UserInfo,
) (*BindResponse, bool, error)

Bind - will create a binding between a service. Parameter "async" declares whether the caller is willing to have the operation run asynchronously. The returned bool will be true if the operation actually ran asynchronously.

func (AnsibleBroker) Bootstrap

func (a AnsibleBroker) Bootstrap() (*BootstrapResponse, error)

Bootstrap - Loads all known specs from a registry into local storage for reference Potentially a large download; on the order of 10s of thousands TODO: How do we handle a large amount of data on this side as well? Pagination?

func (AnsibleBroker) Catalog

func (a AnsibleBroker) Catalog() (*CatalogResponse, error)

Catalog - returns the catalog of services defined

func (AnsibleBroker) Deprovision

func (a AnsibleBroker) Deprovision(
	instance bundle.ServiceInstance, planID string, skipApbExecution bool, async bool, userInfo UserInfo,
) (*DeprovisionResponse, error)

Deprovision - will deprovision a service.

func (AnsibleBroker) GetBind

func (a AnsibleBroker) GetBind(instance bundle.ServiceInstance, bindingUUID uuid.UUID) (*BindResponse, error)

GetBind - will return the binding between a service created via an async binding event.

func (AnsibleBroker) GetBindInstance

func (a AnsibleBroker) GetBindInstance(bindUUID uuid.UUID) (bundle.BindInstance, error)

GetBindInstance - retrieve the bind instance for a bindUUID

func (AnsibleBroker) GetServiceInstance

func (a AnsibleBroker) GetServiceInstance(instanceUUID uuid.UUID) (bundle.ServiceInstance, error)

GetServiceInstance - retrieve the service instance for a instanceID.

func (AnsibleBroker) LastOperation

func (a AnsibleBroker) LastOperation(instanceUUID uuid.UUID, req *LastOperationRequest,
) (*LastOperationResponse, error)

LastOperation - gets the last operation and status

func (AnsibleBroker) Provision

func (a AnsibleBroker) Provision(instanceUUID uuid.UUID, req *ProvisionRequest, async bool, userInfo UserInfo,
) (*ProvisionResponse, error)

Provision - will provision a service

func (AnsibleBroker) Recover

func (a AnsibleBroker) Recover() (string, error)

Recover - Will recover the broker.

func (AnsibleBroker) RemoveSpec

func (a AnsibleBroker) RemoveSpec(specID string) error

RemoveSpec - remove the spec specified from the catalog/etcd

func (AnsibleBroker) RemoveSpecs

func (a AnsibleBroker) RemoveSpecs() error

RemoveSpecs - remove all the specs from the catalog/etcd

func (AnsibleBroker) Unbind

func (a AnsibleBroker) Unbind(
	instance bundle.ServiceInstance, bindInstance bundle.BindInstance, planID string, skipApbExecution bool, async bool, userInfo UserInfo,
) (*UnbindResponse, bool, error)

Unbind - unbind a service's previous binding. Parameter "async" declares whether the caller is willing to have the operation run asynchronously. The returned bool will be true if the operation actually ran asynchronously.

func (AnsibleBroker) Update

func (a AnsibleBroker) Update(instanceUUID uuid.UUID, req *UpdateRequest, async bool, userInfo UserInfo,
) (*UpdateResponse, error)

Update - will update a service

type BindRequest

type BindRequest struct {
	ServiceID string `json:"service_id"`
	PlanID    string `json:"plan_id"`
	// Deprecated: AppID deprecated in favor of BindResource.AppID
	AppID uuid.UUID `json:"app_guid,omitempty"`

	BindResource struct {
		AppID uuid.UUID `json:"app_guid,omitempty"`
		Route string    `json:"route,omitempty"`
	} `json:"bind_resource,omitempty"`
	Parameters bundle.Parameters `json:"parameters,omitempty"`
}

BindRequest - Request for a bind Defined here https://github.com/openservicebrokerapi/servicebroker/blob/v2.12/spec.md#request-4

type BindResponse

type BindResponse struct {
	Credentials     map[string]interface{} `json:"credentials,omitempty"`
	SyslogDrainURL  string                 `json:"syslog_drain_url,omitempty"`
	RouteServiceURL string                 `json:"route_service_url,omitempty"`
	VolumeMounts    []interface{}          `json:"volume_mounts,omitempty"`
	Operation       string                 `json:"operation,omitempty"`
}

BindResponse - Response for a bind Defined here https://github.com/openservicebrokerapi/servicebroker/blob/v2.12/spec.md#response-4

func NewBindResponse

func NewBindResponse(pCreds, bCreds *bundle.ExtractedCredentials) (*BindResponse, error)

NewBindResponse - creates a BindResponse based on available credentials.

type BootstrapResponse

type BootstrapResponse struct {
	SpecCount  int `json:"spec_count"`
	ImageCount int `json:"image_count"`
}

BootstrapResponse - The response for a bootstrap request TODO: What belongs on this thing?

type Broker

Broker - A broker is used to to complete all the tasks that a broker must be able to do.

type CatalogResponse

type CatalogResponse struct {
	Services []Service `json:"services"`
}

CatalogResponse - Response for the catalog call. Defined here https://github.com/openservicebrokerapi/servicebroker/blob/v2.12/spec.md#response

type Config

type Config struct {
	DevBroker           bool   `yaml:"dev_broker"`
	LaunchApbOnBind     bool   `yaml:"launch_apb_on_bind"`
	BootstrapOnStartup  bool   `yaml:"bootstrap_on_startup"`
	Recovery            bool   `yaml:"recovery"`
	OutputRequest       bool   `yaml:"output_request"`
	SSLCertKey          string `yaml:"ssl_cert_key"`
	SSLCert             string `yaml:"ssl_cert"`
	RefreshInterval     string `yaml:"refresh_interval"`
	AutoEscalate        bool   `yaml:"auto_escalate"`
	DashboardRedirector string `yaml:"dashboard_redirector"`
}

Config - Configuration for the broker.

type DashboardClient

type DashboardClient struct {
	ID          string `json:"id"`
	Secret      string `json:"secret"`
	RedirectURI string `json:"redirect_uri"`
}

DashboardClient - Dashboard Client to be returned based on https://github.com/openservicebrokerapi/servicebroker/blob/master/spec.md#dashboard-client-object

type DeprovisionResponse

type DeprovisionResponse struct {
	Operation string `json:"operation,omitempty"`
}

DeprovisionResponse - Response for a deprovision Defined here https://github.com/openservicebrokerapi/servicebroker/blob/v2.12/spec.md#response-6

type DevBroker

type DevBroker interface {
	AddSpec(spec bundle.Spec) (*CatalogResponse, error)
	RemoveSpec(specID string) error
	RemoveSpecs() error
}

DevBroker - Interface for the development broker.

type ErrorResponse

type ErrorResponse struct {
	Description string `json:"description"`
}

ErrorResponse - Error response for all broker errors Defined here https://github.com/openservicebrokerapi/servicebroker/blob/v2.12/spec.md#broker-errors

type JobMsg

type JobMsg struct {
	InstanceUUID         string                      `json:"instance_uuid"`
	JobToken             string                      `json:"job_token"`
	SpecID               string                      `json:"spec_id"`
	PodName              string                      `json:"podname"`
	Msg                  string                      `json:"msg"`
	State                bundle.JobState             `json:"state"`
	ExtractedCredentials bundle.ExtractedCredentials `json:"extracted_credentials"`
	DashboardURL         string                      `json:"dashboard_url"`
	BindingUUID          string                      `json:"binding_uuid"`
	Error                string                      `json:"error"`
}

JobMsg - Message to be returned from the various jobs

func (JobMsg) Render

func (jm JobMsg) Render() string

Render - Display the job message.

type JobStateSubscriber

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

JobStateSubscriber is responsible for handling and persisting JobState changes

func NewJobStateSubscriber

func NewJobStateSubscriber(dao SubscriberDAO) *JobStateSubscriber

NewJobStateSubscriber returns a newly initialized JobStateSubscriber

func (*JobStateSubscriber) ID

func (jss *JobStateSubscriber) ID() string

ID is used as an identifier for the type of subscriber

func (*JobStateSubscriber) Notify

func (jss *JobStateSubscriber) Notify(msg JobMsg)

Notify external API to notify this subscriber of a change in the Job

type LastOperationRequest

type LastOperationRequest struct {
	ServiceID string `json:"service_id"`
	PlanID    string `json:"plan_id"`
	Operation string `json:"operation"`
}

LastOperationRequest - Request to obtain state information about an action that was taken Defined in more detail here https://github.com/openservicebrokerapi/servicebroker/blob/v2.12/spec.md#polling-last-operation

type LastOperationResponse

type LastOperationResponse struct {
	State       LastOperationState `json:"state"`
	Description string             `json:"description,omitempty"`
}

LastOperationResponse - Response for the last operation request. Defined here https://github.com/openservicebrokerapi/servicebroker/blob/v2.12/spec.md#response-1

type LastOperationState

type LastOperationState string

LastOperationState - State that the Last Operation is allowed to be. https://github.com/openservicebrokerapi/servicebroker/blob/v2.12/spec.md#body

const (
	// LastOperationStateInProgress - In Progress state for last operation.
	LastOperationStateInProgress LastOperationState = "in progress"
	// LastOperationStateSucceeded - Succeeded state for the last operation.
	LastOperationStateSucceeded LastOperationState = "succeeded"
	// LastOperationStateFailed - Failed state for the last operation.
	LastOperationStateFailed LastOperationState = "failed"
)

func StateToLastOperation

func StateToLastOperation(state bundle.State) LastOperationState

StateToLastOperation converts apb State objects into LastOperationStates.

type Plan

type Plan struct {
	ID          string                 `json:"id"`
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
	Free        bool                   `json:"free,omitempty"`
	Bindable    bool                   `json:"bindable,omitempty"`
	Schemas     Schema                 `json:"schemas,omitempty"`
	UpdatesTo   []string               `json:"updates_to,omitempty"`
}

Plan - Plan to be returned based on https://github.com/openservicebrokerapi/servicebroker/blob/master/spec.md#plan-object

type ProvisionRequest

type ProvisionRequest struct {
	OrganizationID    uuid.UUID         `json:"organization_guid"`
	PlanID            string            `json:"plan_id"`
	ServiceID         string            `json:"service_id"`
	SpaceID           uuid.UUID         `json:"space_guid"`
	Context           bundle.Context    `json:"context"`
	Parameters        bundle.Parameters `json:"parameters,omitempty"`
	AcceptsIncomplete bool              `json:"accepts_incomplete,omitempty"`
}

ProvisionRequest - Request for provision Defined here https://github.com/openservicebrokerapi/servicebroker/blob/v2.12/spec.md#request-2

type ProvisionResponse

type ProvisionResponse struct {
	DashboardURL string `json:"dashboard_url,omitempty"`
	Operation    string `json:"operation,omitempty"`
}

ProvisionResponse - Response for provision Defined here https://github.com/openservicebrokerapi/servicebroker/blob/v2.12/spec.md#response-2

type Schema

type Schema struct {
	ServiceInstance ServiceInstance `json:"service_instance"`
	ServiceBinding  ServiceBinding  `json:"service_binding"`
}

Schema - Schema to be returned based on 2.13 of the open service broker api. https://github.com/avade/servicebroker/blob/cda8c57b6a4bb7eaee84be20bb52dc155269758a/spec.md

type Service

type Service struct {
	Name                 string                 `json:"name"`
	ID                   string                 `json:"id"`
	Description          string                 `json:"description"`
	Tags                 []string               `json:"tags,omitempty"`
	Requires             []string               `json:"requires,omitempty"`
	Bindable             bool                   `json:"bindable"`
	Metadata             map[string]interface{} `json:"metadata,omitempty"`
	DashboardClient      *DashboardClient       `json:"dashboard_client,omitempty"`
	InstancesRetrievable bool                   `json:"instances_retrievable"`
	BindingsRetrievable  bool                   `json:"bindings_retrievable"`
	PlanUpdatable        bool                   `json:"plan_updateable,omitempty"`
	Plans                []Plan                 `json:"plans"`
}

Service - Service object to be returned. based on https://github.com/openservicebrokerapi/servicebroker/blob/master/spec.md#service-objects

func SpecToService

func SpecToService(spec *bundle.Spec) (Service, error)

SpecToService converts an apb Spec into a Service usable by the service catalog.

type ServiceBinding

type ServiceBinding struct {
	Create map[string]*schema.Schema `json:"create"`
}

ServiceBinding - Schema definitions for creating a service binding.

type ServiceInstance

type ServiceInstance struct {
	Create map[string]*schema.Schema `json:"create"`
	Update map[string]*schema.Schema `json:"update"`
}

ServiceInstance - Schema definitions for creating and updating a service instance. Toyed with the idea of making an InputParameters that was a *schema.Schema based on 2.13 of the open service broker api. https://github.com/avade/servicebroker/blob/cda8c57b6a4bb7eaee84be20bb52dc155269758a/spec.md

type ServiceInstanceResponse

type ServiceInstanceResponse struct {
	ServiceID    string            `json:"service_id"`
	PlanID       string            `json:"plan_id"`
	DashboardURL string            `json:"dashboard_url,omitempty"`
	Parameters   bundle.Parameters `json:"parameters,omitempty"`
}

ServiceInstanceResponse - The response for a get service instance request

type SubscriberDAO

type SubscriberDAO interface {
	SetState(id string, state bundle.JobState) (string, error)
	GetServiceInstance(id string) (*bundle.ServiceInstance, error)
	DeleteServiceInstance(id string) error
	GetBindInstance(id string) (*bundle.BindInstance, error)
	DeleteBinding(bundle.BindInstance, bundle.ServiceInstance) error
	SetServiceInstance(id string, serviceInstance *bundle.ServiceInstance) error
}

SubscriberDAO defines the interface subscribers use when persisting state

type UnbindResponse

type UnbindResponse struct {
	Operation string `json:"operation,omitempty"`
}

UnbindResponse - Response for unbinding Defined here https://github.com/openservicebrokerapi/servicebroker/blob/v2.12/spec.md#response-5

type UpdateRequest

type UpdateRequest struct {
	ServiceID      string            `json:"service_id"`
	PlanID         string            `json:"plan_id,omitempty"`
	Parameters     map[string]string `json:"parameters,omitempty"`
	PreviousValues struct {
		PlanID         string    `json:"plan_id,omitempty"`
		ServiceID      string    `json:"service_id,omitempty"`
		OrganizationID uuid.UUID `json:"organization_id,omitempty"`
		SpaceID        uuid.UUID `json:"space_id,omitempty"`
	} `json:"previous_values,omitempty"`
	Context           bundle.Context `json:"context"`
	AcceptsIncomplete bool           `json:"accepts_incomplete,omitempty"`
}

UpdateRequest - Request for an update for a service instance. Defined here https://github.com/openservicebrokerapi/servicebroker/blob/v2.12/spec.md#request-3

type UpdateResponse

type UpdateResponse struct {
	Operation string `json:"operation,omitempty"`
}

UpdateResponse - Response for an update for a service instance. Defined here https://github.com/openservicebrokerapi/servicebroker/blob/v2.12/spec.md#response-3

type UserInfo

type UserInfo struct {
	Username string                       `json:"username"`
	UID      string                       `json:"uid"`
	Groups   []string                     `json:"groups,omitempty"`
	Scopes   []string                     `json:"scopes.authorization.openshift.io"`
	Extra    map[string]authv1.ExtraValue `json:"extra,omitempty"`
}

UserInfo - holds information about the user that created a resource.

type Work

type Work interface {
	ID() string
	Method() bundle.JobMethod
	Run(token string, msgBuffer chan<- JobMsg)
}

Work - is the interface that wraps the basic run method.

type WorkEngine

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

WorkEngine - a new engine for doing work.

func NewWorkEngine

func NewWorkEngine(bufferSize int, subscriberTimeout time.Duration, dao dao.Dao) *WorkEngine

NewWorkEngine - creates a new work engine

func (*WorkEngine) AttachSubscriber

func (engine *WorkEngine) AttachSubscriber(
	subscriber WorkSubscriber, topic WorkTopic,
) error

AttachSubscriber - Attach a subscriber a specific messaging topic. Will send the JobMsg to the subscribers through the message buffer.

func (*WorkEngine) GetActiveJobChannels

func (engine *WorkEngine) GetActiveJobChannels() map[string]chan JobMsg

GetActiveJobChannels - Get list of active jobs

func (*WorkEngine) GetSubscribers

func (engine *WorkEngine) GetSubscribers(topic WorkTopic) []WorkSubscriber

GetSubscribers - Get list of subscribers to a topic

func (*WorkEngine) StartNewAsyncJob

func (engine *WorkEngine) StartNewAsyncJob(
	token string, work Work, topic WorkTopic,
) (string, error)

StartNewAsyncJob - Starts a job in an new goroutine, reporting to a specific topic. returns token, or generated token if an empty token is passed in.

func (*WorkEngine) StartNewSyncJob

func (engine *WorkEngine) StartNewSyncJob(
	token string, work Work, topic WorkTopic,
) error

StartNewSyncJob - Starts a job and waits for it to finish, reporting to a specific topic.

func (*WorkEngine) Token

func (engine *WorkEngine) Token() string

Token generates a new work token

type WorkFactory

type WorkFactory interface {
	NewProvisionJob(si *bundle.ServiceInstance) Work
	NewDeprovisionJob(si *bundle.ServiceInstance, skipExecution bool) Work
	NewUnbindJob(bindingID string, params *bundle.Parameters, si *bundle.ServiceInstance, skipExecution bool) Work
	NewBindJob(bindingID string, bindingParams *bundle.Parameters, si *bundle.ServiceInstance) Work
	NewUpdateJob(si *bundle.ServiceInstance) Work
}

WorkFactory is a factory for creating Work items

func NewWorkFactory

func NewWorkFactory() WorkFactory

NewWorkFactory will return a work factory capable of creating different kinds of work

type WorkSubscriber

type WorkSubscriber interface {
	ID() string
	Notify(msg JobMsg)
}

WorkSubscriber - Defines how a Subscriber can be notified of changes

type WorkTopic

type WorkTopic string

WorkTopic - Topic jobs can publish messages to, and subscribers can listen to

const (
	ProvisionTopic   WorkTopic = "provision_topic"
	DeprovisionTopic WorkTopic = "deprovision_topic"
	UpdateTopic      WorkTopic = "update_topic"
	BindingTopic     WorkTopic = "binding_topic"
	UnbindingTopic   WorkTopic = "unbinding_topic"
)

Work Engine messaging consts

Jump to

Keyboard shortcuts

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