Documentation
¶
Index ¶
- Constants
- Variables
- func Add(mgr manager.Manager) error
- func Done() (reconcile.Result, error)
- func DoneOnNotFound(err error) (reconcile.Result, error)
- func GetSBRNamespacedNameFromObject(obj runtime.Object) (types.NamespacedName, error)
- func IsNamespacedNameEmpty(namespacedName types.NamespacedName) bool
- func NewCreateWatchEventHandler(controller *SBRController) handler.EventHandler
- func NoRequeue(err error) (reconcile.Result, error)
- func RemoveAndUpdateSBRAnnotations(client dynamic.Interface, objs []*unstructured.Unstructured) error
- func RemoveSBRAnnotations(obj *unstructured.Unstructured) *unstructured.Unstructured
- func Requeue(err error, requeueAfter int64) (reconcile.Result, error)
- func RequeueError(err error) (reconcile.Result, error)
- func RequeueOnConflict(err error) (reconcile.Result, error)
- func RequeueOnNotFound(err error, requeueAfter int64) (reconcile.Result, error)
- func SetAndUpdateSBRAnnotations(client dynamic.Interface, namespacedName types.NamespacedName, ...) error
- func SetSBRAnnotations(namespacedName types.NamespacedName, obj *unstructured.Unstructured) *unstructured.Unstructured
- type Binder
- type Binding
- type CSVToWatcherMapper
- type CustomEnvParser
- type ErrInvalidServiceBinderOptions
- type ExtraFieldsModifier
- type ExtraFieldsModifierFunc
- type OLM
- func (o *OLM) ListCSVOwnedCRDs() ([]unstructured.Unstructured, error)
- func (o *OLM) ListCSVOwnedCRDsAsGVKs() ([]schema.GroupVersionKind, error)
- func (o *OLM) ListGVKsFromCSVNamespacedName(namespacedName types.NamespacedName) ([]schema.GroupVersionKind, error)
- func (o *OLM) SelectCRDByGVK(gvk schema.GroupVersionKind, crd *unstructured.Unstructured) (*olmv1alpha1.CRDDescription, error)
- type Reconciler
- type Retriever
- type SBRController
- type SBRRequestMapper
- type Secret
- type ServiceBinder
- type ServiceBinderOptions
- type ServiceContext
- type ServiceContextList
Constants ¶
const ( // ServiceBindingRequestResource the name of ServiceBindingRequest resource. ServiceBindingRequestResource = "servicebindingrequests" // ServiceBindingRequestKind defines the name of the CRD kind. ServiceBindingRequestKind = "ServiceBindingRequest" // DeploymentConfigKind defines the name of DeploymentConfig kind. DeploymentConfigKind = "DeploymentConfig" // ClusterServiceVersionKind the name of ClusterServiceVersion kind. ClusterServiceVersionKind = "ClusterServiceVersion" // SecretResource defines the resource name for Secrets. SecretResource = "secrets" // SecretKind defines the name of Secret kind. SecretKind = "Secret" )
const ( // BindingReady indicates that the binding succeeded BindingReady conditionsv1.ConditionType = "Ready" // EmptyServiceSelectorsReason is used when the ServiceBindingRequest has empty // backingServiceSelectors. EmptyServiceSelectorsReason = "EmptyServiceSelectors" )
const ( // BindingSuccess binding has succeeded BindingSuccess = "BindingSuccess" // BindingFail binding has failed BindingFail = "BindingFail" //Finalizer annotation used in finalizer steps Finalizer = "finalizer.servicebindingrequest.openshift.io" )
const ChangeTriggerEnv = "ServiceBindingOperatorChangeTriggerEnvVar"
ChangeTriggerEnv hijacking environment in order to trigger a change
Variables ¶
var ( // ErrUnspecifiedBackingServiceNamespace is returned when the namespace of a service is // unspecified. ErrUnspecifiedBackingServiceNamespace = errors.New("backing service namespace is unspecified") // EmptyBackingServiceSelectorsErr is returned when no backing service selectors have been // informed in the Service Binding Request. ErrEmptyBackingServiceSelectors = errors.New("backing service selectors are empty") )
var ApplicationNotFound = errors.New("Application is already deleted")
var CRDGVR = schema.GroupVersionResource{
Group: "apiextensions.k8s.io",
Version: "v1beta1",
Resource: "customresourcedefinitions",
}
CRDGVR is the plural GVR for Kubernetes CRDs.
var EmptyApplicationSelectorErr = errors.New("application ResourceRef or MatchLabel not found")
var GroupVersion = v1alpha1.SchemeGroupVersion.WithResource(ServiceBindingRequestResource)
GroupVersion represents the service binding request resource's group version.
Functions ¶
func Add ¶
Add creates a new ServiceBindingRequest Controller and adds it to the Manager. The Manager will set fields on the Controller and Start it when the Manager is Started.
func DoneOnNotFound ¶ added in v0.1.1
DoneOnNotFound will return done when error is not-found, otherwise it calls out NoRequeue.
func GetSBRNamespacedNameFromObject ¶ added in v0.0.19
func GetSBRNamespacedNameFromObject(obj runtime.Object) (types.NamespacedName, error)
GetSBRNamespacedNameFromObject returns a types.NamespacedName if the required service binding request annotations are present in the given runtime.Object, empty otherwise. When annotations are not present, it checks if the object is an actual SBR, returning the details when positive. An error can be returned in the case the object can't be decoded.
func IsNamespacedNameEmpty ¶ added in v0.0.19
func IsNamespacedNameEmpty(namespacedName types.NamespacedName) bool
IsNamespacedNameEmpty returns true if any of the fields from the given namespacedName is empty.
func NewCreateWatchEventHandler ¶ added in v0.0.19
func NewCreateWatchEventHandler(controller *SBRController) handler.EventHandler
NewCreateWatchEventHandler creates a new instance of handler.EventHandler interface with CSVToWatcherMapper as map-func.
func RemoveAndUpdateSBRAnnotations ¶ added in v0.1.1
func RemoveAndUpdateSBRAnnotations(client dynamic.Interface, objs []*unstructured.Unstructured) error
RemoveAndUpdateSBRAnnotations removes SBR related annotations from all the objects and updates them using the given client.
func RemoveSBRAnnotations ¶ added in v0.1.1
func RemoveSBRAnnotations(obj *unstructured.Unstructured) *unstructured.Unstructured
RemoveSBRAnnotations removes SBR related annotations and return a new object.
func Requeue ¶
Requeue based on empty result and no error informed upstream, request will be requeued.
func RequeueError ¶
RequeueError simply requeue exposing the error.
func RequeueOnConflict ¶ added in v0.1.1
RequeueOnConflict in case of conflict error, returning the error with requeue, otherwise Done.
func RequeueOnNotFound ¶
RequeueOnNotFound inspect error, if not-found then returns Requeue, otherwise expose the error.
func SetAndUpdateSBRAnnotations ¶ added in v0.1.1
func SetAndUpdateSBRAnnotations( client dynamic.Interface, namespacedName types.NamespacedName, objs []*unstructured.Unstructured, ) error
SetAndUpdateSBRAnnotations update existing annotations to include operator's. The annotations added are referring to a existing SBR namespaced name.
func SetSBRAnnotations ¶ added in v0.0.19
func SetSBRAnnotations(namespacedName types.NamespacedName, obj *unstructured.Unstructured) *unstructured.Unstructured
SetSBRAnnotations set annotations to include SBR information and return a new object.
Types ¶
type Binder ¶
type Binder struct {
// contains filtered or unexported fields
}
Binder executes the "binding" act of updating different application kinds to use intermediary secret. Those secrets should be offered as environment variables.
func NewBinder ¶
func NewBinder( ctx context.Context, dynClient dynamic.Interface, sbr *v1alpha1.ServiceBindingRequest, volumeKeys []string, restMapper meta.RESTMapper, ) *Binder
NewBinder returns a new Binder instance.
func (*Binder) Bind ¶
func (b *Binder) Bind() ([]*unstructured.Unstructured, error)
Bind resources to intermediary secret, by searching informed ResourceKind containing the labels in ApplicationSelector, and then updating spec.
type CSVToWatcherMapper ¶ added in v0.0.19
type CSVToWatcherMapper struct {
// contains filtered or unexported fields
}
CSVToWatcherMapper creates a EventHandler interface to map ClusterServiceVersion objects back to controller and add given GVK to watch list.
type CustomEnvParser ¶ added in v0.0.19
CustomEnvParser is responsible to interpolate a given EnvVar containing templates.
func NewCustomEnvParser ¶ added in v0.0.19
func NewCustomEnvParser(envMap []corev1.EnvVar, cache map[string]interface{}) *CustomEnvParser
NewCustomEnvParser returns a new CustomEnvParser.
func (*CustomEnvParser) Parse ¶ added in v0.0.19
func (c *CustomEnvParser) Parse() (map[string]interface{}, error)
Parse interpolates and caches the templates in EnvMap.
type ErrInvalidServiceBinderOptions ¶ added in v0.1.1
type ErrInvalidServiceBinderOptions string
ErrInvalidServiceBinderOptions is returned when ServiceBinderOptions contains an invalid value.
func (ErrInvalidServiceBinderOptions) Error ¶ added in v0.1.1
func (e ErrInvalidServiceBinderOptions) Error() string
type ExtraFieldsModifier ¶ added in v0.1.1
type ExtraFieldsModifier interface {
ModifyExtraFields(u *unstructured.Unstructured) error
}
ExtraFieldsModifier is useful for updating backend service which requires additional changes besides env/volumes updating. eg. for knative service we need to remove or update `spec.template.metadata.name` from service template before updating otherwise it will be rejected.
type ExtraFieldsModifierFunc ¶ added in v0.1.1
type ExtraFieldsModifierFunc func(u *unstructured.Unstructured) error
ExtraFieldsModifierFunc func receiver type for ExtraFieldsModifier
func (ExtraFieldsModifierFunc) ModifyExtraFields ¶ added in v0.1.1
func (f ExtraFieldsModifierFunc) ModifyExtraFields(u *unstructured.Unstructured) error
ModifyExtraFields implements ExtraFieldsModifier interface
type OLM ¶ added in v0.0.19
type OLM struct {
// contains filtered or unexported fields
}
OLM represents the actions this operator needs to take upon Operator-Lifecycle-Manager resources, like ClusterServiceVersions (CSV) and CRDDescriptions.
func (*OLM) ListCSVOwnedCRDs ¶ added in v0.0.19
func (o *OLM) ListCSVOwnedCRDs() ([]unstructured.Unstructured, error)
ListCSVOwnedCRDs return a unstructured list of CRD objects from "owned" section in CSVs.
func (*OLM) ListCSVOwnedCRDsAsGVKs ¶ added in v0.0.19
func (o *OLM) ListCSVOwnedCRDsAsGVKs() ([]schema.GroupVersionKind, error)
ListCSVOwnedCRDsAsGVKs return the list of owned CRDs from all CSV objects as a list of GVKs.
func (*OLM) ListGVKsFromCSVNamespacedName ¶ added in v0.0.19
func (o *OLM) ListGVKsFromCSVNamespacedName( namespacedName types.NamespacedName, ) ([]schema.GroupVersionKind, error)
ListGVKsFromCSVNamespacedName return the list of owned GVKs for a given CSV namespaced named.
func (*OLM) SelectCRDByGVK ¶ added in v0.0.19
func (o *OLM) SelectCRDByGVK(gvk schema.GroupVersionKind, crd *unstructured.Unstructured) (*olmv1alpha1.CRDDescription, error)
SelectCRDByGVK return a single CRD based on a given GVK.
type Reconciler ¶
type Reconciler struct {
RestMapper meta.RESTMapper // restMapper to convert GVK and GVR
// contains filtered or unexported fields
}
Reconciler reconciles a ServiceBindingRequest object
func (*Reconciler) Reconcile ¶
Reconcile a ServiceBindingRequest by the following steps:
- Inspecting SBR in order to identify backend service. The service is composed by a CRD name and kind, and by inspecting "connects-to" label identify the name of service instance;
- Using OperatorLifecycleManager standards, identifying which items are intersting for binding by parsing CustomResourceDefinitionDescripton object. Alternatively, this informmation may also come from special annotations in the CR/CRD;
- Search and read contents identified in previous step, creating an intermediary secret to hold data formatted as environment variables key/value;
- Search applications that are interested to bind with given service, by inspecting labels. The Deployment (and other kinds) will be updated in "spec" level.
type Retriever ¶
type Retriever struct {
// contains filtered or unexported fields
}
Retriever reads all data referred in plan instance, and store in a secret.
func NewRetriever ¶
NewRetriever instantiate a new retriever instance.
func (*Retriever) ProcessServiceContexts ¶ added in v0.1.1
func (r *Retriever) ProcessServiceContexts( globalEnvVarPrefix string, svcCtxs ServiceContextList, envVarTemplates []corev1.EnvVar, ) (map[string][]byte, []string, error)
ProcessServiceContexts returns environment variables and volume keys from a ServiceContext slice.
type SBRController ¶ added in v0.0.19
type SBRController struct {
Controller controller.Controller // controller-runtime instance
Client dynamic.Interface // kubernetes dynamic api client
// contains filtered or unexported fields
}
SBRController hold the controller instance and methods for a ServiceBindingRequest.
func NewSBRController ¶ added in v0.0.19
func NewSBRController( mgr manager.Manager, options controller.Options, client dynamic.Interface, ) (*SBRController, error)
NewSBRController creates a new SBRController instance. It can return error on bootstrapping a new dynamic client.
func (*SBRController) AddWatchForGVK ¶ added in v0.0.19
func (s *SBRController) AddWatchForGVK(gvk schema.GroupVersionKind) error
AddWatchForGVK creates a watch on a given GVK, as long as it's not duplicated.
func (*SBRController) Watch ¶ added in v0.0.19
func (s *SBRController) Watch() error
Watch setup "watch" for all GVKs relevant for SBRController.
type SBRRequestMapper ¶ added in v0.0.19
type SBRRequestMapper struct{}
SBRRequestMapper is the handler.Mapper interface implementation. It should influence the enqueue process considering the resources informed.
func (*SBRRequestMapper) Map ¶ added in v0.0.19
func (m *SBRRequestMapper) Map(obj handler.MapObject) []reconcile.Request
Map execute the mapping of a resource with the requests it would produce. Here we inspect the given object trying to identify if this object is part of a SBR, or a actual SBR resource.
type Secret ¶ added in v0.1.1
type Secret struct {
// contains filtered or unexported fields
}
Secret represents the data collected by this operator, and later handled as a secret.
func (*Secret) Commit ¶ added in v0.1.1
func (s *Secret) Commit(payload map[string][]byte) (*unstructured.Unstructured, error)
Commit will store informed data as a secret, commit it against the API server. It can forward errors from custom environment parser component, or from the API server itself.
func (*Secret) Delete ¶ added in v0.1.1
Delete the secret represented by this component. It can return error when the API server does.
func (*Secret) Get ¶ added in v0.1.1
func (s *Secret) Get() (*unstructured.Unstructured, bool, error)
Get an unstructured object from the secret handled by this component. It can return errors in case the API server does.
type ServiceBinder ¶ added in v0.1.1
type ServiceBinder struct {
// Binder is responsible for interacting with the cluster and apply binding related changes.
Binder *Binder
// EnvVars contains the environment variables to bind.
EnvVars map[string][]byte
// DynClient is the Kubernetes dynamic client used to interact with the cluster.
DynClient dynamic.Interface
// Logger provides logging facilities for internal components.
Logger *log.Log
// Objects is a list of additional unstructured objects related to the Service Binding Request.
Objects []*unstructured.Unstructured
// SBR is the ServiceBindingRequest associated with binding.
SBR *v1alpha1.ServiceBindingRequest
// Secret is the Secret associated with the Service Binding Request.
Secret *Secret
}
ServiceBinder manages binding for a Service Binding Request and associated objects.
func BuildServiceBinder ¶ added in v0.1.1
func BuildServiceBinder( ctx context.Context, options *ServiceBinderOptions, ) ( *ServiceBinder, error, )
BuildServiceBinder creates a new binding manager according to options.
type ServiceBinderOptions ¶ added in v0.1.1
type ServiceBinderOptions struct {
Logger *log.Log
DynClient dynamic.Interface
DetectBindingResources bool
SBR *v1alpha1.ServiceBindingRequest
Objects []*unstructured.Unstructured
EnvVars map[string][]byte
EnvVarPrefix string
Binding *Binding
RESTMapper meta.RESTMapper
}
ServiceBinderOptions is BuildServiceBinder arguments.
func (*ServiceBinderOptions) Valid ¶ added in v0.1.1
func (o *ServiceBinderOptions) Valid() error
Valid returns an error if the receiver is invalid, nil otherwise.
type ServiceContext ¶ added in v0.1.1
type ServiceContext struct {
// Service is the resource of the service being evaluated.
Service *unstructured.Unstructured
// EnvVars contains the service's contributed environment variables.
EnvVars map[string]interface{}
// VolumeKeys contains the keys that should be mounted as volume from the binding secret.
VolumeKeys []string
// EnvVarPrefix indicates the prefix to use in environment variables.
EnvVarPrefix *string
}
ServiceContext contains information related to a service.
type ServiceContextList ¶ added in v0.1.1
type ServiceContextList []*ServiceContext
ServiceContextList is a list of ServiceContext values.
func (ServiceContextList) GetServices ¶ added in v0.1.1
func (sc ServiceContextList) GetServices() []*unstructured.Unstructured
GetServices returns a slice of service unstructured objects contained in the collection.