validation

package
v0.20.0-alpha1 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2016 License: Apache-2.0, Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package validation has functions for validating the correctness of api objects and explaining what is wrong with them when they aren't valid.

Index

Constants

View Source
const SecretKeyFmt string = "\\.?" + validation.DNS1123LabelFmt + "(\\." + validation.DNS1123LabelFmt + ")*"

Variables

View Source
var DNS1123LabelErrorMsg string = fmt.Sprintf(`must be a DNS label (at most %d characters, matching regex %s): e.g. "my-name"`, validation.DNS1123LabelMaxLength, validation.DNS1123LabelFmt)
View Source
var DNS952LabelErrorMsg string = fmt.Sprintf(`must be a DNS 952 label (at most %d characters, matching regex %s): e.g. "my-name"`, validation.DNS952LabelMaxLength, validation.DNS952LabelFmt)
View Source
var DNSSubdomainErrorMsg string = fmt.Sprintf(`must be a DNS subdomain (at most %d characters, matching regex %s): e.g. "example.com"`, validation.DNS1123SubdomainMaxLength, validation.DNS1123SubdomainFmt)
View Source
var NameMayNotBe = []string{".", ".."}

NameMayNotBe specifies strings that cannot be used as names specified as path segments (like the REST API or etcd store)

View Source
var NameMayNotContain = []string{"/", "%"}

NameMayNotContain specifies substrings that cannot be used in names specified as path segments (like the REST API or etcd store)

View Source
var PortNameErrorMsg string = fmt.Sprintf(`must be an IANA_SVC_NAME (at most 15 characters, matching regex %s, it must contain at least one letter [a-z], and hyphens cannot be adjacent to other hyphens): e.g. "http"`, validation.IdentifierNoHyphensBeginEndFmt)
View Source
var PortRangeErrorMsg string = IntervalErrorMsg(0, 65536)
View Source
var RepairMalformedUpdates bool = true

TODO: delete this global variable when we enable the validation of common fields by default.

Functions

func AccumulateUniqueHostPorts

func AccumulateUniqueHostPorts(containers []api.Container, accumulator *sets.String) validation.ErrorList

AccumulateUniqueHostPorts extracts each HostPort of each Container, accumulating the results and returning an error if any ports conflict.

func IntervalErrorMsg

func IntervalErrorMsg(lo, hi int) string

func IsSecretKey

func IsSecretKey(value string) bool

IsSecretKey tests for a string that conforms to the definition of a subdomain in DNS (RFC 1123), except that a leading dot is allowed

func IsValidPathSegmentName added in v1.0.0

func IsValidPathSegmentName(name string) (bool, string)

IsValidPathSegmentName validates the name can be safely encoded as a path segment

func IsValidPathSegmentPrefix added in v1.0.0

func IsValidPathSegmentPrefix(name string) (bool, string)

IsValidPathSegmentPrefix validates the name can be used as a prefix for a name which will be encoded as a path segment It does not check for exact matches with disallowed names, since an arbitrary suffix might make the name valid

func NameIsDNS952Label added in v0.18.4

func NameIsDNS952Label(name string, prefix bool) (bool, string)

NameIsDNS952Label is a ValidateNameFunc for names that must be a DNS 952 label.

func NameIsDNSLabel added in v0.18.4

func NameIsDNSLabel(name string, prefix bool) (bool, string)

NameIsDNSLabel is a ValidateNameFunc for names that must be a DNS 1123 label.

func NameIsDNSSubdomain added in v0.18.4

func NameIsDNSSubdomain(name string, prefix bool) (bool, string)

NameIsDNSSubdomain is a ValidateNameFunc for names that must be a DNS subdomain.

func NewInvalidTypeError

func NewInvalidTypeError(expected reflect.Kind, observed reflect.Kind, fieldName string) error

func ValidateAnnotations

func ValidateAnnotations(annotations map[string]string, field string) validation.ErrorList

ValidateAnnotations validates that a set of annotations are correctly defined.

func ValidateEndpoints

func ValidateEndpoints(endpoints *api.Endpoints) validation.ErrorList

ValidateEndpoints tests if required fields are set.

func ValidateEndpointsName

func ValidateEndpointsName(name string, prefix bool) (bool, string)

ValidateEndpointsName can be used to check whether the given endpoints name is valid. Prefix indicates this name will be used as part of generation, in which case trailing dashes are allowed.

func ValidateEndpointsUpdate

func ValidateEndpointsUpdate(newEndpoints, oldEndpoints *api.Endpoints) validation.ErrorList

ValidateEndpointsUpdate tests to make sure an endpoints update can be applied.

func ValidateEvent

func ValidateEvent(event *api.Event) validation.ErrorList

