Skip to content

Commit 715461b

Browse files
author
Per Goncalves da Silva
committed
Add resource name validation
Signed-off-by: Per Goncalves da Silva <[email protected]>
1 parent c8ddc53 commit 715461b

File tree

1 file changed

+20
-0
lines changed
  • internal/operator-controller/rukpak/render/validators

1 file changed

+20
-0
lines changed

internal/operator-controller/rukpak/render/validators/validator.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"cmp"
55
"errors"
66
"fmt"
7+
"k8s.io/apimachinery/pkg/util/validation"
78
"maps"
89
"slices"
910
"strings"
@@ -49,6 +50,25 @@ func CheckDeploymentSpecUniqueness(rv1 *render.RegistryV1) []error {
4950
return errs
5051
}
5152

53+
// CheckDeploymentNameIsDNS1123SubDomain checks each deployment strategy spec name complies with the Kubernetes
54+
// resource naming conversions
55+
func CheckDeploymentNameIsDNS1123SubDomain(rv1 *render.RegistryV1) []error {
56+
deploymentNameErrMap := map[string][]string{}
57+
for _, dep := range rv1.CSV.Spec.InstallStrategy.StrategySpec.DeploymentSpecs {
58+
errs := validation.IsDNS1123Subdomain(dep.Name)
59+
if len(errs) > 0 {
60+
slices.Sort(errs)
61+
deploymentNameErrMap[dep.Name] = errs
62+
}
63+
}
64+
65+
var errs []error
66+
for _, dep := range slices.Sorted(maps.Keys(deploymentNameErrMap)) {
67+
errs = append(errs, fmt.Errorf("invalid cluster service version strategy deployment name '%s': %s", dep, strings.Join(deploymentNameErrMap[dep], ", ")))
68+
}
69+
return errs
70+
}
71+
5272
// CheckOwnedCRDExistence checks bundle owned custom resource definitions declared in the csv exist in the bundle
5373
func CheckOwnedCRDExistence(rv1 *render.RegistryV1) []error {
5474
crdsNames := sets.Set[string]{}

0 commit comments

Comments
 (0)