...

Source file src/sigs.k8s.io/cli-utils/pkg/apply/filter/inventory-policy-prune-filter.go

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

     1  // Copyright 2021 The Kubernetes Authors.
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  package filter
     5  
     6  import (
     7  	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
     8  	"sigs.k8s.io/cli-utils/pkg/inventory"
     9  )
    10  
    11  // InventoryPolicyPruneFilter implements ValidationFilter interface to determine
    12  // if an object should be pruned (deleted) because of the InventoryPolicy
    13  // and if the objects owning inventory identifier matchs the inventory id.
    14  type InventoryPolicyPruneFilter struct {
    15  	Inv       inventory.Info
    16  	InvPolicy inventory.Policy
    17  }
    18  
    19  // Name returns a filter identifier for logging.
    20  func (ipf InventoryPolicyPruneFilter) Name() string {
    21  	return "InventoryPolicyFilter"
    22  }
    23  
    24  // Filter returns an inventory.PolicyPreventedActuationError if the object
    25  // prune/delete should be skipped.
    26  func (ipf InventoryPolicyPruneFilter) Filter(obj *unstructured.Unstructured) error {
    27  	_, err := inventory.CanPrune(ipf.Inv, obj, ipf.InvPolicy)
    28  	if err != nil {
    29  		return err
    30  	}
    31  	return nil
    32  }
    33  

View as plain text