MCPcopy Create free account
hub / github.com/devfile/api / ValidateComponents

Function ValidateComponents

pkg/validation/components.go:42–226  ·  view source on GitHub ↗

ValidateComponents validates that the components 1. makes sure the container components reference a valid volume component if it uses volume mounts 2. makes sure the volume components are unique 3. checks the URI specified in openshift components and kubernetes components are with valid format 4. ma

(components []v1alpha2.Component)

Source from the content-addressed store, hash-verified

40// 4. makes sure the component name is unique
41// 5. makes sure the image dockerfile component git src has at most one remote
42func ValidateComponents(components []v1alpha2.Component) (returnedErr error) {
43
44 processedVolumes := make(map[string]bool)
45 processedVolumeMounts := make(map[string][]string)
46 processedEndPointName := make(map[string]bool)
47 processedEndPointPort := make(map[int]bool)
48 processedComponentWithVolumeMounts := make(map[string]v1alpha2.Component)
49 processedDeploymentAnnotations := make(map[string]string)
50 processedServiceAnnotations := make(map[string]string)
51 deploymentAnnotationDuplication := make(map[string]bool)
52 serviceAnnotationDuplication := make(map[string]bool)
53
54 err := v1alpha2.CheckDuplicateKeys(components)
55 if err != nil {
56 returnedErr = multierror.Append(returnedErr, err)
57 }
58
59 for _, component := range components {
60 switch {
61 case component.Container != nil:
62 // Process all the volume mounts in container components to validate them later
63 for _, volumeMount := range component.Container.VolumeMounts {
64 processedVolumeMounts[component.Name] = append(processedVolumeMounts[component.Name], volumeMount.Name)
65 processedComponentWithVolumeMounts[component.Name] = component
66
67 }
68
69 // Check if any containers are customizing the reserved PROJECT_SOURCE or PROJECTS_ROOT env
70 for _, env := range component.Container.Env {
71 if env.Name == EnvProjectsSrc {
72 reservedEnvErr := &ReservedEnvError{envName: EnvProjectsSrc, componentName: component.Name}
73 returnedErr = multierror.Append(returnedErr, reservedEnvErr)
74 } else if env.Name == EnvProjectsRoot {
75 reservedEnvErr := &ReservedEnvError{envName: EnvProjectsRoot, componentName: component.Name}
76 returnedErr = multierror.Append(returnedErr, reservedEnvErr)
77 }
78 }
79 var memoryLimit, cpuLimit, memoryRequest, cpuRequest resource.Quantity
80 if component.Container.MemoryLimit != "" {
81 memoryLimit, err = resource.ParseQuantity(component.Container.MemoryLimit)
82 if err != nil {
83 parseQuantityErr := &ParsingResourceRequirementError{resource: MemoryLimit, cmpName: component.Name, errMsg: err.Error()}
84 returnedErr = multierror.Append(returnedErr, parseQuantityErr)
85 }
86 }
87 if component.Container.CpuLimit != "" {
88 cpuLimit, err = resource.ParseQuantity(component.Container.CpuLimit)
89 if err != nil {
90 parseQuantityErr := &ParsingResourceRequirementError{resource: CpuLimit, cmpName: component.Name, errMsg: err.Error()}
91 returnedErr = multierror.Append(returnedErr, parseQuantityErr)
92 }
93 }
94 if component.Container.MemoryRequest != "" {
95 memoryRequest, err = resource.ParseQuantity(component.Container.MemoryRequest)
96 if err != nil {
97 parseQuantityErr := &ParsingResourceRequirementError{resource: MemoryRequest, cmpName: component.Name, errMsg: err.Error()}
98 returnedErr = multierror.Append(returnedErr, parseQuantityErr)
99 } else if !memoryLimit.IsZero() && memoryRequest.Cmp(memoryLimit) > 0 {

Callers 1

TestValidateComponentsFunction · 0.85

Calls 7

CheckDuplicateKeysFunction · 0.92
validateEndpointsFunction · 0.85
ValidateURIFunction · 0.85
validateDuplicatedNameFunction · 0.85
ErrorMethod · 0.45

Tested by 1

TestValidateComponentsFunction · 0.68