Skip to content

Commit 5708511

Browse files
authored
Merge pull request kubernetes#88708 from mikedanese/deleteopts
Migrate clientset metav1.DeleteOpts to pass-by-value
2 parents cd0057c + 76f8594 commit 5708511

File tree

430 files changed

+1855
-1856
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

430 files changed

+1855
-1856
lines changed

cmd/kubeadm/app/cmd/token.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ func RunDeleteTokens(out io.Writer, client clientset.Interface, tokenIDsOrTokens
431431

432432
tokenSecretName := bootstraputil.BootstrapTokenSecretName(tokenID)
433433
klog.V(1).Infof("[token] deleting token %q", tokenID)
434-
if err := client.CoreV1().Secrets(metav1.NamespaceSystem).Delete(context.TODO(), tokenSecretName, nil); err != nil {
434+
if err := client.CoreV1().Secrets(metav1.NamespaceSystem).Delete(context.TODO(), tokenSecretName, metav1.DeleteOptions{}); err != nil {
435435
return errors.Wrapf(err, "failed to delete bootstrap token %q", tokenID)
436436
}
437437
fmt.Fprintf(out, "bootstrap token %q deleted\n", tokenID)

cmd/kubeadm/app/phases/upgrade/health.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,7 @@ func createJob(client clientset.Interface, cfg *kubeadmapi.ClusterConfiguration)
200200
func deleteHealthCheckJob(client clientset.Interface, ns, jobName string) error {
201201
klog.V(2).Infof("Deleting Job %q in the namespace %q", jobName, ns)
202202
propagation := metav1.DeletePropagationForeground
203-
deleteOptions := &metav1.DeleteOptions{
204-
PropagationPolicy: &propagation,
205-
}
206-
if err := client.BatchV1().Jobs(ns).Delete(context.TODO(), jobName, deleteOptions); err != nil {
203+
if err := client.BatchV1().Jobs(ns).Delete(context.TODO(), jobName, metav1.DeleteOptions{PropagationPolicy: &propagation}); err != nil {
207204
return errors.Wrapf(err, "could not delete Job %q in the namespace %q", jobName, ns)
208205
}
209206
return nil

cmd/kubeadm/app/util/apiclient/idempotency.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,19 +194,13 @@ func CreateOrUpdateDaemonSet(client clientset.Interface, ds *apps.DaemonSet) err
194194
// DeleteDaemonSetForeground deletes the specified DaemonSet in foreground mode; i.e. it blocks until/makes sure all the managed Pods are deleted
195195
func DeleteDaemonSetForeground(client clientset.Interface, namespace, name string) error {
196196
foregroundDelete := metav1.DeletePropagationForeground
197-
deleteOptions := &metav1.DeleteOptions{
198-
PropagationPolicy: &foregroundDelete,
199-
}
200-
return client.AppsV1().DaemonSets(namespace).Delete(context.TODO(), name, deleteOptions)
197+
return client.AppsV1().DaemonSets(namespace).Delete(context.TODO(), name, metav1.DeleteOptions{PropagationPolicy: &foregroundDelete})
201198
}
202199

203200
// DeleteDeploymentForeground deletes the specified Deployment in foreground mode; i.e. it blocks until/makes sure all the managed Pods are deleted
204201
func DeleteDeploymentForeground(client clientset.Interface, namespace, name string) error {
205202
foregroundDelete := metav1.DeletePropagationForeground
206-
deleteOptions := &metav1.DeleteOptions{
207-
PropagationPolicy: &foregroundDelete,
208-
}
209-
return client.AppsV1().Deployments(namespace).Delete(context.TODO(), name, deleteOptions)
203+
return client.AppsV1().Deployments(namespace).Delete(context.TODO(), name, metav1.DeleteOptions{PropagationPolicy: &foregroundDelete})
210204
}
211205

212206
// CreateOrUpdateRole creates a Role if the target resource doesn't exist. If the resource exists already, this function will update the resource instead.

pkg/controller/bootstrap/tokencleaner.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ func (tc *TokenCleaner) evalSecret(o interface{}) {
192192
ttl, alreadyExpired := bootstrapsecretutil.GetExpiration(secret, time.Now())
193193
if alreadyExpired {
194194
klog.V(3).Infof("Deleting expired secret %s/%s", secret.Namespace, secret.Name)
195-
var options *metav1.DeleteOptions
195+
var options metav1.DeleteOptions
196196
if len(secret.UID) > 0 {
197-
options = &metav1.DeleteOptions{Preconditions: &metav1.Preconditions{UID: &secret.UID}}
197+
options.Preconditions = &metav1.Preconditions{UID: &secret.UID}
198198
}
199199
err := tc.client.CoreV1().Secrets(secret.Namespace).Delete(context.TODO(), secret.Name, options)
200200
// NotFound isn't a real error (it's already been deleted)

pkg/controller/certificates/cleaner/cleaner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (ccc *CSRCleanerController) handle(csr *capi.CertificateSigningRequest) err
109109
return err
110110
}
111111
if isIssuedPastDeadline(csr) || isDeniedPastDeadline(csr) || isPendingPastDeadline(csr) || isIssuedExpired {
112-
if err := ccc.csrClient.Delete(context.TODO(), csr.Name, nil); err != nil {
112+
if err := ccc.csrClient.Delete(context.TODO(), csr.Name, metav1.DeleteOptions{}); err != nil {
113113
return fmt.Errorf("unable to delete CSR %q: %v", csr.Name, err)
114114
}
115115
}

pkg/controller/client_builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func (b SAControllerClientBuilder) Config(name string) (*restclient.Config, erro
157157
if !valid {
158158
klog.Warningf("secret %s contained an invalid API token for %s/%s", secret.Name, sa.Namespace, sa.Name)
159159
// try to delete the secret containing the invalid token
160-
if err := b.CoreClient.Secrets(secret.Namespace).Delete(context.TODO(), secret.Name, &metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) {
160+
if err := b.CoreClient.Secrets(secret.Namespace).Delete(context.TODO(), secret.Name, metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) {
161161
klog.Warningf("error deleting secret %s containing invalid API token for %s/%s: %v", secret.Name, sa.Namespace, sa.Name, err)
162162
}
163163
// continue watching for good tokens

pkg/controller/cloud/node_lifecycle_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"time"
2424

2525
"k8s.io/api/core/v1"
26+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2627
"k8s.io/apimachinery/pkg/labels"
2728
"k8s.io/apimachinery/pkg/types"
2829
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
@@ -190,7 +191,7 @@ func (c *CloudNodeLifecycleController) MonitorNodes() {
190191
fmt.Sprintf("Deleting node %v because it does not exist in the cloud provider", node.Name),
191192
"Node %s event: %s", node.Name, deleteNodeEvent)
192193

193-
if err := c.kubeClient.CoreV1().Nodes().Delete(context.TODO(), node.Name, nil); err != nil {
194+
if err := c.kubeClient.CoreV1().Nodes().Delete(context.TODO(), node.Name, metav1.DeleteOptions{}); err != nil {
194195
klog.Errorf("unable to delete node %q: %v", node.Name, err)
195196
}
196197
}

pkg/controller/controller_utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ func (r RealPodControl) DeletePod(namespace string, podID string, object runtime
602602
return fmt.Errorf("object does not have ObjectMeta, %v", err)
603603
}
604604
klog.V(2).Infof("Controller %v deleting pod %v/%v", accessor.GetName(), namespace, podID)
605-
if err := r.KubeClient.CoreV1().Pods(namespace).Delete(context.TODO(), podID, nil); err != nil && !apierrors.IsNotFound(err) {
605+
if err := r.KubeClient.CoreV1().Pods(namespace).Delete(context.TODO(), podID, metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) {
606606
r.Recorder.Eventf(object, v1.EventTypeWarning, FailedDeletePodReason, "Error deleting: %v", err)
607607
return fmt.Errorf("unable to delete pods: %v", err)
608608
}

pkg/controller/cronjob/injection.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (r realJobControl) CreateJob(namespace string, job *batchv1.Job) (*batchv1.
120120

121121
func (r realJobControl) DeleteJob(namespace string, name string) error {
122122
background := metav1.DeletePropagationBackground
123-
return r.KubeClient.BatchV1().Jobs(namespace).Delete(context.TODO(), name, &metav1.DeleteOptions{PropagationPolicy: &background})
123+
return r.KubeClient.BatchV1().Jobs(namespace).Delete(context.TODO(), name, metav1.DeleteOptions{PropagationPolicy: &background})
124124
}
125125

126126
type fakeJobControl struct {
@@ -222,7 +222,7 @@ func (r realPodControl) ListPods(namespace string, opts metav1.ListOptions) (*v1
222222
}
223223

224224
func (r realPodControl) DeletePod(namespace string, name string) error {
225-
return r.KubeClient.CoreV1().Pods(namespace).Delete(context.TODO(), name, nil)
225+
return r.KubeClient.CoreV1().Pods(namespace).Delete(context.TODO(), name, metav1.DeleteOptions{})
226226
}
227227

228228
type fakePodControl struct {

pkg/controller/daemon/update.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (dsc *DaemonSetsController) cleanupHistory(ds *apps.DaemonSet, old []*apps.
171171
continue
172172
}
173173
// Clean up
174-
err := dsc.kubeClient.AppsV1().ControllerRevisions(ds.Namespace).Delete(context.TODO(), history.Name, nil)
174+
err := dsc.kubeClient.AppsV1().ControllerRevisions(ds.Namespace).Delete(context.TODO(), history.Name, metav1.DeleteOptions{})
175175
if err != nil {
176176
return err
177177
}
@@ -227,7 +227,7 @@ func (dsc *DaemonSetsController) dedupCurHistories(ds *apps.DaemonSet, curHistor
227227
}
228228
}
229229
// Remove duplicates
230-
err = dsc.kubeClient.AppsV1().ControllerRevisions(ds.Namespace).Delete(context.TODO(), cur.Name, nil)
230+
err = dsc.kubeClient.AppsV1().ControllerRevisions(ds.Namespace).Delete(context.TODO(), cur.Name, metav1.DeleteOptions{})
231231
if err != nil {
232232
return nil, err
233233
}

0 commit comments

Comments
 (0)