validation

package
v0.0.0-...-11fd857 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertErrorFieldsToK8sError

func ConvertErrorFieldsToK8sError(ErrorFields []ErrorField) field.ErrorList

func ConvertErrorFieldsToString

func ConvertErrorFieldsToString(ErrorFields []ErrorField) string

func ConvertObjectNameToReference

func ConvertObjectNameToReference(name string) string

e.g. example-v-v1 -> example:v1

func ConvertReferenceToObjectName

func ConvertReferenceToObjectName(name string) string

e.g. example:v1 -> example-v-v1

func GetResourceMetadata

func GetResourceMetadata(resourceType ResourceType) (string, string, string, string)

func GetRootResourceFromName

func GetRootResourceFromName(name string) string

e.g. example-v-v1 -> example

func ValidateCreateOrUpdateWrapper

func ValidateCreateOrUpdateWrapper(ctx context.Context, validator IValidator, newObj interface{}, oldObj interface{}, errorWhenGetOldObj error) error

Wrapper functions for manager to call Check the error when querying objects with same name and namespace to decide whether the operation is create or update

func ValidateDeleteWrapper

func ValidateDeleteWrapper(ctx context.Context, validator IValidator, obj interface{}, errorWhenGetObj error) error

Types

type ActivationValidator

type ActivationValidator struct {
	// Check Campaign existence
	CampaignLookupFunc ObjectLookupFunc
}

func NewActivationValidator

func NewActivationValidator(campaignLookupFunc ObjectLookupFunc) ActivationValidator

func (*ActivationValidator) ConvertInterfaceToActivation

func (a *ActivationValidator) ConvertInterfaceToActivation(ref interface{}) model.ActivationState

func (*ActivationValidator) ValidateCampaignAndStage

func (a *ActivationValidator) ValidateCampaignAndStage(ctx context.Context, new model.ActivationState) *ErrorField

Validate Campaign exists for the activation And if initial stage is provided in the activation spec, validate it is a valid stage in the campaign

func (*ActivationValidator) ValidateCreateOrUpdate

func (a *ActivationValidator) ValidateCreateOrUpdate(ctx context.Context, newRef interface{}, oldRef interface{}) []ErrorField

Validate Activation creation or update 1. Campaign exists 2. If initial stage is provided in the activation spec, validate it is a valid stage in the campaign 3. Spec is immutable for update

func (*ActivationValidator) ValidateDelete

func (a *ActivationValidator) ValidateDelete(ctx context.Context, activation interface{}) []ErrorField

type CampaignValidator

type CampaignValidator struct {
	// Check Campaign Container existence
	CampaignContainerLookupFunc ObjectLookupFunc

	// Check Activations associated with the Campaign
	CampaignActivationsLookupFunc LinkedObjectLookupFunc
}

func NewCampaignValidator

func NewCampaignValidator(campaignContainerLookupFunc ObjectLookupFunc, campaignActivationsLookupFunc LinkedObjectLookupFunc) CampaignValidator

func (*CampaignValidator) ConvertInterfaceToCampaign

func (c *CampaignValidator) ConvertInterfaceToCampaign(ref interface{}) model.CampaignState

func (*CampaignValidator) ValidateCreateOrUpdate

func (c *CampaignValidator) ValidateCreateOrUpdate(ctx context.Context, newRef interface{}, oldRef interface{}) []ErrorField

Validate Campaign creation or update 1. First stage is valid 2. Stages in the list are 3. campaign name and rootResource is valid. And rootResource is immutable 4. Update is not allow when there are running activations

func (*CampaignValidator) ValidateDelete

func (c *CampaignValidator) ValidateDelete(ctx context.Context, newRef interface{}) []ErrorField

Validate campaign deletion 1. No running activations

func (*CampaignValidator) ValidateFirstStage

func (c *CampaignValidator) ValidateFirstStage(campaign model.CampaignState) *ErrorField

Validate First stage of the campaign 1. If stages is empty, firstStage must be empty 2. If stages is not empty, firstStage must be one of the stages in the list

func (*CampaignValidator) ValidateRunningActivation

func (c *CampaignValidator) ValidateRunningActivation(ctx context.Context, campaign model.CampaignState) *ErrorField

Validate NO running activations CampaignActivationsLookupFunc will look up activations with label {"campaign" : c.ObjectMeta.Name}

func (*CampaignValidator) ValidateStages

func (c *CampaignValidator) ValidateStages(campaign model.CampaignState) *ErrorField

Validate stageSelector of stages should always be one of the stages in the stages list

type CatalogValidator

type CatalogValidator struct {
	// Check Catalog existence
	CatalogLookupFunc          ObjectLookupFunc
	CatalogContainerLookupFunc ObjectLookupFunc
	ChildCatalogLookupFunc     LinkedObjectLookupFunc
}

