mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
40 lines
846 B
Go
40 lines
846 B
Go
package generic
|
|
|
|
import (
|
|
"github.com/rancher/wrangler/pkg/apply"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
)
|
|
|
|
type GeneratingHandlerOptions struct {
|
|
AllowCrossNamespace bool
|
|
AllowClusterScoped bool
|
|
NoOwnerReference bool
|
|
DynamicLookup bool
|
|
}
|
|
|
|
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
|
|
}
|