mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Make the FilterNamespace function the last visitor
This commit is contained in:
parent
4c33e36a88
commit
a8449732e0
@ -402,6 +402,7 @@ func (b *Builder) Do() *Result {
|
|||||||
if b.requireNamespace {
|
if b.requireNamespace {
|
||||||
helpers = append(helpers, RequireNamespace(b.namespace))
|
helpers = append(helpers, RequireNamespace(b.namespace))
|
||||||
}
|
}
|
||||||
|
helpers = append(helpers, FilterNamespace())
|
||||||
r.visitor = NewDecoratedVisitor(r.visitor, helpers...)
|
r.visitor = NewDecoratedVisitor(r.visitor, helpers...)
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
@ -384,6 +384,17 @@ func UpdateObjectNamespace(info *Info) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FilterNamespace omits the namespace if the object is not namespace scoped
|
||||||
|
func FilterNamespace() VisitorFunc {
|
||||||
|
return func(info *Info) error {
|
||||||
|
if info.Mapping.Scope.Name() != meta.RESTScopeNameNamespace {
|
||||||
|
info.Namespace = ""
|
||||||
|
UpdateObjectNamespace(info)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// SetNamespace ensures that every Info object visited will have a namespace
|
// SetNamespace ensures that every Info object visited will have a namespace
|
||||||
// set. If info.Object is set, it will be mutated as well.
|
// set. If info.Object is set, it will be mutated as well.
|
||||||
func SetNamespace(namespace string) VisitorFunc {
|
func SetNamespace(namespace string) VisitorFunc {
|
||||||
|
Loading…
Reference in New Issue
Block a user