Skip to content

Conversation

@liwenwu-amazon
Copy link
Contributor

@liwenwu-amazon liwenwu-amazon commented Dec 3, 2022

Issue #, if available:
#15
Description of changes:
Use tags to track whether target group should be deleted

Testings:

  • create a serviceexport, stop controller, then manually delete remove serviceexport finalizer , restart controller, make sure the target group are deleted.
  • Update httpRoute and remove a backend ref, and confirm controller will delete the target group referenced by this backendref

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@liwenwu-amazon liwenwu-amazon changed the title Fixed target group leaking problems (wip) Fixed target group leaking problems Dec 4, 2022
ResourceArn: tg.Arn,
}

tagsOutput, err := vpcLatticeSess.ListTagsForResourceWithContext(ctx, &tagsInput)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to handle this err

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check out https://github.com/uber-go/multierr if you're not familiar. I think it probably makes sense to just short circuit, rather than aggregating though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add logic to set tagsOutput to nil so the caller will know there is no tags associated to this target group

"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/gateway-api/apis/v1alpha2"
mcs_api "sigs.k8s.io/mcs-api/pkg/apis/v1alpha1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kube style for this is typically to use v1alpha1 or mcsv1alpha1` if there's a conflict.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will create an issue to track this and cleanup the whole code base #61


httpRoute := &v1alpha2.HTTPRoute{}

if err := t.client.Get(ctx, httprouteName, httpRoute); err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to handle this err. I'd recommend inverting this if statement

if err := ...; err != nil { // handle error } // business logic 
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well this is not an error, just means that the parent HTTPRoute does not exist. I have reverted if and else for it. so it might helped the readability

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if you get a transient network error? Or a permissions error? 404 is only one type of error that. can occur.

glog.V(6).Infof("tgname %v is not used by httproute %v\n", tgName, httpRoute)
}
} else {
glog.V(6).Infof("parent httpRoute %v not found for TG name %v namespace %v", httprouteName, srvName, srvNamespace)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current logic will trigger this for more than not found errors. Any transient network error will trigger this.

}
}

if tg, err := t.latticeDataStore.GetTargetGroup(*sdkTG.getTargetGroupOutput.Name, true); err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to handle NotFound and TransientError separately?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, seems if other TransientError is not handled, these targetGroup will be deleted.

}

return ctrl.Result{}, err
return ctrl.Result{RequeueAfter: time.Minute * 10}, err
Copy link
Contributor

@ellistarn ellistarn Dec 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend against this. Golang's error return pattern is a "result or error" semantic. In this case, you're returning a "result and error". This violates the standard go pattern, and IIUC, controller runtime will ignore this value in 100% of cases since error will always be set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any other mechanism to force controller reconcile every 10 minutes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to force reconcile every 10 minutes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants