mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-13 13:55:41 +00:00
opportunistically attempt to refresh RESTMapper
if GVK resolution fails.
This commit is contained in:
parent
05cd3e66ef
commit
38fecc8319
@ -238,7 +238,7 @@ func (c *TypeChecker) typesToCheck(p *v1beta1.ValidatingAdmissionPolicy) []schem
|
|||||||
if p.Spec.MatchConstraints == nil || len(p.Spec.MatchConstraints.ResourceRules) == 0 {
|
if p.Spec.MatchConstraints == nil || len(p.Spec.MatchConstraints.ResourceRules) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
restMapperRefreshAttempted := false // at most once per policy, refresh RESTMapper and retry resolution.
|
||||||
for _, rule := range p.Spec.MatchConstraints.ResourceRules {
|
for _, rule := range p.Spec.MatchConstraints.ResourceRules {
|
||||||
groups := extractGroups(&rule.Rule)
|
groups := extractGroups(&rule.Rule)
|
||||||
if len(groups) == 0 {
|
if len(groups) == 0 {
|
||||||
@ -268,8 +268,17 @@ func (c *TypeChecker) typesToCheck(p *v1beta1.ValidatingAdmissionPolicy) []schem
|
|||||||
}
|
}
|
||||||
resolved, err := c.RestMapper.KindsFor(gvr)
|
resolved, err := c.RestMapper.KindsFor(gvr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if restMapperRefreshAttempted {
|
||||||
|
// RESTMapper refresh happens at most once per policy
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
c.tryRefreshRESTMapper()
|
||||||
|
restMapperRefreshAttempted = true
|
||||||
|
resolved, err = c.RestMapper.KindsFor(gvr)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
for _, r := range resolved {
|
for _, r := range resolved {
|
||||||
if !r.Empty() {
|
if !r.Empty() {
|
||||||
gvks.Insert(r)
|
gvks.Insert(r)
|
||||||
@ -344,6 +353,13 @@ func sortGVKList(list []schema.GroupVersionKind) []schema.GroupVersionKind {
|
|||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tryRefreshRESTMapper refreshes the RESTMapper if it supports refreshing.
|
||||||
|
func (c *TypeChecker) tryRefreshRESTMapper() {
|
||||||
|
if r, ok := c.RestMapper.(meta.ResettableRESTMapper); ok {
|
||||||
|
r.Reset()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func buildEnv(hasParams bool, hasAuthorizer bool, types typeOverwrite) (*cel.Env, error) {
|
func buildEnv(hasParams bool, hasAuthorizer bool, types typeOverwrite) (*cel.Env, error) {
|
||||||
baseEnv := environment.MustBaseEnvSet(environment.DefaultCompatibilityVersion())
|
baseEnv := environment.MustBaseEnvSet(environment.DefaultCompatibilityVersion())
|
||||||
requestType := plugincel.BuildRequestType()
|
requestType := plugincel.BuildRequestType()
|
||||||
|
Loading…
Reference in New Issue
Block a user