func NewCatalogValidator

func NewCatalogValidator(catalogLookupFunc ObjectLookupFunc, catalogContainerLookupFunc ObjectLookupFunc, childCatalogLookupFunc LinkedObjectLookupFunc) CatalogValidator

func (*CatalogValidator) ConvertInterfaceToCatalog

func (c *CatalogValidator) ConvertInterfaceToCatalog(ref interface{}) model.CatalogState

func (*CatalogValidator) ValidateChildCatalog

func (c *CatalogValidator) ValidateChildCatalog(ctx context.Context, catalog model.CatalogState) *ErrorField

Validate NO Child Catalog Use ChildCatalogLookupFunc to lookup the child catalogs with labels {"parentName": catalog.ObjectMeta.Name}

func (*CatalogValidator) ValidateCreateOrUpdate

func (c *CatalogValidator) ValidateCreateOrUpdate(ctx context.Context, newRef interface{}, oldRef interface{}) []ErrorField

Validate Catalog creation or update 1. Schema is valid 2. Parent catalog exists 3. Catalog name and rootResource is valid. And rootResource is immutable TODO: 4. Update won't form a cycle in the parent-child relationship

func (*CatalogValidator) ValidateDelete

func (c *CatalogValidator) ValidateDelete(ctx context.Context, catalog interface{}) []ErrorField

Validate Catalog deletion 1. Catalog has no child catalogs

func (*CatalogValidator) ValidateParentCatalog

func (c *CatalogValidator) ValidateParentCatalog(ctx context.Context, catalog model.CatalogState) *ErrorField

Validate Parent Catalog exists if provided Use CatalogLookupFunc to lookup the catalog with parentName

func (*CatalogValidator) ValidateSchema

func (c *CatalogValidator) ValidateSchema(ctx context.Context, new model.CatalogState) *ErrorField

Validate Schema is valid

type ErrorField

type ErrorField struct {
	FieldPath       string
	Value           interface{}
	DetailedMessage string
}

func ValidateObjectName

func ValidateObjectName(name string, rootResource string) *ErrorField

Validate the name of versioned objects

func ValidateRootResource

func ValidateRootResource(ctx context.Context, o model.ObjectMeta, rootResource string, lookupFunc ObjectLookupFunc) *ErrorField

Validate rootResource exists for versioned objects - solutions, campaigns and catalogs

type IValidator

type IValidator interface {
	ValidateCreateOrUpdate(ctx context.Context, newRef interface{}, oldRef interface{}) []ErrorField
	ValidateDelete(ctx context.Context, newRef interface{}) []ErrorField
}

type InstanceValidator

type InstanceValidator struct {
	UniqueNameInstanceLookupFunc ObjectLookupFunc
	SolutionLookupFunc           ObjectLookupFunc
	TargetLookupFunc             ObjectLookupFunc
}

func NewInstanceValidator

func NewInstanceValidator(uniqueNameInstanceLookupFunc ObjectLookupFunc, solutionLookupFunc ObjectLookupFunc, targetLookupFunc ObjectLookupFunc) InstanceValidator

func (*InstanceValidator) ConvertInterfaceToInstance

func (i *InstanceValidator) ConvertInterfaceToInstance(ref interface{}) model.InstanceState

func (*InstanceValidator) ValidateCreateOrUpdate

func (i *InstanceValidator) ValidateCreateOrUpdate(ctx context.Context, newRef interface{}, oldRef interface{}) []ErrorField

Validate Instance creation or update 1. DisplayName is unique 2. Solution exists 3. Target exists if provided by name rather than selector 4. Target is valid, i.e. either name or selector is provided

func (*InstanceValidator) ValidateDelete

func (i *InstanceValidator) ValidateDelete(ctx context.Context, new interface{}) []ErrorField

func (*InstanceValidator) ValidateSolutionExist

func (i *InstanceValidator) ValidateSolutionExist(ctx context.Context, c model.InstanceState) *ErrorField

Validate Solution exists for instance

func (*InstanceValidator) ValidateTargetExist

func (i *InstanceValidator) ValidateTargetExist(ctx context.Context, c model.InstanceState) *ErrorField

Validate Target exists for instance if target name is provided

func (*InstanceValidator) ValidateTargetValid

func (i *InstanceValidator) ValidateTargetValid(c model.InstanceState) *ErrorField

Validate Target is valid, i.e. either name or selector is provided

func (*InstanceValidator) ValidateUniqueName

func (i *InstanceValidator) ValidateUniqueName(ctx context.Context, c model.InstanceState) *ErrorField

