|
| 1 | +// Copyright 2018 The Operator-SDK Authors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package action |
| 16 | + |
| 17 | +import ( |
| 18 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 19 | +) |
| 20 | + |
| 21 | +// DeleteOp wraps all the options for Delete(). |
| 22 | +type DeleteOp struct { |
| 23 | + metaDeleteOptions *metav1.DeleteOptions |
| 24 | +} |
| 25 | + |
| 26 | +// DeleteOption configures DeleteOp. |
| 27 | +type DeleteOption func(*DeleteOp) |
| 28 | + |
| 29 | +func NewDeleteOp() *DeleteOp { |
| 30 | + op := &DeleteOp{} |
| 31 | + op.setDefaults() |
| 32 | + return op |
| 33 | +} |
| 34 | + |
| 35 | +func (op *DeleteOp) applyOpts(opts []DeleteOption) { |
| 36 | + for _, opt := range opts { |
| 37 | + opt(op) |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +func (op *DeleteOp) setDefaults() { |
| 42 | + if op.metaDeleteOptions == nil { |
| 43 | + op.metaDeleteOptions = &metav1.DeleteOptions{} |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +// WithDeleteOptions sets the metav1.DeleteOptions for the Delete() operation. |
| 48 | +func WithDeleteOptions(metaDeleteOptions *metav1.DeleteOptions) DeleteOption { |
| 49 | + return func(op *DeleteOp) { |
| 50 | + op.metaDeleteOptions = metaDeleteOptions |
| 51 | + } |
| 52 | +} |
0 commit comments