Documentation ¶
Index ¶
- Constants
- Variables
- func CheckHTTPCode(result *Result, e error) error
- func CreateAdminRoleBinding(namespace string) environment.Object
- func DELETE(modifiers ...MethodDefModifier) methodDefCreator
- func ENSURE_DELETION(active bool, modifiers ...MethodDefModifier) methodDefCreator
- func GET(modifiers ...MethodDefModifier) methodDefCreator
- func NewObject(kind, namespaceName string, name string) environment.Object
- func PATCH(modifiers ...MethodDefModifier) methodDefCreator
- func POST(modifiers ...MethodDefModifier) methodDefCreator
- type ActionOptions
- type AfterDoCallback
- type AfterDoCallbackFunc
- type AfterDoCallbackFuncCreator
- type AfterDoCallbacksChain
- type BeforeDoCallback
- type BeforeDoCallbackFunc
- type BeforeDoCallbackFuncCreator
- type BeforeDoCallbacksChain
- type CallbackContext
- type CheNamespaceTypeService
- type Client
- type CommonEnvTypeService
- func (t *CommonEnvTypeService) AdditionalObject() (environment.Object, bool)
- func (t *CommonEnvTypeService) AfterCallback(client *Client, action string) error
- func (t *CommonEnvTypeService) GetCluster() cluster.Cluster
- func (t *CommonEnvTypeService) GetEnvDataAndObjects(filter FilterFunc) (*environment.EnvData, environment.Objects, error)
- func (t *CommonEnvTypeService) GetNamespaceName() string
- func (t *CommonEnvTypeService) GetTokenProducer(forceMasterTokenGlobally bool) TokenProducer
- func (t *CommonEnvTypeService) GetType() environment.Type
- type CreateAction
- func (c CreateAction) Filter() FilterFunc
- func (c *CreateAction) ForceMasterTokenGlobally() bool
- func (c *CreateAction) GetNamespaceEntity(nsTypeService EnvironmentTypeService) (*tenant.Namespace, error)
- func (c *CreateAction) GetOperationSets(envService EnvironmentTypeService, client Client) (*environment.EnvData, []OperationSet, error)
- func (c *CreateAction) HealingStrategy() HealingFuncGenerator
- func (c CreateAction) ManageAndUpdateResults(errorChan chan error, envTypes []environment.Type, healing Healing) error
- func (c CreateAction) MethodName() string
- func (c *CreateAction) UpdateNamespace(env *environment.EnvData, cluster *cluster.Cluster, ...)
- type DeleteAction
- func (d *DeleteAction) Filter() FilterFunc
- func (d *DeleteAction) GetNamespaceEntity(nsTypeService EnvironmentTypeService) (*tenant.Namespace, error)
- func (d *DeleteAction) GetOperationSets(envService EnvironmentTypeService, client Client) (*environment.EnvData, []OperationSet, error)
- func (d *DeleteAction) HealingStrategy() HealingFuncGenerator
- func (d *DeleteAction) ManageAndUpdateResults(errorChan chan error, envTypes []environment.Type, healing Healing) error
- func (d *DeleteAction) UpdateNamespace(env *environment.EnvData, cluster *cluster.Cluster, ...)
- type DeleteActionOption
- type EnvironmentTypeService
- type FilterFunc
- type Healing
- type HealingFuncGenerator
- type MethodDefModifier
- type MethodDefinition
- type NamespaceAction
- type ObjectChecker
- type ObjectEndpoints
- type OperationSet
- type RequestCreator
- type RequestCreatorModifier
- type Result
- type Service
- type ServiceBuilder
- func (b *ServiceBuilder) Create(nsTypes []environment.Type, actionOpts *ActionOptions) error
- func (b *ServiceBuilder) Delete(nsTypes []environment.Type, existingNamespaces []*tenant.Namespace, ...) error
- func (b *ServiceBuilder) Update(nsTypes []environment.Type, existingNamespaces []*tenant.Namespace, ...) error
- type ServiceContext
- type TokenProducer
- type UpdateAction
- func (u *UpdateAction) Filter() FilterFunc
- func (u *UpdateAction) GetNamespaceEntity(nsTypeService EnvironmentTypeService) (*tenant.Namespace, error)
- func (u *UpdateAction) GetOperationSets(envService EnvironmentTypeService, client Client) (*environment.EnvData, []OperationSet, error)
- func (u *UpdateAction) HealingStrategy() HealingFuncGenerator
- func (u *UpdateAction) UpdateNamespace(env *environment.EnvData, cluster *cluster.Cluster, ...)
- type UserNamespaceTypeService
- type UserTokenResolver
Constants ¶
const ( GetObjectAndMergeName = "GetObjectAndMerge" FailIfExistsName = "FailIfAlreadyExists" WhenConflictThenDeleteAndRedoName = "WhenConflictThenDeleteAndRedo" GetObjectName = "GetObject" IgnoreWhenDoesNotExistName = "IgnoreWhenDoesNotExistOrConflicts" TryToWaitUntilIsGoneName = "TryToWaitUntilIsGone" WaitUntilIsRemovedName = "WaitUntilIsRemoved" )
const EnsureDeletion = "ENSURE_DELETION"
Variables ¶
var ( AllObjectEndpoints = map[string]*ObjectEndpoints{ environment.ValKindNamespace: endpoints( endpoint(`/api/v1/namespaces`, POST(BeforeDo(FailIfAlreadyExists), AfterDo(GetObject))), endpoint(`/api/v1/namespaces/{{ index . "metadata" "name"}}`, PATCH(), GET(), DELETE(), ENSURE_DELETION(false))), environment.ValKindProject: endpoints( endpoint(`/oapi/v1/projects`, POST(BeforeDo(FailIfAlreadyExists), AfterDo(GetObject))), endpoint(`/oapi/v1/projects/{{ index . "metadata" "name"}}`, PATCH(), GET(), DELETE(), ENSURE_DELETION(false))), environment.ValKindProjectRequest: endpoints( endpoint(`/oapi/v1/projectrequests`, POST(BeforeDo(FailIfAlreadyExists), AfterDo(GetObject))), endpoint(`/oapi/v1/projects/{{ index . "metadata" "name"}}`, PATCH(), GET(), DELETE(), ENSURE_DELETION(false))), environment.ValKindRole: endpoints( endpoint(`/oapi/v1/namespaces/{{ index . "metadata" "namespace"}}/roles`, POST(AfterDo(WhenConflictThenDeleteAndRedo))), endpoint(`/oapi/v1/namespaces/{{ index . "metadata" "namespace"}}/roles/{{ index . "metadata" "name"}}`, PATCH(), GET(), DELETE(), ENSURE_DELETION(true))), environment.ValKindRoleBinding: endpoints( endpoint(`/oapi/v1/namespaces/{{ index . "metadata" "namespace"}}/rolebindings`, POST(AfterDo(WhenConflictThenDeleteAndRedo))), endpoint(`/oapi/v1/namespaces/{{ index . "metadata" "namespace"}}/rolebindings/{{ index . "metadata" "name"}}`, PATCH(), GET(), DELETE(Require(MasterToken)), ENSURE_DELETION(true))), environment.ValKindRoleBindingRestriction: endpoints( endpoint(`/oapi/v1/namespaces/{{ index . "metadata" "namespace"}}/rolebindingrestrictions`, POST(Require(MasterToken), AfterDo(WhenConflictThenDeleteAndRedo))), endpoint(`/oapi/v1/namespaces/{{ index . "metadata" "namespace"}}/rolebindingrestrictions/{{ index . "metadata" "name"}}`, PATCH(Require(MasterToken)), GET(Require(MasterToken)), DELETE(Require(MasterToken)), ENSURE_DELETION(true))), environment.ValKindRoute: endpoints( endpoint(`/oapi/v1/namespaces/{{ index . "metadata" "namespace"}}/routes`, POST(AfterDo(WhenConflictThenDeleteAndRedo))), endpoint(`/oapi/v1/namespaces/{{ index . "metadata" "namespace"}}/routes/{{ index . "metadata" "name"}}`, PATCH(), GET(), DELETE(), ENSURE_DELETION(true))), environment.ValKindDeployment: endpoints( endpoint(`/apis/apps/v1/namespaces/{{ index . "metadata" "namespace"}}/deployments`, POST(AfterDo(WhenConflictThenDeleteAndRedo))), endpoint(`/apis/apps/v1/namespaces/{{ index . "metadata" "namespace"}}/deployments/{{ index . "metadata" "name"}}`, PATCH(), GET(), DELETE(), ENSURE_DELETION(true))), environment.ValKindDeploymentConfig: endpoints( endpoint(`/apis/apps.openshift.io/v1/namespaces/{{ index . "metadata" "namespace"}}/deploymentconfigs`, POST(AfterDo(WhenConflictThenDeleteAndRedo))), endpoint(`/apis/apps.openshift.io/v1/namespaces/{{ index . "metadata" "namespace"}}/deploymentconfigs/{{ index . "metadata" "name"}}`, PATCH(), GET(), DELETE(), ENSURE_DELETION(true))), environment.ValKindPersistentVolumeClaim: endpoints( endpoint(`/api/v1/namespaces/{{ index . "metadata" "namespace"}}/persistentvolumeclaims`, POST(AfterDo(WhenConflictThenDeleteAndRedo))), endpoint(`/api/v1/namespaces/{{ index . "metadata" "namespace"}}/persistentvolumeclaims/{{ index . "metadata" "name"}}`, PATCH(), GET(), DELETE(AfterDo(TryToWaitUntilIsGone)), ENSURE_DELETION(false))), environment.ValKindService: endpoints( endpoint(`/api/v1/namespaces/{{ index . "metadata" "namespace"}}/services`, POST(AfterDo(WhenConflictThenDeleteAndRedo))), endpoint(`/api/v1/namespaces/{{ index . "metadata" "namespace"}}/services/{{ index . "metadata" "name"}}`, PATCH(), GET(), DELETE(), ENSURE_DELETION(true))), environment.ValKindSecret: endpoints( endpoint(`/api/v1/namespaces/{{ index . "metadata" "namespace"}}/secrets`, POST(AfterDo(WhenConflictThenDeleteAndRedo))), endpoint(`/api/v1/namespaces/{{ index . "metadata" "namespace"}}/secrets/{{ index . "metadata" "name"}}`, PATCH(), GET(), DELETE(), ENSURE_DELETION(true))), environment.ValKindServiceAccount: endpoints( endpoint(`/api/v1/namespaces/{{ index . "metadata" "namespace"}}/serviceaccounts`, POST(AfterDo(WhenConflictThenDeleteAndRedo))), endpoint(`/api/v1/namespaces/{{ index . "metadata" "namespace"}}/serviceaccounts/{{ index . "metadata" "name"}}`, PATCH(), GET(), DELETE(), ENSURE_DELETION(true))), environment.ValKindConfigMap: endpoints( endpoint(`/api/v1/namespaces/{{ index . "metadata" "namespace"}}/configmaps`, POST(AfterDo(WhenConflictThenDeleteAndRedo))), endpoint(`/api/v1/namespaces/{{ index . "metadata" "namespace"}}/configmaps/{{ index . "metadata" "name"}}`, PATCH(), GET(), DELETE(), ENSURE_DELETION(true))), environment.ValKindResourceQuota: endpoints( endpoint(`/api/v1/namespaces/{{ index . "metadata" "namespace"}}/resourcequotas`, POST(AfterDo(WhenConflictThenDeleteAndRedo, GetObject))), endpoint(`/api/v1/namespaces/{{ index . "metadata" "namespace"}}/resourcequotas/{{ index . "metadata" "name"}}`, PATCH(), GET(), DELETE(), ENSURE_DELETION(true))), environment.ValKindLimitRange: endpoints( endpoint(`/api/v1/namespaces/{{ index . "metadata" "namespace"}}/limitranges`, POST(AfterDo(WhenConflictThenDeleteAndRedo))), endpoint(`/api/v1/namespaces/{{ index . "metadata" "namespace"}}/limitranges/{{ index . "metadata" "name"}}`, PATCH(), GET(), DELETE(), ENSURE_DELETION(true))), environment.ValKindJob: endpoints( endpoint(`/apis/batch/v1/namespaces/{{ index . "metadata" "namespace"}}/jobs`, POST(AfterDo(WhenConflictThenDeleteAndRedo))), endpoint(`/apis/batch/v1/namespaces/{{ index . "metadata" "namespace"}}/jobs/{{ index . "metadata" "name"}}`, PATCH(), GET(), DELETE(), ENSURE_DELETION(true))), environment.ValKindPod: endpoints( endpoint(`/api/v1/namespaces/{{ index . "metadata" "namespace"}}/pods`, POST(AfterDo(WhenConflictThenDeleteAndRedo))), endpoint(`/api/v1/namespaces/{{ index . "metadata" "namespace"}}/pods/{{ index . "metadata" "name"}}`, PATCH(), GET(), DELETE(), ENSURE_DELETION(true))), environment.ValKindReplicationController: endpoints( endpoint(`/api/v1/namespaces/{{ index . "metadata" "namespace"}}/replicationcontrollers`, POST(AfterDo(WhenConflictThenDeleteAndRedo))), endpoint(`/api/v1/namespaces/{{ index . "metadata" "namespace"}}/replicationcontrollers/{{ index . "metadata" "name"}}`, PATCH(), GET(), DELETE(), ENSURE_DELETION(true))), environment.ValKindDaemonSet: endpoints( endpoint(`/apis/apps/v1/namespaces/{{ index . "metadata" "namespace"}}/daemonsets`, POST(AfterDo(WhenConflictThenDeleteAndRedo))), endpoint(`/apis/apps/v1/namespaces/{{ index . "metadata" "namespace"}}/daemonsets/{{ index . "metadata" "name"}}`, PATCH(), GET(), DELETE(), ENSURE_DELETION(true))), environment.ValKindReplicaSet: endpoints( endpoint(`/apis/apps/v1/namespaces/{{ index . "metadata" "namespace"}}/replicasets`, POST(AfterDo(WhenConflictThenDeleteAndRedo))), endpoint(`/apis/apps/v1/namespaces/{{ index . "metadata" "namespace"}}/replicasets/{{ index . "metadata" "name"}}`, PATCH(), GET(), DELETE(), ENSURE_DELETION(true))), environment.ValKindStatefulSet: endpoints( endpoint(`/apis/apps/v1/namespaces/{{ index . "metadata" "namespace"}}/statefulsets`, POST(AfterDo(WhenConflictThenDeleteAndRedo))), endpoint(`/apis/apps/v1/namespaces/{{ index . "metadata" "namespace"}}/statefulsets/{{ index . "metadata" "name"}}`, PATCH(), GET(), DELETE(), ENSURE_DELETION(true))), environment.ValKindHorizontalPodAutoScaler: endpoints( endpoint(`/apis/autoscaling/v1/namespaces/{{ index . "metadata" "namespace"}}/horizontalpodautoscalers`, POST(AfterDo(WhenConflictThenDeleteAndRedo))), endpoint(`/apis/autoscaling/v1/namespaces/{{ index . "metadata" "namespace"}}/horizontalpodautoscalers/{{ index . "metadata" "name"}}`, PATCH(), GET(), DELETE(), ENSURE_DELETION(true))), environment.ValKindCronJob: endpoints( endpoint(`/apis/batch/v1beta1/namespaces/{{ index . "metadata" "namespace"}}/cronjobs`, POST(AfterDo(WhenConflictThenDeleteAndRedo))), endpoint(`/apis/batch/v1beta1/namespaces/{{ index . "metadata" "namespace"}}/cronjobs/{{ index . "metadata" "name"}}`, PATCH(), GET(), DELETE(), ENSURE_DELETION(true))), environment.ValKindBuildConfig: endpoints( endpoint(`/apis/build.openshift.io/v1/namespaces/{{ index . "metadata" "namespace"}}/buildconfigs`, POST(AfterDo(WhenConflictThenDeleteAndRedo))), endpoint(`/apis/build.openshift.io/v1/namespaces/{{ index . "metadata" "namespace"}}/buildconfigs/{{ index . "metadata" "name"}}`, PATCH(), GET(), DELETE(), ENSURE_DELETION(true))), environment.ValKindBuild: endpoints( endpoint(`/apis/build.openshift.io/v1/namespaces/{{ index . "metadata" "namespace"}}/builds`, POST(AfterDo(WhenConflictThenDeleteAndRedo))), endpoint(`/apis/build.openshift.io/v1/namespaces/{{ index . "metadata" "namespace"}}/builds/{{ index . "metadata" "name"}}`, PATCH(), GET(), DELETE(), ENSURE_DELETION(true))), environment.ValKindImageStream: endpoints( endpoint(`/apis/image.openshift.io/v1/namespaces/{{ index . "metadata" "namespace"}}/imagestreams`, POST(AfterDo(WhenConflictThenDeleteAndRedo))), endpoint(`/apis/image.openshift.io/v1/namespaces/{{ index . "metadata" "namespace"}}/imagestreams/{{ index . "metadata" "name"}}`, PATCH(), GET(), DELETE(), ENSURE_DELETION(true))), } )
var AllToGetAndDelete = []string{environment.ValKindService, environment.ValKindPod, environment.ValKindReplicationController, environment.ValKindDaemonSet, environment.ValKindDeployment, environment.ValKindReplicaSet, environment.ValKindStatefulSet, environment.ValKindJob, environment.ValKindHorizontalPodAutoScaler, environment.ValKindCronJob, environment.ValKindDeploymentConfig, environment.ValKindBuildConfig, environment.ValKindBuild, environment.ValKindImageStream, environment.ValKindRoute, environment.ValKindPersistentVolumeClaim, environment.ValKindConfigMap}
var DefaultBeforeDoCallBack = func(context CallbackContext) (*MethodDefinition, []byte, error) {
reqBody, err := yaml.Marshal(context.Object)
return context.Method, reqBody, err
}
var FailIfAlreadyExists = BeforeDoCallback{ Create: func(previousCallback BeforeDoCallbackFunc) BeforeDoCallbackFunc { return func(context CallbackContext) (*MethodDefinition, []byte, error) { method, body, err := previousCallback(context) if err != nil { return method, body, err } masterClient := *context.Client masterClient.TokenProducer = func(forceMasterToken bool) string { return context.Client.TokenProducer(true) } result, err := context.ObjEndpoints.Apply(&masterClient, context.Object, http.MethodGet) if err != nil { if result != nil && isNotPresent(result.Response.StatusCode) { bodyToSend, err := yaml.Marshal(context.Object) if err != nil { return nil, nil, errors.Wrapf(err, "unable marshal object to be send to OS as part of %s request", method.action) } return method, bodyToSend, nil } } return nil, nil, fmt.Errorf("the object [%s] already exists", context.Object.ToString()) } }, Name: FailIfExistsName, }
var GetObject = AfterDoCallback{ Create: func(previousCallback AfterDoCallbackFunc) AfterDoCallbackFunc { return func(context CallbackContext) (*Result, error) { result, err := previousCallback(context) err = CheckHTTPCode(result, err) if err != nil { return result, err } retries := 50 errorChan := retry.Do(retries, time.Millisecond*100, func() error { getResponse, err := context.ObjEndpoints.Apply(context.Client, context.Object, http.MethodGet) err = CheckHTTPCode(getResponse, err) if err != nil { return err } getObject, err := getResponse.bodyToObject() if err != nil { return err } if !environment.HasValidStatus(getObject) { return fmt.Errorf("not ready yet") } return nil }) msg := utils.ListErrorsInMessage(errorChan, 100) if len(msg) > 0 { return result, fmt.Errorf("unable to finish the action %s on a object %s as there were %d of unsuccessful retries "+ "to get the created objects from the cluster %s. The retrieved errors:%s", context.Method.action, context.Object, retries, context.Client.MasterURL, msg) } return result, nil } }, Name: GetObjectName, }
var GetObjectAndMerge = BeforeDoCallback{ Create: func(previousCallback BeforeDoCallbackFunc) BeforeDoCallbackFunc { return func(context CallbackContext) (*MethodDefinition, []byte, error) { method, body, err := previousCallback(context) if err != nil { return method, body, err } retries := 10 errorChan := retry.Do(retries, time.Second, func() error { result, err := context.ObjEndpoints.Apply(context.Client, context.Object, http.MethodGet) if result != nil && isNotPresent(result.Response.StatusCode) { method, err = context.ObjEndpoints.GetMethodDefinition(http.MethodPost, context.Object) if err != nil { return err } return nil } if err != nil { return err } var returnedObj environment.Object err = yaml.Unmarshal(result.Body, &returnedObj) if err != nil { return errors.Wrapf(err, "unable unmarshal object responded from OS while doing GET method") } if isInTerminatingState(returnedObj) { return fmt.Errorf("the object %s is in terminating state - cannot create PATCH for it - need to wait till it is completely removed", returnedObj) } environment.GetStatus(returnedObj) body, err = marshalYAMLToJSON(context.Object) if err != nil { return errors.Wrapf(err, "unable marshal object to be send to OS as part of %s request", method.action) } return nil }) msg := utils.ListErrorsInMessage(errorChan, 100) if len(msg) > 0 { return nil, nil, fmt.Errorf("unable to finish the action %s on a object %s as there were %d of unsuccessful retries "+ "to get object and create a patch for the cluster %s. The retrieved errors:%s", method.action, context.Object, retries, context.Client.MasterURL, msg) } return method, body, nil } }, Name: GetObjectAndMergeName, }
Before callbacks
var IgnoreWhenDoesNotExistOrConflicts = AfterDoCallback{ Create: func(previousCallback AfterDoCallbackFunc) AfterDoCallbackFunc { return func(context CallbackContext) (*Result, error) { result, err := previousCallback(context) code := result.Response.StatusCode if isNotPresent(code) || code == http.StatusConflict { logrus.WithFields(map[string]interface{}{ "action": context.Method.action, "status": result.Response.Status, "object-kind": environment.GetKind(context.Object), "object-name": environment.GetName(context.Object), "namespace": environment.GetNamespace(context.Object), "message": string(result.Body), }).Warnf("failed to %s the object. Ignoring this error because it probably does not exist or is being removed", context.Method.action) return &Result{}, nil } return result, err } }, Name: IgnoreWhenDoesNotExistName, }
var NoHealing = func(openShiftService *ServiceBuilder) Healing { return func(originalError error) error { return originalError } }
var TryToWaitUntilIsGone = AfterDoCallback{ Create: func(previousCallback AfterDoCallbackFunc) AfterDoCallbackFunc { return func(context CallbackContext) (*Result, error) { result, err := previousCallback(context) err = CheckHTTPCode(result, err) if err != nil { return result, err } retries := 60 msg := waitUntilIsGone(context, retries, true) if len(msg) > 0 { logrus.WithFields(map[string]interface{}{ "action": context.Method.action, "object-kind": environment.GetKind(context.Object), "object-name": environment.GetName(context.Object), "namespace": environment.GetNamespace(context.Object), "cluster": context.Client.MasterURL, "first-5-errors": msg, }).Warnf("unable to finish the action %s for an object as there were %d of unsuccessful retries to completely remove the objects from the cluster", context.Method.action, retries) } return result, nil } }, Name: TryToWaitUntilIsGoneName, }
var WhenConflictThenDeleteAndRedo = AfterDoCallback{ Create: func(previousCallback AfterDoCallbackFunc) AfterDoCallbackFunc { return func(context CallbackContext) (*Result, error) { result, err := previousCallback(context) if result.Response != nil && result.Response.StatusCode == http.StatusConflict { logrus.WithFields(map[string]interface{}{ "method": context.Method.action, "object-kind": environment.GetKind(context.Object), "object-name": environment.GetName(context.Object), "namespace": environment.GetNamespace(context.Object), }).Warnf("there was a conflict, trying to delete the object and re-do the operation") err := CheckHTTPCode(context.ObjEndpoints.Apply(context.Client, context.Object, http.MethodDelete)) if err != nil { return result, errors.Wrap(err, "delete request failed while removing an object because of a conflict") } redoMethod := removeAfterDoCallback(*context.Method, WhenConflictThenDeleteAndRedoName) redoResult, err := context.ObjEndpoints.apply(context.Client, context.Object, redoMethod) err = CheckHTTPCode(redoResult, err) if err != nil { return redoResult, errors.Wrapf(err, "redoing an action %s failed after the object was successfully removed because of a previous conflict", context.Method.action) } return redoResult, nil } return result, err } }, Name: WhenConflictThenDeleteAndRedoName, }
After callbacks
Functions ¶
func CheckHTTPCode ¶
func CreateAdminRoleBinding ¶
func CreateAdminRoleBinding(namespace string) environment.Object
func DELETE ¶
func DELETE(modifiers ...MethodDefModifier) methodDefCreator
func ENSURE_DELETION ¶
func ENSURE_DELETION(active bool, modifiers ...MethodDefModifier) methodDefCreator
func GET ¶
func GET(modifiers ...MethodDefModifier) methodDefCreator
func PATCH ¶
func PATCH(modifiers ...MethodDefModifier) methodDefCreator
func POST ¶
func POST(modifiers ...MethodDefModifier) methodDefCreator
Types ¶
type ActionOptions ¶
type ActionOptions struct {
// contains filtered or unexported fields
}
func CreateOpts ¶
func CreateOpts() *ActionOptions
func UpdateOpts ¶
func UpdateOpts() *ActionOptions
func (*ActionOptions) DisableSelfHealing ¶
func (o *ActionOptions) DisableSelfHealing() *ActionOptions
func (*ActionOptions) EnableSelfHealing ¶
func (o *ActionOptions) EnableSelfHealing() *ActionOptions
type AfterDoCallback ¶
type AfterDoCallback struct { Create AfterDoCallbackFuncCreator Name string }
type AfterDoCallbackFunc ¶
type AfterDoCallbackFunc func(context CallbackContext) (*Result, error)
type AfterDoCallbackFuncCreator ¶
type AfterDoCallbackFuncCreator func(previousCallback AfterDoCallbackFunc) AfterDoCallbackFunc
type AfterDoCallbacksChain ¶
type AfterDoCallbacksChain []AfterDoCallback
type BeforeDoCallback ¶
type BeforeDoCallback struct { Create BeforeDoCallbackFuncCreator Name string }
func WaitUntilIsRemoved ¶
func WaitUntilIsRemoved(doCheckAndContinue bool) BeforeDoCallback
type BeforeDoCallbackFunc ¶
type BeforeDoCallbackFunc func(context CallbackContext) (*MethodDefinition, []byte, error)
type BeforeDoCallbackFuncCreator ¶
type BeforeDoCallbackFuncCreator func(previousCallback BeforeDoCallbackFunc) BeforeDoCallbackFunc
type BeforeDoCallbacksChain ¶
type BeforeDoCallbacksChain []BeforeDoCallback
type CallbackContext ¶
type CallbackContext struct { Client *Client Object environment.Object ObjEndpoints *ObjectEndpoints Method *MethodDefinition }
func NewCallbackContext ¶
func NewCallbackContext(client *Client, object environment.Object, objEndpoints *ObjectEndpoints, method *MethodDefinition) CallbackContext
type CheNamespaceTypeService ¶
type CheNamespaceTypeService struct { *CommonEnvTypeService // contains filtered or unexported fields }
func (*CheNamespaceTypeService) AdditionalObject ¶
func (t *CheNamespaceTypeService) AdditionalObject() (environment.Object, bool)
type Client ¶
type Client struct { MasterURL string TokenProducer TokenProducer // contains filtered or unexported fields }
func NewClient ¶
func NewClient(httpTransport http.RoundTripper, masterURL string, TokenProducer TokenProducer) *Client
func (*Client) Do ¶
func (c *Client) Do(requestCreator RequestCreator, object environment.Object, body []byte) (*Result, error)
type CommonEnvTypeService ¶
type CommonEnvTypeService struct {
// contains filtered or unexported fields
}
func (*CommonEnvTypeService) AdditionalObject ¶
func (t *CommonEnvTypeService) AdditionalObject() (environment.Object, bool)
func (*CommonEnvTypeService) AfterCallback ¶
func (t *CommonEnvTypeService) AfterCallback(client *Client, action string) error
func (*CommonEnvTypeService) GetCluster ¶
func (t *CommonEnvTypeService) GetCluster() cluster.Cluster
func (*CommonEnvTypeService) GetEnvDataAndObjects ¶
func (t *CommonEnvTypeService) GetEnvDataAndObjects(filter FilterFunc) (*environment.EnvData, environment.Objects, error)
func (*CommonEnvTypeService) GetNamespaceName ¶
func (t *CommonEnvTypeService) GetNamespaceName() string
func (*CommonEnvTypeService) GetTokenProducer ¶
func (t *CommonEnvTypeService) GetTokenProducer(forceMasterTokenGlobally bool) TokenProducer
func (*CommonEnvTypeService) GetType ¶
func (t *CommonEnvTypeService) GetType() environment.Type
type CreateAction ¶
type CreateAction struct {
// contains filtered or unexported fields
}
func NewCreateAction ¶
func NewCreateAction(tenantRepo tenant.Repository, actionOpts *ActionOptions) *CreateAction
func (CreateAction) Filter ¶
func (c CreateAction) Filter() FilterFunc
func (*CreateAction) ForceMasterTokenGlobally ¶
func (c *CreateAction) ForceMasterTokenGlobally() bool
func (*CreateAction) GetNamespaceEntity ¶
func (c *CreateAction) GetNamespaceEntity(nsTypeService EnvironmentTypeService) (*tenant.Namespace, error)
func (*CreateAction) GetOperationSets ¶
func (c *CreateAction) GetOperationSets(envService EnvironmentTypeService, client Client) (*environment.EnvData, []OperationSet, error)
func (*CreateAction) HealingStrategy ¶
func (c *CreateAction) HealingStrategy() HealingFuncGenerator
func (CreateAction) ManageAndUpdateResults ¶
func (c CreateAction) ManageAndUpdateResults(errorChan chan error, envTypes []environment.Type, healing Healing) error
func (CreateAction) MethodName ¶
func (c CreateAction) MethodName() string
func (*CreateAction) UpdateNamespace ¶
func (c *CreateAction) UpdateNamespace(env *environment.EnvData, cluster *cluster.Cluster, namespace *tenant.Namespace, failed bool)
type DeleteAction ¶
type DeleteAction struct {
// contains filtered or unexported fields
}
func NewDeleteAction ¶
func NewDeleteAction(tenantRepo tenant.Repository, existingNamespaces []*tenant.Namespace, deleteOpts *DeleteActionOption) *DeleteAction
func (*DeleteAction) Filter ¶
func (d *DeleteAction) Filter() FilterFunc
func (*DeleteAction) GetNamespaceEntity ¶
func (d *DeleteAction) GetNamespaceEntity(nsTypeService EnvironmentTypeService) (*tenant.Namespace, error)
func (*DeleteAction) GetOperationSets ¶
func (d *DeleteAction) GetOperationSets(envService EnvironmentTypeService, client Client) (*environment.EnvData, []OperationSet, error)
func (*DeleteAction) HealingStrategy ¶
func (d *DeleteAction) HealingStrategy() HealingFuncGenerator
func (*DeleteAction) ManageAndUpdateResults ¶
func (d *DeleteAction) ManageAndUpdateResults(errorChan chan error, envTypes []environment.Type, healing Healing) error
func (*DeleteAction) UpdateNamespace ¶
func (d *DeleteAction) UpdateNamespace(env *environment.EnvData, cluster *cluster.Cluster, namespace *tenant.Namespace, failed bool)
type DeleteActionOption ¶
type DeleteActionOption struct { *ActionOptions // contains filtered or unexported fields }
func DeleteOpts ¶
func DeleteOpts() *DeleteActionOption
func (*DeleteActionOption) ButKeepTenantEntity ¶
func (o *DeleteActionOption) ButKeepTenantEntity() *DeleteActionOption
func (*DeleteActionOption) DisableSelfHealing ¶
func (o *DeleteActionOption) DisableSelfHealing() *DeleteActionOption
func (*DeleteActionOption) EnableSelfHealing ¶
func (o *DeleteActionOption) EnableSelfHealing() *DeleteActionOption
func (*DeleteActionOption) RemoveFromCluster ¶
func (o *DeleteActionOption) RemoveFromCluster() *DeleteActionOption
type EnvironmentTypeService ¶
type EnvironmentTypeService interface { GetType() environment.Type GetNamespaceName() string GetEnvDataAndObjects(filter FilterFunc) (*environment.EnvData, environment.Objects, error) GetCluster() cluster.Cluster AfterCallback(client *Client, action string) error GetTokenProducer(forceMasterTokenGlobally bool) TokenProducer AdditionalObject() (environment.Object, bool) }
EnvironmentTypeService represents service operating with information related to environment types(template, objects, cluster,...). It is responsible for getting, sorting and filtering objects to be applied, provides information (needed token) specific for the particular type and performs after-apply-callback (needed by user namespace)
func NewEnvironmentTypeService ¶
func NewEnvironmentTypeService(envType environment.Type, context *ServiceContext, envService *environment.Service) EnvironmentTypeService
type FilterFunc ¶
type FilterFunc func(environment.Object) bool
type HealingFuncGenerator ¶
type HealingFuncGenerator func(openShiftService *ServiceBuilder) Healing
type MethodDefModifier ¶
type MethodDefModifier func(*MethodDefinition) *MethodDefinition
func AfterDo ¶
func AfterDo(afterDoCallbacks ...AfterDoCallback) MethodDefModifier
func BeforeDo ¶
func BeforeDo(beforeDoCallback ...BeforeDoCallback) MethodDefModifier
func Require ¶
func Require(requestCreatorModifier RequestCreatorModifier) MethodDefModifier
type MethodDefinition ¶
type MethodDefinition struct {
// contains filtered or unexported fields
}
MethodDefinition represents defined actions (beforeDoCallbacks, afterDoCallbacks,requestCreator) to be executed when the method is performed for an endpoint.
func NewMethodDefinition ¶
func NewMethodDefinition(action string, beforeCallbacks []BeforeDoCallback, afterCallbacks []AfterDoCallback, requestCreator RequestCreator, modifiers ...MethodDefModifier) MethodDefinition
type NamespaceAction ¶
type NamespaceAction interface { MethodName() string GetNamespaceEntity(nsTypeService EnvironmentTypeService) (*tenant.Namespace, error) UpdateNamespace(env *environment.EnvData, cluster *cluster.Cluster, namespace *tenant.Namespace, failed bool) GetOperationSets(envService EnvironmentTypeService, client Client) (*environment.EnvData, []OperationSet, error) ForceMasterTokenGlobally() bool HealingStrategy() HealingFuncGenerator ManageAndUpdateResults(errorChan chan error, envTypes []environment.Type, healing Healing) error }
NamespaceAction represents the action that should be applied on the namespaces for the particular tenant - [post|update|delete]. It is mainly responsible for operation on DB and provides additional information specific to the action that is needed by other objects
type ObjectChecker ¶
type ObjectChecker func(object environment.Object) bool
type ObjectEndpoints ¶
type ObjectEndpoints struct {
Methods map[string]MethodDefinition
}
ObjectEndpoints is list of MethodDefinitions for a particular object endpoint (eg. `/oapi/v1/projectrequests`). In other words, is saying which methods (Post/Delete/Get/Patch) are allowed to be performed for the endpoint
func (*ObjectEndpoints) Apply ¶
func (e *ObjectEndpoints) Apply(client *Client, object environment.Object, action string) (*Result, error)
func (*ObjectEndpoints) GetMethodDefinition ¶
func (e *ObjectEndpoints) GetMethodDefinition(method string, object environment.Object) (*MethodDefinition, error)
type OperationSet ¶
type OperationSet struct { Method string Objects environment.Objects }
func NewOperationSet ¶
func NewOperationSet(method string, objects environment.Objects) OperationSet
type RequestCreator ¶
type RequestCreator struct {
// contains filtered or unexported fields
}
func MasterToken ¶
func MasterToken(requestCreator RequestCreator) RequestCreator
type RequestCreatorModifier ¶
type RequestCreatorModifier func(requestCreator RequestCreator) RequestCreator
type Result ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service knowing which action is requested starts for every requested environment type a new goroutine. The goroutine gets template objects to be applied and the target cluster; and for every object starts new goroutine that sends a request to the OS cluster.
type ServiceBuilder ¶
type ServiceBuilder struct {
// contains filtered or unexported fields
}
func NewBuilderWithTransport ¶
func NewBuilderWithTransport(context *ServiceContext, namespaceRepository tenant.Repository, transport http.RoundTripper, envService *environment.Service) *ServiceBuilder
func NewService ¶
func NewService(context *ServiceContext, repo tenant.Repository, envService *environment.Service) *ServiceBuilder
func (*ServiceBuilder) Create ¶
func (b *ServiceBuilder) Create(nsTypes []environment.Type, actionOpts *ActionOptions) error
func (*ServiceBuilder) Delete ¶
func (b *ServiceBuilder) Delete(nsTypes []environment.Type, existingNamespaces []*tenant.Namespace, deleteOpts *DeleteActionOption) error
func (*ServiceBuilder) Update ¶
func (b *ServiceBuilder) Update(nsTypes []environment.Type, existingNamespaces []*tenant.Namespace, actionOpts *ActionOptions) error
type ServiceContext ¶
type ServiceContext struct {
// contains filtered or unexported fields
}
func NewServiceContext ¶
func NewServiceContext(callerCtx context.Context, config *configuration.Data, clusterMapping cluster.ForType, openShiftUsername, nsBaseName string, userTokenResolver UserTokenResolver) *ServiceContext
type TokenProducer ¶
type UpdateAction ¶
type UpdateAction struct {
// contains filtered or unexported fields
}
func NewUpdateAction ¶
func NewUpdateAction(tenantRepo tenant.Repository, existingNamespaces []*tenant.Namespace, actionOpts *ActionOptions) *UpdateAction
func (*UpdateAction) Filter ¶
func (u *UpdateAction) Filter() FilterFunc
func (*UpdateAction) GetNamespaceEntity ¶
func (u *UpdateAction) GetNamespaceEntity(nsTypeService EnvironmentTypeService) (*tenant.Namespace, error)
func (*UpdateAction) GetOperationSets ¶
func (u *UpdateAction) GetOperationSets(envService EnvironmentTypeService, client Client) (*environment.EnvData, []OperationSet, error)
func (*UpdateAction) HealingStrategy ¶
func (u *UpdateAction) HealingStrategy() HealingFuncGenerator
func (*UpdateAction) UpdateNamespace ¶
func (u *UpdateAction) UpdateNamespace(env *environment.EnvData, cluster *cluster.Cluster, namespace *tenant.Namespace, failed bool)
type UserNamespaceTypeService ¶
type UserNamespaceTypeService struct {
*CommonEnvTypeService
}
func (*UserNamespaceTypeService) AfterCallback ¶
func (t *UserNamespaceTypeService) AfterCallback(client *Client, action string) error
func (*UserNamespaceTypeService) GetNamespaceName ¶
func (t *UserNamespaceTypeService) GetNamespaceName() string
func (*UserNamespaceTypeService) GetTokenProducer ¶
func (t *UserNamespaceTypeService) GetTokenProducer(forceMasterTokenGlobally bool) TokenProducer
type UserTokenResolver ¶
func TokenResolver ¶
func TokenResolver() UserTokenResolver
func TokenResolverForUser ¶
func TokenResolverForUser(user *auth.User) UserTokenResolver