ValidateEvent makes sure that the event makes sense.

func ValidateImmutableField added in v1.0.0

func ValidateImmutableField(new, old interface{}, fieldName string) validation.ErrorList

func ValidateLabelName added in v0.18.4

func ValidateLabelName(labelName, fieldName string) validation.ErrorList

func ValidateLabels

func ValidateLabels(labels map[string]string, field string) validation.ErrorList

ValidateLabels validates that a set of labels are correctly defined.

func ValidateLimitRange

func ValidateLimitRange(limitRange *api.LimitRange) validation.ErrorList

ValidateLimitRange tests if required fields in the LimitRange are set.

func ValidateLimitRangeName

func ValidateLimitRangeName(name string, prefix bool) (bool, string)

ValidateLimitRangeName can be used to check whether the given limit range name is valid. Prefix indicates this name will be used as part of generation, in which case trailing dashes are allowed.

func ValidateLoadBalancerStatus added in v0.19.0

func ValidateLoadBalancerStatus(status *api.LoadBalancerStatus) validation.ErrorList

ValidateLoadBalancerStatus validates required fields on a LoadBalancerStatus

func ValidateNamespace

func ValidateNamespace(namespace *api.Namespace) validation.ErrorList

ValidateNamespace tests if required fields are set.

func ValidateNamespaceFinalizeUpdate

func ValidateNamespaceFinalizeUpdate(newNamespace, oldNamespace *api.Namespace) validation.ErrorList

ValidateNamespaceFinalizeUpdate tests to see if the update is legal for an end user to make. newNamespace is updated with fields that cannot be changed.

func ValidateNamespaceName

func ValidateNamespaceName(name string, prefix bool) (bool, string)

ValidateNamespaceName can be used to check whether the given namespace name is valid. Prefix indicates this name will be used as part of generation, in which case trailing dashes are allowed.

func ValidateNamespaceStatusUpdate

func ValidateNamespaceStatusUpdate(newNamespace, oldNamespace *api.Namespace) validation.ErrorList

ValidateNamespaceStatusUpdate tests to see if the update is legal for an end user to make. newNamespace is updated with fields that cannot be changed.

func ValidateNamespaceUpdate

func ValidateNamespaceUpdate(newNamespace *api.Namespace, oldNamespace *api.Namespace) validation.ErrorList

ValidateNamespaceUpdate tests to make sure a namespace update can be applied. newNamespace is updated with fields that cannot be changed

func ValidateNode

func ValidateNode(node *api.Node) validation.ErrorList

ValidateNode tests if required fields in the node are set.

func ValidateNodeName

func ValidateNodeName(name string, prefix bool) (bool, string)

ValidateNodeName can be used to check whether the given node name is valid. Prefix indicates this name will be used as part of generation, in which case trailing dashes are allowed.

func ValidateNodeUpdate

func ValidateNodeUpdate(node, oldNode *api.Node) validation.ErrorList

ValidateNodeUpdate tests to make sure a node update can be applied. Modifies oldNode.

func ValidateNonEmptySelector added in v0.18.4

func ValidateNonEmptySelector(selectorMap map[string]string, fieldName string) validation.ErrorList

Validates that the given selector is non-empty.

func ValidateObjectMeta

func ValidateObjectMeta(meta *api.ObjectMeta, requiresNamespace bool, nameFn ValidateNameFunc) validation.ErrorList

ValidateObjectMeta validates an object's metadata on creation. It expects that name generation has already been performed. It doesn't return an error for rootscoped resources with namespace, because namespace should already be cleared before. TODO: Remove calls to this method scattered in validations of specific resources, e.g., ValidatePodUpdate.

func ValidateObjectMetaUpdate

func ValidateObjectMetaUpdate(new, old *api.ObjectMeta) validation.ErrorList

ValidateObjectMetaUpdate validates an object's metadata when updated

func ValidatePathSegmentName added in v0.19.0

func ValidatePathSegmentName(name string, prefix bool) (bool, string)

ValidatePathSegmentName validates the name can be safely encoded as a path segment

func ValidatePersistentVolume

func ValidatePersistentVolume(pv *api.PersistentVolume) validation.ErrorList

func ValidatePersistentVolumeClaim

func ValidatePersistentVolumeClaim(pvc *api.PersistentVolumeClaim) validation.ErrorList

func ValidatePersistentVolumeClaimStatusUpdate

func ValidatePersistentVolumeClaimStatusUpdate(newPvc, oldPvc *api.PersistentVolumeClaim) validation.ErrorList

func ValidatePersistentVolumeClaimUpdate

func ValidatePersistentVolumeClaimUpdate(newPvc, oldPvc *api.PersistentVolumeClaim) validation.ErrorList

