k3s/vendor/github.com/rancher/wrangler/pkg/generic/generating.go

40 lines
846 B
Go
Raw Normal View History

2019-12-12 01:27:03 +00:00
package generic
2020-04-22 22:34:19 +00:00
import (
"github.com/rancher/wrangler/pkg/apply"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
2019-12-12 01:27:03 +00:00
type GeneratingHandlerOptions struct {
AllowCrossNamespace bool
AllowClusterScoped bool
2020-04-22 22:34:19 +00:00
NoOwnerReference bool
2019-12-12 01:27:03 +00:00
DynamicLookup bool
}
2020-04-22 22:34:19 +00:00
func ConfigureApplyForObject(apply apply.Apply, obj metav1.Object, opts *GeneratingHandlerOptions) apply.Apply {
if opts == nil {
opts = &GeneratingHandlerOptions{}
}
if opts.DynamicLookup {
apply = apply.WithDynamicLookup()
}
if opts.NoOwnerReference {
apply = apply.WithSetOwnerReference(true, false)
}
if opts.AllowCrossNamespace && !opts.AllowClusterScoped {
apply = apply.
WithDefaultNamespace(obj.GetNamespace()).
WithListerNamespace(obj.GetNamespace())
}
if !opts.AllowClusterScoped {
apply = apply.WithRestrictClusterScoped()
}
return apply
}