in postdeploy-hooks/k8s-cleanup/kubectl.go [150:171]
func (ce CommandExecutor) deleteResources(resources []string) error {
if len(resources) == 0 {
fmt.Printf("There are no resources to delete\n")
return nil
}
fmt.Printf("Beginning to delete resources, there are %d resources to delete\n", len(resources))
for _, resource := range resources {
args := []string{"delete", resource, "--ignore-not-found=true"}
_, err := ce.execCommand(args)
// If the code returned is MethodNotAllowed log that and continue. This
// has popped up for example when trying to delete the podmetrics resource.
if strings.Contains(err.Error(), "MethodNotAllowed") {
fmt.Printf("Unable to delete resource: %s. Deleting that resource is not allowed.\n Continuing on to delete other resources.", resource)
continue
}
if err != nil {
return fmt.Errorf("attempting to delete resource %v resulted in err: %w", resource, err)
}
}
return nil
}