...
1
16
17 package model
18
19 import (
20 apiservercel "k8s.io/apiserver/pkg/cel"
21 "k8s.io/apiserver/pkg/cel/common"
22
23 "k8s.io/apiextensions-apiserver/pkg/apiserver/schema"
24 )
25
26
27
28
29
30
31
32
33
34
35 func SchemaDeclType(s *schema.Structural, isResourceRoot bool) *apiservercel.DeclType {
36 return common.SchemaDeclType(&Structural{Structural: s}, isResourceRoot)
37 }
38
39
40
41 func WithTypeAndObjectMeta(s *schema.Structural) *schema.Structural {
42 if s.Properties != nil &&
43 s.Properties["kind"].Type == "string" &&
44 s.Properties["apiVersion"].Type == "string" &&
45 s.Properties["metadata"].Type == "object" &&
46 s.Properties["metadata"].Properties != nil &&
47 s.Properties["metadata"].Properties["name"].Type == "string" &&
48 s.Properties["metadata"].Properties["generateName"].Type == "string" {
49 return s
50 }
51 result := &schema.Structural{
52 Generic: s.Generic,
53 Extensions: s.Extensions,
54 ValueValidation: s.ValueValidation,
55 }
56 props := make(map[string]schema.Structural, len(s.Properties))
57 for k, prop := range s.Properties {
58 props[k] = prop
59 }
60 stringType := schema.Structural{Generic: schema.Generic{Type: "string"}}
61 props["kind"] = stringType
62 props["apiVersion"] = stringType
63 props["metadata"] = schema.Structural{
64 Generic: schema.Generic{Type: "object"},
65 Properties: map[string]schema.Structural{
66 "name": stringType,
67 "generateName": stringType,
68 },
69 }
70 result.Properties = props
71
72 return result
73 }
74
View as plain text