Skip to content

Commit

Permalink
fix(lint): Fix findings
Browse files Browse the repository at this point in the history
  • Loading branch information
astefanutti committed Nov 22, 2019
1 parent c02067c commit d7656f6
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions pkg/trait/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ func (t *garbageCollectorTrait) garbageCollectResources(e *Environment) {
t.deleteEachOf(deletableGVKs, e, selector)
}

func (t *garbageCollectorTrait) deleteAllOf(GKVs map[schema.GroupVersionKind]struct{}, e *Environment, selector labels.Selector) {
for GVK := range GKVs {
func (t *garbageCollectorTrait) deleteAllOf(gvks map[schema.GroupVersionKind]struct{}, e *Environment, selector labels.Selector) {
for gvk := range gvks {
err := e.Client.DeleteAllOf(context.TODO(),
&unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": GVK.GroupVersion().String(),
"kind": GVK.Kind,
"apiVersion": gvk.GroupVersion().String(),
"kind": gvk.Kind,
"metadata": map[string]interface{}{
"namespace": e.Integration.Namespace,
},
Expand All @@ -161,19 +161,19 @@ func (t *garbageCollectorTrait) deleteAllOf(GKVs map[schema.GroupVersionKind]str
client.PropagationPolicy(metav1.DeletePropagationBackground),
)
if err != nil {
t.L.ForIntegration(e.Integration).Errorf(err, "cannot delete child resources: %v", GVK)
t.L.ForIntegration(e.Integration).Errorf(err, "cannot delete child resources: %v", gvk)
} else {
t.L.ForIntegration(e.Integration).Debugf("child resources deleted: %v", GVK)
t.L.ForIntegration(e.Integration).Debugf("child resources deleted: %v", gvk)
}
}
}

func (t *garbageCollectorTrait) deleteEachOf(GKVs map[schema.GroupVersionKind]struct{}, e *Environment, selector labels.Selector) {
for GVK := range GKVs {
func (t *garbageCollectorTrait) deleteEachOf(gvks map[schema.GroupVersionKind]struct{}, e *Environment, selector labels.Selector) {
for gvk := range gvks {
resources := unstructured.UnstructuredList{
Object: map[string]interface{}{
"apiVersion": GVK.GroupVersion().String(),
"kind": GVK.Kind,
"apiVersion": gvk.GroupVersion().String(),
"kind": gvk.Kind,
},
}
options := []client.ListOption{
Expand All @@ -182,13 +182,14 @@ func (t *garbageCollectorTrait) deleteEachOf(GKVs map[schema.GroupVersionKind]st
}
if err := t.client.List(context.TODO(), &resources, options...); err != nil {
if !k8serrors.IsNotFound(err) && !k8serrors.IsForbidden(err) {
t.L.ForIntegration(e.Integration).Errorf(err, "cannot list child resources: %v", GVK)
t.L.ForIntegration(e.Integration).Errorf(err, "cannot list child resources: %v", gvk)
}
continue
}

for _, resource := range resources.Items {
err := t.client.Delete(context.TODO(), &resource, client.PropagationPolicy(metav1.DeletePropagationBackground))
r := resource
err := t.client.Delete(context.TODO(), &r, client.PropagationPolicy(metav1.DeletePropagationBackground))
if err != nil {
// The resource may have already been deleted
if !k8serrors.IsNotFound(err) {
Expand Down

0 comments on commit d7656f6

Please sign in to comment.