Skip to content

Commit 430b1de

Browse files
committed
Test library and type names
1 parent e085f38 commit 430b1de

File tree

8 files changed

+20
-10
lines changed

8 files changed

+20
-10
lines changed

staging/src/k8s.io/apiserver/pkg/cel/library/authz.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ var authzLib = &authz{}
232232
type authz struct{}
233233

234234
func (*authz) LibraryName() string {
235-
return "k8s.authz"
235+
return "kubernetes.authz"
236236
}
237237

238238
func (*authz) Types() []*cel.Type {
@@ -337,7 +337,7 @@ var authzSelectorsLib = &authzSelectors{}
337337
type authzSelectors struct{}
338338

339339
func (*authzSelectors) LibraryName() string {
340-
return "k8s.authzSelectors"
340+
return "kubernetes.authzSelectors"
341341
}
342342

343343
func (*authzSelectors) Types() []*cel.Type {

staging/src/k8s.io/apiserver/pkg/cel/library/format.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ var formatLib = &format{}
9191
type format struct{}
9292

9393
func (*format) LibraryName() string {
94-
return "format"
94+
return "kubernetes.format"
9595
}
9696

9797
func (*format) Types() []*cel.Type {

staging/src/k8s.io/apiserver/pkg/cel/library/library_compatibility_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/google/cel-go/cel"
2121
"github.com/google/cel-go/common/decls"
2222
"github.com/google/cel-go/common/types"
23+
"strings"
2324
"testing"
2425

2526
"k8s.io/apimachinery/pkg/util/sets"
@@ -28,6 +29,9 @@ import (
2829
func TestLibraryCompatibility(t *testing.T) {
2930
functionNames := sets.New[string]()
3031
for _, lib := range KnownLibraries() {
32+
if !strings.HasPrefix(lib.LibraryName(), "kubernetes.") {
33+
t.Errorf("Expected all kubernetes CEL libraries to have a name package with a 'kubernetes.' prefix but got %v", lib.LibraryName())
34+
}
3135
for name := range lib.declarations() {
3236
functionNames[name] = struct{}{}
3337
}
@@ -93,12 +97,18 @@ func TestTypeRegistration(t *testing.T) {
9397
}
9498
}
9599
}
96-
for _, t := range lib.Types() {
97-
registeredTypes.Insert(t)
100+
for _, lb := range lib.Types() {
101+
registeredTypes.Insert(lb)
102+
if !strings.HasPrefix(lb.TypeName(), "kubernetes.") && !legacyTypeNames.Has(lb.TypeName()) {
103+
t.Errorf("Expected all types in kubernetes CEL libraries to have a type name packaged with a 'kubernetes.' prefix but got %v", lb.TypeName())
104+
}
98105
}
99106
unregistered := usedTypes.Difference(registeredTypes)
100107
if len(unregistered) != 0 {
101108
t.Errorf("Expected types to be registered with the %s library Type() functions, but they were not: %v", lib.LibraryName(), unregistered)
102109
}
103110
}
104111
}
112+
113+
// TODO: Consider renaming these to "kubernetes.net.IP" and "kubernetes.net.CIDR" if we decide not to promote them to cel-go
114+
var legacyTypeNames = sets.New[string]("net.IP", "net.CIDR")

staging/src/k8s.io/apiserver/pkg/cel/library/lists.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ var listsLib = &lists{}
9696
type lists struct{}
9797

9898
func (*lists) LibraryName() string {
99-
return "k8s.lists"
99+
return "kubernetes.lists"
100100
}
101101

102102
func (*lists) Types() []*cel.Type {

staging/src/k8s.io/apiserver/pkg/cel/library/quantity.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ var quantityLib = &quantity{}
143143
type quantity struct{}
144144

145145
func (*quantity) LibraryName() string {
146-
return "k8s.quantity"
146+
return "kubernetes.quantity"
147147
}
148148

149149
func (*quantity) Types() []*cel.Type {

staging/src/k8s.io/apiserver/pkg/cel/library/regex.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var regexLib = &regex{}
5252
type regex struct{}
5353

5454
func (*regex) LibraryName() string {
55-
return "k8s.regex"
55+
return "kubernetes.regex"
5656
}
5757

5858
func (*regex) Types() []*cel.Type {

staging/src/k8s.io/apiserver/pkg/cel/library/test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type testLib struct {
3838
}
3939

4040
func (*testLib) LibraryName() string {
41-
return "k8s.test"
41+
return "kubernetes.test"
4242
}
4343

4444
type TestOption func(*testLib) *testLib

staging/src/k8s.io/apiserver/pkg/cel/library/urls.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ var urlsLib = &urls{}
113113
type urls struct{}
114114

115115
func (*urls) LibraryName() string {
116-
return "k8s.urls"
116+
return "kubernetes.urls"
117117
}
118118

119119
func (*urls) Types() []*cel.Type {

0 commit comments

Comments
 (0)