@@ -50,7 +50,7 @@ type Writer interface {
50
50
Create (ctx context.Context , obj runtime.Object ) error
51
51
52
52
// Delete deletes the given obj from Kubernetes cluster.
53
- Delete (ctx context.Context , obj runtime.Object ) error
53
+ Delete (ctx context.Context , obj runtime.Object , opts ... DeleteOptionFunc ) error
54
54
55
55
// Update updates the given obj in the Kubernetes cluster. obj must be a
56
56
// struct pointer so that obj can be updated with the content returned by the Server.
@@ -93,6 +93,88 @@ type FieldIndexer interface {
93
93
IndexField (obj runtime.Object , field string , extractValue IndexerFunc ) error
94
94
}
95
95
96
+ // DeleteOptions contains options for delete requests. It's generally a subset
97
+ // of metav1.DeleteOptions.
98
+ type DeleteOptions struct {
99
+ // GracePeriodSeconds is the duration in seconds before the object should be
100
+ // deleted. Value must be non-negative integer. The value zero indicates
101
+ // delete immediately. If this value is nil, the default grace period for the
102
+ // specified type will be used.
103
+ GracePeriodSeconds * int64
104
+
105
+ // Preconditions must be fulfilled before a deletion is carried out. If not
106
+ // possible, a 409 Conflict status will be returned.
107
+ Preconditions * metav1.Preconditions
108
+
109
+ // PropagationPolicy determined whether and how garbage collection will be
110
+ // performed. Either this field or OrphanDependents may be set, but not both.
111
+ // The default policy is decided by the existing finalizer set in the
112
+ // metadata.finalizers and the resource-specific default policy.
113
+ // Acceptable values are: 'Orphan' - orphan the dependents; 'Background' -
114
+ // allow the garbage collector to delete the dependents in the background;
115
+ // 'Foreground' - a cascading policy that deletes all dependents in the
116
+ // foreground.
117
+ PropagationPolicy * metav1.DeletionPropagation
118
+
119
+ // Raw represents raw DeleteOptions, as passed to the API server.
120
+ Raw * metav1.DeleteOptions
121
+ }
122
+
123
+ // AsDeleteOptions returns these options as a metav1.DeleteOptions.
124
+ // This may mutate the Raw field.
125
+ func (o * DeleteOptions ) AsDeleteOptions () * metav1.DeleteOptions {
126
+
127
+ if o == nil {
128
+ return & metav1.DeleteOptions {}
129
+ }
130
+ if o .Raw == nil {
131
+ o .Raw = & metav1.DeleteOptions {}
132
+ }
133
+
134
+ o .Raw .GracePeriodSeconds = o .GracePeriodSeconds
135
+ o .Raw .Preconditions = o .Preconditions
136
+ o .Raw .PropagationPolicy = o .PropagationPolicy
137
+ return o .Raw
138
+ }
139
+
140
+ // ApplyOptions executes the given DeleteOptionFuncs and returns the mutated
141
+ // DeleteOptions.
142
+ func (o * DeleteOptions ) ApplyOptions (optFuncs []DeleteOptionFunc ) * DeleteOptions {
143
+ for _ , optFunc := range optFuncs {
144
+ optFunc (o )
145
+ }
146
+ return o
147
+ }
148
+
149
+ // DeleteOptionFunc is a function that mutates a DeleteOptions struct. It implements
150
+ // the functional options pattern. See
151
+ // https://github.com/tmrts/go-patterns/blob/master/idiom/functional-options.md.
152
+ type DeleteOptionFunc func (* DeleteOptions )
153
+
154
+ // GracePeriodSeconds is a functional option that sets the GracePeriodSeconds
155
+ // field of a DeleteOptions struct.
156
+ func GracePeriodSeconds (gp int64 ) DeleteOptionFunc {
157
+ return func (opts * DeleteOptions ) {
158
+ opts .GracePeriodSeconds = & gp
159
+ }
160
+ }
161
+
162
+ // Preconditions is a functional option that sets the Preconditions field of a
163
+ // DeleteOptions struct.
164
+ func Preconditions (p * metav1.Preconditions ) DeleteOptionFunc {
165
+ return func (opts * DeleteOptions ) {
166
+ opts .Preconditions = p
167
+ }
168
+ }
169
+
170
+ // PropagationPolicy is a functional option that sets the PropagationPolicy
171
+ // field of a DeleteOptions struct.
172
+ func PropagationPolicy (p metav1.DeletionPropagation ) DeleteOptionFunc {
173
+ return func (opts * DeleteOptions ) {
174
+ opts .PropagationPolicy = & p
175
+ }
176
+ }
177
+
96
178
// ListOptions contains options for limitting or filtering results.
97
179
// It's generally a subset of metav1.ListOptions, with support for
98
180
// pre-parsed selectors (since generally, selectors will be executed
0 commit comments