Validate DisplayName is unique, i.e. No existing instance with the same DisplayName UniqueNameInstanceLookupFunc will lookup instances with labels {"displayName": c.Spec.DisplayName}

type LinkedObjectLookupFunc

type LinkedObjectLookupFunc func(ctx context.Context, objectName string, namespace string) (bool, error)

Prototype for linked objects lookup functions.

type ObjectLookupFunc

type ObjectLookupFunc func(ctx context.Context, objectName string, namespace string) (interface{}, error)

Prototype for object lookup functions. Return value indicates if the object exists or not.

type ResourceType

type ResourceType string
const (
	Target            ResourceType = "target"
	Device            ResourceType = "device"
	Solution          ResourceType = "solution"
	Instance          ResourceType = "instance"
	Campaign          ResourceType = "campaign"
	Activation        ResourceType = "activation"
	Catalog           ResourceType = "catalog"
	SolutionContainer ResourceType = "solutioncontainer"
	CampaignContainer ResourceType = "campaigncontainer"
	CatalogContainer  ResourceType = "catalogcontainer"
)

type SolutionValidator

type SolutionValidator struct {
	// Check Instances associated with the Solution
	SolutionInstanceLookupFunc   LinkedObjectLookupFunc
	SolutionContainerLookupFunc  ObjectLookupFunc
	UniqueNameSolutionLookupFunc ObjectLookupFunc
}

func NewSolutionValidator

func NewSolutionValidator(solutionInstanceLookupFunc LinkedObjectLookupFunc, solutionContainerLookupFunc ObjectLookupFunc, uniqueNameSolutionLookupFunc ObjectLookupFunc) SolutionValidator

func (*SolutionValidator) ConvertInterfaceToSolution

func (s *SolutionValidator) ConvertInterfaceToSolution(ref interface{}) model.SolutionState

func (*SolutionValidator) ValidateCreateOrUpdate

func (s *SolutionValidator) ValidateCreateOrUpdate(ctx context.Context, newRef interface{}, oldRef interface{}) []ErrorField

Validate Solution creation or update 1. DisplayName is unique 2. name and rootResource is valid. And rootResource is immutable for update

func (*SolutionValidator) ValidateDelete

func (s *SolutionValidator) ValidateDelete(ctx context.Context, newRef interface{}) []ErrorField

Validate Solution deletion 1. No associated instances

func (*SolutionValidator) ValidateNoInstanceForSolution

func (s *SolutionValidator) ValidateNoInstanceForSolution(ctx context.Context, solution model.SolutionState) *ErrorField

Validate no instance associated with the solution SolutionInstanceLookupFunc will lookup instances with labels {"solution": s.ObjectMeta.Name}

func (*SolutionValidator) ValidateSolutionUniqueName

func (s *SolutionValidator) ValidateSolutionUniqueName(ctx context.Context, solution model.SolutionState) *ErrorField

Validate DisplayName is unique, i.e. No existing solution with the same DisplayName UniqueNameSolutionLookupFunc will lookup solutions with labels {"displayName": c.Spec.DisplayName}

type TargetValidator

type TargetValidator struct {
	// Check Instance associated with the Solution
	TargetInstanceLookupFunc   LinkedObjectLookupFunc
	UniqueNameTargetLookupFunc ObjectLookupFunc
}

func NewTargetValidator

func NewTargetValidator(targetInstanceLookupFunc LinkedObjectLookupFunc, uniqueNameTargetLookupFunc ObjectLookupFunc) TargetValidator

func (*TargetValidator) ConvertInterfaceToTarget

func (t *TargetValidator) ConvertInterfaceToTarget(ref interface{}) model.TargetState

func (*TargetValidator) ValidateCreateOrUpdate

func (t *TargetValidator) ValidateCreateOrUpdate(ctx context.Context, newRef interface{}, oldRef interface{}) []ErrorField

Validate Target creation or update 1. DisplayName is unique

func (*TargetValidator) ValidateDelete

func (t *TargetValidator) ValidateDelete(ctx context.Context, newRef interface{}) []ErrorField

Validate Target deletion 1. No associated instances

func (*TargetValidator) ValidateNoInstanceForTarget

func (t *TargetValidator) ValidateNoInstanceForTarget(ctx context.Context, target model.TargetState) *ErrorField

Validate No associated instances for the target TargetInstanceLookupFunc will lookup instances with labels {"target": t.ObjectMeta.Name}

func (*TargetValidator) ValidateTargetUniqueName

func (t *TargetValidator) ValidateTargetUniqueName(ctx context.Context, target model.TargetState) *ErrorField

Validate DisplayName is unique, i.e. No existing target with the same DisplayName UniqueNameTargetLookupFunc will lookup targets with labels {"displayName": t.Spec.DisplayName}

Jump to

Keyboard shortcuts

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