func ValidatePersistentVolumeName

func ValidatePersistentVolumeName(name string, prefix bool) (bool, string)

func ValidatePersistentVolumeStatusUpdate

func ValidatePersistentVolumeStatusUpdate(newPv, oldPv *api.PersistentVolume) validation.ErrorList

ValidatePersistentVolumeStatusUpdate tests to see if the status update is legal for an end user to make. newPv is updated with fields that cannot be changed.

func ValidatePersistentVolumeUpdate

func ValidatePersistentVolumeUpdate(newPv, oldPv *api.PersistentVolume) validation.ErrorList

ValidatePersistentVolumeUpdate tests to see if the update is legal for an end user to make. newPv is updated with fields that cannot be changed.

func ValidatePod

func ValidatePod(pod *api.Pod) validation.ErrorList

ValidatePod tests if required fields in the pod are set.

func ValidatePodLogOptions added in v0.18.4

func ValidatePodLogOptions(opts *api.PodLogOptions) validation.ErrorList

func ValidatePodName

func ValidatePodName(name string, prefix bool) (bool, string)

ValidatePodName can be used to check whether the given pod name is valid. Prefix indicates this name will be used as part of generation, in which case trailing dashes are allowed.

func ValidatePodSecurityContext added in v1.0.0

func ValidatePodSecurityContext(securityContext *api.PodSecurityContext, spec *api.PodSpec) validation.ErrorList

ValidatePodSecurityContext test that the specified PodSecurityContext has valid data.

func ValidatePodSpec

func ValidatePodSpec(spec *api.PodSpec) validation.ErrorList

ValidatePodSpec tests that the specified PodSpec has valid data. This includes checking formatting and uniqueness. It also canonicalizes the structure by setting default values and implementing any backwards-compatibility tricks.

func ValidatePodStatusUpdate

func ValidatePodStatusUpdate(newPod, oldPod *api.Pod) validation.ErrorList

ValidatePodStatusUpdate tests to see if the update is legal for an end user to make. newPod is updated with fields that cannot be changed.

func ValidatePodTemplate

func ValidatePodTemplate(pod *api.PodTemplate) validation.ErrorList

ValidatePodTemplate tests if required fields in the pod template are set.

func ValidatePodTemplateSpec

func ValidatePodTemplateSpec(spec *api.PodTemplateSpec) validation.ErrorList

ValidatePodTemplateSpec validates the spec of a pod template

func ValidatePodTemplateSpecForRC added in v0.18.4

func ValidatePodTemplateSpecForRC(template *api.PodTemplateSpec, selectorMap map[string]string, replicas int, fieldName string) validation.ErrorList

Validates the given template and ensures that it is in accordance with the desrired selector and replicas.

func ValidatePodTemplateUpdate

func ValidatePodTemplateUpdate(newPod, oldPod *api.PodTemplate) validation.ErrorList

ValidatePodTemplateUpdate tests to see if the update is legal for an end user to make. newPod is updated with fields that cannot be changed.

func ValidatePodUpdate

func ValidatePodUpdate(newPod, oldPod *api.Pod) validation.ErrorList

ValidatePodUpdate tests to see if the update is legal for an end user to make. newPod is updated with fields that cannot be changed.

func ValidatePositiveField added in v0.18.4

func ValidatePositiveField(value int64, fieldName string) validation.ErrorList

Validates that given value is not negative.

func ValidatePositiveQuantity added in v0.18.4

func ValidatePositiveQuantity(value resource.Quantity, fieldName string) validation.ErrorList

Validates that a Quantity is not negative

func ValidateReadOnlyPersistentDisks

func ValidateReadOnlyPersistentDisks(volumes []api.Volume) validation.ErrorList

func ValidateReplicationController

func ValidateReplicationController(controller *api.ReplicationController) validation.ErrorList

ValidateReplicationController tests if required fields in the replication controller are set.

func ValidateReplicationControllerName

func ValidateReplicationControllerName(name string, prefix bool) (bool, string)

ValidateReplicationControllerName can be used to check whether the given replication controller name is valid. Prefix indicates this name will be used as part of generation, in which case trailing dashes are allowed.

func ValidateReplicationControllerSpec

func ValidateReplicationControllerSpec(spec *api.ReplicationControllerSpec) validation.ErrorList

ValidateReplicationControllerSpec tests if required fields in the replication controller spec are set.

func ValidateReplicationControllerStatusUpdate added in v0.19.0

func ValidateReplicationControllerStatusUpdate(controller, oldController *api.ReplicationController) validation.ErrorList

ValidateReplicationControllerStatusUpdate tests if required fields in the replication controller are set.

func ValidateReplicationControllerUpdate

