...
1
2
3
4 package apply
5
6 import (
7 "k8s.io/apimachinery/pkg/api/meta"
8 "k8s.io/cli-runtime/pkg/resource"
9 "k8s.io/client-go/discovery"
10 "k8s.io/client-go/dynamic"
11 "k8s.io/client-go/rest"
12 "k8s.io/kubectl/pkg/cmd/util"
13 "sigs.k8s.io/cli-utils/pkg/apply/info"
14 "sigs.k8s.io/cli-utils/pkg/apply/prune"
15 "sigs.k8s.io/cli-utils/pkg/inventory"
16 "sigs.k8s.io/cli-utils/pkg/kstatus/watcher"
17 )
18
19 type DestroyerBuilder struct {
20 commonBuilder
21 }
22
23
24 func NewDestroyerBuilder() *DestroyerBuilder {
25 return &DestroyerBuilder{
26
27 }
28 }
29
30 func (b *DestroyerBuilder) Build() (*Destroyer, error) {
31 bx, err := b.finalize()
32 if err != nil {
33 return nil, err
34 }
35 return &Destroyer{
36 pruner: &prune.Pruner{
37 InvClient: bx.invClient,
38 Client: bx.client,
39 Mapper: bx.mapper,
40 },
41 statusWatcher: bx.statusWatcher,
42 invClient: bx.invClient,
43 mapper: bx.mapper,
44 client: bx.client,
45 openAPIGetter: bx.discoClient,
46 infoHelper: info.NewHelper(bx.mapper, bx.unstructuredClientForMapping),
47 }, nil
48 }
49
50 func (b *DestroyerBuilder) WithFactory(factory util.Factory) *DestroyerBuilder {
51 b.factory = factory
52 return b
53 }
54
55 func (b *DestroyerBuilder) WithInventoryClient(invClient inventory.Client) *DestroyerBuilder {
56 b.invClient = invClient
57 return b
58 }
59
60 func (b *DestroyerBuilder) WithDynamicClient(client dynamic.Interface) *DestroyerBuilder {
61 b.client = client
62 return b
63 }
64
65 func (b *DestroyerBuilder) WithDiscoveryClient(discoClient discovery.CachedDiscoveryInterface) *DestroyerBuilder {
66 b.discoClient = discoClient
67 return b
68 }
69
70 func (b *DestroyerBuilder) WithRestMapper(mapper meta.RESTMapper) *DestroyerBuilder {
71 b.mapper = mapper
72 return b
73 }
74
75 func (b *DestroyerBuilder) WithRestConfig(restConfig *rest.Config) *DestroyerBuilder {
76 b.restConfig = restConfig
77 return b
78 }
79
80 func (b *DestroyerBuilder) WithUnstructuredClientForMapping(unstructuredClientForMapping func(*meta.RESTMapping) (resource.RESTClient, error)) *DestroyerBuilder {
81 b.unstructuredClientForMapping = unstructuredClientForMapping
82 return b
83 }
84
85 func (b *DestroyerBuilder) WithStatusWatcher(statusWatcher watcher.StatusWatcher) *DestroyerBuilder {
86 b.statusWatcher = statusWatcher
87 return b
88 }
89
View as plain text