fix setting resource selector default namespace for policy
Signed-off-by: carlory <baofa.fan@daocloud.io>
This commit is contained in:
parent
61110bb557
commit
990c079eb6
|
@ -30,10 +30,13 @@ func (a *MutatingAdmission) Handle(ctx context.Context, req admission.Request) a
|
|||
}
|
||||
|
||||
// Set default namespace for all resource selector if not set.
|
||||
// We need to get the default namespace from the request because for kube-apiserver < v1.24,
|
||||
// the namespace of the object with namespace unset in the mutating webook chain of a create request
|
||||
// is not populated yet. See https://github.com/kubernetes/kubernetes/pull/94637 for more details.
|
||||
for i := range policy.Spec.ResourceSelectors {
|
||||
if len(policy.Spec.ResourceSelectors[i].Namespace) == 0 {
|
||||
klog.Infof("Setting resource selector default namespace for policy: %s/%s", policy.Namespace, policy.Name)
|
||||
policy.Spec.ResourceSelectors[i].Namespace = policy.Namespace
|
||||
klog.Infof("Setting resource selector default namespace for policy: %s/%s", req.Namespace, policy.Name)
|
||||
policy.Spec.ResourceSelectors[i].Namespace = req.Namespace
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,13 +42,16 @@ func (a *MutatingAdmission) Handle(ctx context.Context, req admission.Request) a
|
|||
if err != nil {
|
||||
return admission.Errored(http.StatusBadRequest, err)
|
||||
}
|
||||
klog.V(2).Infof("Mutating PropagationPolicy(%s/%s) for request: %s", policy.Namespace, policy.Name, req.Operation)
|
||||
klog.V(2).Infof("Mutating PropagationPolicy(%s/%s) for request: %s", req.Namespace, policy.Name, req.Operation)
|
||||
|
||||
// Set default namespace for all resource selector if not set.
|
||||
// We need to get the default namespace from the request because for kube-apiserver < v1.24,
|
||||
// the namespace of the object with namespace unset in the mutating webook chain of a create request
|
||||
// is not populated yet. See https://github.com/kubernetes/kubernetes/pull/94637 for more details.
|
||||
for i := range policy.Spec.ResourceSelectors {
|
||||
if len(policy.Spec.ResourceSelectors[i].Namespace) == 0 {
|
||||
klog.Infof("Setting resource selector default namespace for policy: %s/%s", policy.Namespace, policy.Name)
|
||||
policy.Spec.ResourceSelectors[i].Namespace = policy.Namespace
|
||||
klog.Infof("Setting resource selector default namespace for policy: %s/%s", req.Namespace, policy.Name)
|
||||
policy.Spec.ResourceSelectors[i].Namespace = req.Namespace
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue