Skip to content

Commit 42b7cfe

Browse files
authored
Merge pull request kubernetes#128274 from eddycharly/fix-cel-type-provider
fix: cel type provider should return a type type
2 parents a339a36 + ea1bd95 commit 42b7cfe

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

staging/src/k8s.io/apiserver/pkg/cel/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ func (rt *DeclTypeProvider) FindStructType(typeName string) (*types.Type, bool)
429429
declType, found := rt.findDeclType(typeName)
430430
if found {
431431
expT := declType.CelType()
432-
return expT, found
432+
return types.NewTypeTypeWithParam(expT), found
433433
}
434434
return rt.typeProvider.FindStructType(typeName)
435435
}

staging/src/k8s.io/apiserver/pkg/cel/types_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ package cel
1818

1919
import (
2020
"testing"
21+
22+
"github.com/google/cel-go/common/types"
23+
"github.com/stretchr/testify/require"
2124
)
2225

2326
func TestTypes_ListType(t *testing.T) {
@@ -77,3 +80,16 @@ func testValue(t *testing.T, id int64, val interface{}) *DynValue {
7780
}
7881
return dv
7982
}
83+
84+
func TestDeclTypeProvider_FindStructType(t *testing.T) {
85+
obj := NewObjectType("foo", map[string]*DeclField{
86+
"bar": NewDeclField("bar", StringType, true, nil, nil),
87+
})
88+
base := types.NewEmptyRegistry()
89+
provider := NewDeclTypeProvider(obj)
90+
provider, err := provider.WithTypeProvider(base)
91+
require.NoError(t, err)
92+
wrappedType, found := provider.FindStructType("foo")
93+
require.True(t, found)
94+
require.Equal(t, types.TypeKind, wrappedType.Kind())
95+
}

0 commit comments

Comments
 (0)