mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-10 20:42:26 +00:00
refactor: make scope of ParamKind available to vap controller
This commit is contained in:
parent
6323c106e9
commit
3f63a2d17d
@ -73,6 +73,7 @@ type celAdmissionController struct {
|
|||||||
type policyData struct {
|
type policyData struct {
|
||||||
definitionInfo
|
definitionInfo
|
||||||
paramController generic.Controller[runtime.Object]
|
paramController generic.Controller[runtime.Object]
|
||||||
|
paramScope meta.RESTScope
|
||||||
bindings []bindingInfo
|
bindings []bindingInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,6 +117,9 @@ type paramInfo struct {
|
|||||||
// Function to call to stop the informer and clean up the controller
|
// Function to call to stop the informer and clean up the controller
|
||||||
stop func()
|
stop func()
|
||||||
|
|
||||||
|
// Whether this param is cluster or namespace scoped
|
||||||
|
scope meta.RESTScope
|
||||||
|
|
||||||
// Policy Definitions which refer to this param CRD
|
// Policy Definitions which refer to this param CRD
|
||||||
dependentDefinitions sets.Set[namespacedName]
|
dependentDefinitions sets.Set[namespacedName]
|
||||||
}
|
}
|
||||||
|
@ -258,7 +258,7 @@ func (c *policyController) reconcilePolicyDefinitionSpec(namespace, name string,
|
|||||||
return info.configurationError
|
return info.configurationError
|
||||||
}
|
}
|
||||||
|
|
||||||
paramInfo := c.ensureParamInfo(paramSource, paramsGVR.Resource)
|
paramInfo := c.ensureParamInfo(paramSource, paramsGVR)
|
||||||
paramInfo.dependentDefinitions.Insert(nn)
|
paramInfo.dependentDefinitions.Insert(nn)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -266,7 +266,7 @@ func (c *policyController) reconcilePolicyDefinitionSpec(namespace, name string,
|
|||||||
|
|
||||||
// Ensures that there is an informer started for the given GVK to be used as a
|
// Ensures that there is an informer started for the given GVK to be used as a
|
||||||
// param
|
// param
|
||||||
func (c *policyController) ensureParamInfo(paramSource *v1alpha1.ParamKind, paramsGVR schema.GroupVersionResource) *paramInfo {
|
func (c *policyController) ensureParamInfo(paramSource *v1alpha1.ParamKind, mapping *meta.RESTMapping) *paramInfo {
|
||||||
if info, ok := c.paramsCRDControllers[*paramSource]; ok {
|
if info, ok := c.paramsCRDControllers[*paramSource]; ok {
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
@ -279,7 +279,7 @@ func (c *policyController) ensureParamInfo(paramSource *v1alpha1.ParamKind, para
|
|||||||
// Try to see if our provided informer factory has an informer for this type.
|
// Try to see if our provided informer factory has an informer for this type.
|
||||||
// We assume the informer is already started, and starts all types associated
|
// We assume the informer is already started, and starts all types associated
|
||||||
// with it.
|
// with it.
|
||||||
if genericInformer, err := c.informerFactory.ForResource(paramsGVR); err == nil {
|
if genericInformer, err := c.informerFactory.ForResource(mapping.Resource); err == nil {
|
||||||
informer = genericInformer.Informer()
|
informer = genericInformer.Informer()
|
||||||
|
|
||||||
// Ensure the informer is started
|
// Ensure the informer is started
|
||||||
@ -296,7 +296,7 @@ func (c *policyController) ensureParamInfo(paramSource *v1alpha1.ParamKind, para
|
|||||||
// (cannot start ahead of time, and cannot track dependencies via stopCh)
|
// (cannot start ahead of time, and cannot track dependencies via stopCh)
|
||||||
informer = dynamicinformer.NewFilteredDynamicInformer(
|
informer = dynamicinformer.NewFilteredDynamicInformer(
|
||||||
c.dynamicClient,
|
c.dynamicClient,
|
||||||
paramsGVR,
|
mapping.Resource,
|
||||||
corev1.NamespaceAll,
|
corev1.NamespaceAll,
|
||||||
// Use same interval as is used for k8s typed sharedInformerFactory
|
// Use same interval as is used for k8s typed sharedInformerFactory
|
||||||
// https://github.com/kubernetes/kubernetes/blob/7e0923899fed622efbc8679cca6b000d43633e38/cmd/kube-apiserver/app/server.go#L430
|
// https://github.com/kubernetes/kubernetes/blob/7e0923899fed622efbc8679cca6b000d43633e38/cmd/kube-apiserver/app/server.go#L430
|
||||||
@ -319,6 +319,7 @@ func (c *policyController) ensureParamInfo(paramSource *v1alpha1.ParamKind, para
|
|||||||
ret := ¶mInfo{
|
ret := ¶mInfo{
|
||||||
controller: controller,
|
controller: controller,
|
||||||
stop: instanceCancel,
|
stop: instanceCancel,
|
||||||
|
scope: mapping.Scope,
|
||||||
dependentDefinitions: sets.New[namespacedName](),
|
dependentDefinitions: sets.New[namespacedName](),
|
||||||
}
|
}
|
||||||
c.paramsCRDControllers[*paramSource] = ret
|
c.paramsCRDControllers[*paramSource] = ret
|
||||||
@ -464,15 +465,18 @@ func (c *policyController) latestPolicyData() []policyData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var paramController generic.Controller[runtime.Object]
|
var paramController generic.Controller[runtime.Object]
|
||||||
|
var paramScope meta.RESTScope
|
||||||
if paramKind := definitionInfo.lastReconciledValue.Spec.ParamKind; paramKind != nil {
|
if paramKind := definitionInfo.lastReconciledValue.Spec.ParamKind; paramKind != nil {
|
||||||
if info, ok := c.paramsCRDControllers[*paramKind]; ok {
|
if info, ok := c.paramsCRDControllers[*paramKind]; ok {
|
||||||
paramController = info.controller
|
paramController = info.controller
|
||||||
|
paramScope = info.scope
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res = append(res, policyData{
|
res = append(res, policyData{
|
||||||
definitionInfo: *definitionInfo,
|
definitionInfo: *definitionInfo,
|
||||||
paramController: paramController,
|
paramController: paramController,
|
||||||
|
paramScope: paramScope,
|
||||||
bindings: bindingInfos,
|
bindings: bindingInfos,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user