mirror of
https://github.com/redhat-developer/odo.git
synced 2025-10-19 03:06:19 +03:00
56 lines
2.2 KiB
Go
Generated
56 lines
2.2 KiB
Go
Generated
//
|
|
//
|
|
// Copyright Red Hat
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package validation
|
|
|
|
import "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
|
|
|
|
// validateEndpoints checks if
|
|
// 1. all the endpoint names are unique across components
|
|
// 2. endpoint port are unique across component containers
|
|
// ie; two component containers cannot have the same target port but two endpoints
|
|
// in a single component container can have the same target port
|
|
func validateEndpoints(endpoints []v1alpha2.Endpoint, processedEndPointPort map[int]bool, processedEndPointName map[string]bool) (errList []error) {
|
|
currentComponentEndPointPort := make(map[int]bool)
|
|
|
|
errList = validateDuplicatedName(endpoints, processedEndPointName, currentComponentEndPointPort)
|
|
portErrorList := validateDuplicatedPort(processedEndPointPort, currentComponentEndPointPort)
|
|
errList = append(errList, portErrorList...)
|
|
|
|
return errList
|
|
}
|
|
|
|
func validateDuplicatedName(endpoints []v1alpha2.Endpoint, processedEndPointName map[string]bool, currentComponentEndPointPort map[int]bool) (errList []error) {
|
|
for _, endPoint := range endpoints {
|
|
if _, ok := processedEndPointName[endPoint.Name]; ok {
|
|
errList = append(errList, &InvalidEndpointError{name: endPoint.Name})
|
|
}
|
|
processedEndPointName[endPoint.Name] = true
|
|
currentComponentEndPointPort[endPoint.TargetPort] = true
|
|
}
|
|
return errList
|
|
}
|
|
|
|
func validateDuplicatedPort(processedEndPointPort map[int]bool, currentComponentEndPointPort map[int]bool) (errList []error) {
|
|
for targetPort := range currentComponentEndPointPort {
|
|
if _, ok := processedEndPointPort[targetPort]; ok {
|
|
errList = append(errList, &InvalidEndpointError{port: targetPort})
|
|
}
|
|
processedEndPointPort[targetPort] = true
|
|
}
|
|
return errList
|
|
}
|