...

Source file src/sigs.k8s.io/cli-utils/pkg/apply/task/delete_inv_task.go

Documentation: sigs.k8s.io/cli-utils/pkg/apply/task

     1  // Copyright 2021 The Kubernetes Authors.
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  package task
     5  
     6  import (
     7  	apierrors "k8s.io/apimachinery/pkg/api/errors"
     8  	"k8s.io/klog/v2"
     9  	"sigs.k8s.io/cli-utils/pkg/apply/event"
    10  	"sigs.k8s.io/cli-utils/pkg/apply/taskrunner"
    11  	"sigs.k8s.io/cli-utils/pkg/common"
    12  	"sigs.k8s.io/cli-utils/pkg/inventory"
    13  	"sigs.k8s.io/cli-utils/pkg/object"
    14  )
    15  
    16  // DeleteInvTask encapsulates structures necessary to delete
    17  // the inventory object from the cluster. Implements
    18  // the Task interface. This task should happen after all
    19  // resources have been deleted.
    20  type DeleteInvTask struct {
    21  	TaskName  string
    22  	InvClient inventory.Client
    23  	InvInfo   inventory.Info
    24  	DryRun    common.DryRunStrategy
    25  }
    26  
    27  func (i *DeleteInvTask) Name() string {
    28  	return i.TaskName
    29  }
    30  
    31  func (i *DeleteInvTask) Action() event.ResourceAction {
    32  	return event.InventoryAction
    33  }
    34  
    35  func (i *DeleteInvTask) Identifiers() object.ObjMetadataSet {
    36  	return object.ObjMetadataSet{}
    37  }
    38  
    39  // Start deletes the inventory object from the cluster.
    40  func (i *DeleteInvTask) Start(taskContext *taskrunner.TaskContext) {
    41  	go func() {
    42  		klog.V(2).Infof("delete inventory task starting (name: %q)", i.Name())
    43  		err := i.InvClient.DeleteInventoryObj(i.InvInfo, i.DryRun)
    44  		// Not found is not error, since this means it was already deleted.
    45  		if apierrors.IsNotFound(err) {
    46  			err = nil
    47  		}
    48  		klog.V(2).Infof("delete inventory task completing (name: %q)", i.Name())
    49  		taskContext.TaskChannel() <- taskrunner.TaskResult{Err: err}
    50  	}()
    51  }
    52  
    53  // Cancel is not supported by the DeleteInvTask.
    54  func (i *DeleteInvTask) Cancel(_ *taskrunner.TaskContext) {}
    55  
    56  // StatusUpdate is not supported by the DeleteInvTask.
    57  func (i *DeleteInvTask) StatusUpdate(_ *taskrunner.TaskContext, _ object.ObjMetadata) {}
    58  

View as plain text