@@ -16,39 +16,90 @@ import (
16
16
// Option represents optional call parameters, such as label selectors.
17
17
type Option interface {
18
18
updateURL (base string , v url.Values ) string
19
+ updateDelete (r Resource , d * deleteOptions )
19
20
}
20
21
21
- type queryParam struct {
22
- paramName string
23
- paramValue string
24
- }
22
+ type optionFunc func (base string , v url.Values ) string
23
+
24
+ func (f optionFunc ) updateDelete (r Resource , d * deleteOptions ) {}
25
+ func (f optionFunc ) updateURL (base string , v url.Values ) string { return f (base , v ) }
26
+
27
+ type deleteOptions struct {
28
+ Kind string `json:"kind"`
29
+ APIVersion string `json:"apiVersion"`
25
30
26
- func (o queryParam ) updateURL (base string , v url.Values ) string {
27
- v .Set (o .paramName , o .paramValue )
28
- return base
31
+ GracePeriod * int64 `json:"gracePeriodSeconds,omitempty"`
32
+ Preconditions struct {
33
+ UID string `json:"uid,omitempty"`
34
+ } `json:"preconditions"`
35
+ PropagationPolicy string `json:"propagationPolicy"`
29
36
}
30
37
31
38
// QueryParam can be used to manually set a URL query parameter by name.
32
39
func QueryParam (name , value string ) Option {
33
- return queryParam {
34
- paramName : name ,
35
- paramValue : value ,
36
- }
40
+ return optionFunc (func (base string , v url.Values ) string {
41
+ v .Set (name , value )
42
+ return base
43
+ })
44
+ }
45
+
46
+ type deleteOptionFunc func (r Resource , d * deleteOptions )
47
+
48
+ func (f deleteOptionFunc ) updateDelete (r Resource , d * deleteOptions ) { f (r , d ) }
49
+ func (f deleteOptionFunc ) updateURL (base string , v url.Values ) string { return base }
50
+
51
+ func DeleteAtomic () Option {
52
+ return deleteOptionFunc (func (r Resource , d * deleteOptions ) {
53
+ d .Preconditions .UID = * r .GetMetadata ().Uid
54
+ })
55
+ }
56
+
57
+ // DeletePropagationOrphan orphans the dependent resources during a delete.
58
+ func DeletePropagationOrphan () Option {
59
+ return deleteOptionFunc (func (r Resource , d * deleteOptions ) {
60
+ d .PropagationPolicy = "Orphan"
61
+ })
62
+ }
63
+
64
+ // DeletePropagationBackground deletes the resources and causes the garbage
65
+ // collector to delete dependent resources in the background.
66
+ func DeletePropagationBackground () Option {
67
+ return deleteOptionFunc (func (r Resource , d * deleteOptions ) {
68
+ d .PropagationPolicy = "Background"
69
+ })
70
+ }
71
+
72
+ // DeletePropagationForeground deletes the resources and causes the garbage
73
+ // collector to delete dependent resources and wait for all dependents whose
74
+ // ownerReference.blockOwnerDeletion=true. API sever will put the "foregroundDeletion"
75
+ // finalizer on the object, and sets its deletionTimestamp. This policy is
76
+ // cascading, i.e., the dependents will be deleted with Foreground.
77
+ func DeletePropagationForeground () Option {
78
+ return deleteOptionFunc (func (r Resource , d * deleteOptions ) {
79
+ d .PropagationPolicy = "Foreground"
80
+ })
81
+ }
82
+
83
+ func DeleteGracePeriod (d time.Duration ) Option {
84
+ seconds := int64 (d / time .Second )
85
+ return deleteOptionFunc (func (r Resource , d * deleteOptions ) {
86
+ d .GracePeriod = & seconds
87
+ })
37
88
}
38
89
39
90
// ResourceVersion causes watch operations to only show changes since
40
91
// a particular version of a resource.
41
92
func ResourceVersion (resourceVersion string ) Option {
42
- return queryParam { "resourceVersion" , resourceVersion }
93
+ return QueryParam ( "resourceVersion" , resourceVersion )
43
94
}
44
95
45
96
// Timeout declares the timeout for list and watch operations. Timeout
46
97
// is only accurate to the second.
47
98
func Timeout (d time.Duration ) Option {
48
- return queryParam {
99
+ return QueryParam (
49
100
"timeoutSeconds" ,
50
101
strconv .FormatInt (int64 (d / time .Second ), 10 ),
51
- }
102
+ )
52
103
}
53
104
54
105
// Subresource is a way to interact with a part of an API object without needing
@@ -59,15 +110,9 @@ func Timeout(d time.Duration) Option {
59
110
//
60
111
// See https://kubernetes.io/docs/reference/api-concepts/
61
112
func Subresource (name string ) Option {
62
- return subresource {name }
63
- }
64
-
65
- type subresource struct {
66
- name string
67
- }
68
-
69
- func (s subresource ) updateURL (base string , v url.Values ) string {
70
- return base + "/" + s .name
113
+ return optionFunc (func (base string , v url.Values ) string {
114
+ return base + "/" + name
115
+ })
71
116
}
72
117
73
118
type resourceType struct {
0 commit comments