Skip to content

Commit 81b9a45

Browse files
nak3estroz
authored andcommitted
Use same validation with k8s's for API resource group (#953)
* Use same validation with k8s's for API resource group * Update Gopkg.lock
1 parent 85303a1 commit 81b9a45

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

Gopkg.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/scaffold/resource.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
"strings"
2424

2525
"github.com/markbates/inflect"
26+
27+
"k8s.io/apimachinery/pkg/util/validation"
2628
)
2729

2830
var (
@@ -31,8 +33,6 @@ var (
3133
ResourceVersionRegexp = regexp.MustCompile("^v[1-9][0-9]*((alpha|beta)[1-9][0-9]*)?$")
3234
// ResourceKindRegexp matches Kubernetes API Kind's.
3335
ResourceKindRegexp = regexp.MustCompile("^[A-Z]{1}[a-zA-Z0-9]+$")
34-
// ResourceGroupRegexp matches Kubernetes API Group's.
35-
ResourceGroupRegexp = regexp.MustCompile("^[a-z0-9]+$")
3636
)
3737

3838
// Resource contains the information required to scaffold files for a resource.
@@ -127,8 +127,8 @@ func (r *Resource) checkAndSetGroups() error {
127127
r.FullGroup = fg[0]
128128
r.Group = g[0]
129129

130-
if !ResourceGroupRegexp.MatchString(r.Group) {
131-
return errors.New("group should consist of lowercase alphabetical characters")
130+
if err := validation.IsDNS1123Subdomain(r.Group); err != nil {
131+
return fmt.Errorf("group name is invalid: %v", err)
132132
}
133133
return nil
134134
}

0 commit comments

Comments
 (0)