func ValidateReplicationControllerUpdate(controller, oldController *api.ReplicationController) validation.ErrorList

ValidateReplicationControllerUpdate tests if required fields in the replication controller are set.

func ValidateResourceQuota

func ValidateResourceQuota(resourceQuota *api.ResourceQuota) validation.ErrorList

ValidateResourceQuota tests if required fields in the ResourceQuota are set.

func ValidateResourceQuotaName

func ValidateResourceQuotaName(name string, prefix bool) (bool, string)

ValidateResourceQuotaName can be used to check whether the given resource quota name is valid. Prefix indicates this name will be used as part of generation, in which case trailing dashes are allowed.

func ValidateResourceQuotaStatusUpdate

func ValidateResourceQuotaStatusUpdate(newResourceQuota, oldResourceQuota *api.ResourceQuota) validation.ErrorList

ValidateResourceQuotaStatusUpdate tests to see if the status update is legal for an end user to make. newResourceQuota is updated with fields that cannot be changed.

func ValidateResourceQuotaUpdate

func ValidateResourceQuotaUpdate(newResourceQuota, oldResourceQuota *api.ResourceQuota) validation.ErrorList

ValidateResourceQuotaUpdate tests to see if the update is legal for an end user to make. newResourceQuota is updated with fields that cannot be changed.

func ValidateResourceRequirements

func ValidateResourceRequirements(requirements *api.ResourceRequirements) validation.ErrorList

Validates resource requirement spec.

func ValidateSecret

func ValidateSecret(secret *api.Secret) validation.ErrorList

ValidateSecret tests if required fields in the Secret are set.

func ValidateSecretName

func ValidateSecretName(name string, prefix bool) (bool, string)

ValidateSecretName can be used to check whether the given secret name is valid. Prefix indicates this name will be used as part of generation, in which case trailing dashes are allowed.

func ValidateSecretUpdate

func ValidateSecretUpdate(newSecret, oldSecret *api.Secret) validation.ErrorList

ValidateSecretUpdate tests if required fields in the Secret are set.

func ValidateSecurityContext

func ValidateSecurityContext(sc *api.SecurityContext) validation.ErrorList

ValidateSecurityContext ensure the security context contains valid settings

func ValidateService

func ValidateService(service *api.Service) validation.ErrorList

ValidateService tests if required fields in the service are set.

func ValidateServiceAccount

func ValidateServiceAccount(serviceAccount *api.ServiceAccount) validation.ErrorList

ValidateServiceAccount tests if required fields in the ServiceAccount are set.

func ValidateServiceAccountName

func ValidateServiceAccountName(name string, prefix bool) (bool, string)

ValidateServiceAccountName can be used to check whether the given service account name is valid. Prefix indicates this name will be used as part of generation, in which case trailing dashes are allowed.

func ValidateServiceAccountUpdate

func ValidateServiceAccountUpdate(newServiceAccount, oldServiceAccount *api.ServiceAccount) validation.ErrorList

ValidateServiceAccountUpdate tests if required fields in the ServiceAccount are set.

func ValidateServiceName

func ValidateServiceName(name string, prefix bool) (bool, string)

ValidateServiceName can be used to check whether the given service name is valid. Prefix indicates this name will be used as part of generation, in which case trailing dashes are allowed.

func ValidateServiceUpdate

func ValidateServiceUpdate(service, oldService *api.Service) validation.ErrorList

ValidateServiceUpdate tests if required fields in the service are set during an update

Types

type InvalidTypeError

type InvalidTypeError struct {
	ExpectedKind reflect.Kind
	ObservedKind reflect.Kind
	FieldName    string
}

func (*InvalidTypeError) Error

func (i *InvalidTypeError) Error() string

type NullSchema

type NullSchema struct{}

func (NullSchema) ValidateBytes

func (NullSchema) ValidateBytes(data []byte) error

type Schema

type Schema interface {
	ValidateBytes(data []byte) error
}

Schema is an interface that knows how to validate an API object serialized to a byte array.

func NewSwaggerSchemaFromBytes

func NewSwaggerSchemaFromBytes(data []byte) (Schema, error)

type SwaggerSchema

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

func (*SwaggerSchema) ValidateBytes

func (s *SwaggerSchema) ValidateBytes(data []byte) error

func (*SwaggerSchema) ValidateObject

func (s *SwaggerSchema) ValidateObject(obj interface{}, fieldName, typeName string) []error

type ValidateNameFunc

type ValidateNameFunc func(name string, prefix bool) (bool, string)

ValidateNameFunc validates that the provided name is valid for a given resource type. Not all resources have the same validation rules for names. Prefix is true if the name will have a value appended to it.

Jump to

Keyboard shortcuts

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