Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ConsoleLink Creation/Remove #462

Merged
merged 2 commits into from
Oct 2, 2020
Merged

Conversation

myeung18
Copy link

@myeung18 myeung18 commented Sep 4, 2020

Signed-off-by: Marco Yeung myeung@redhat.com

Added ConsoleLink Creation/Remove and upgraded client-go/RHsyseng libraries for OCP4.3 or above

@myeung18 myeung18 force-pushed the consolelink branch 2 times, most recently from fc531c7 to ad21da0 Compare September 4, 2020 19:14
@myeung18
Copy link
Author

myeung18 commented Sep 4, 2020

This new PR is to replace #448.

deploy/cluster_role_binding.yaml Show resolved Hide resolved
deploy/cluster_role.yaml Show resolved Hide resolved
go.mod Show resolved Hide resolved
pkg/apis/addtoscheme_apps_v1alpha1.go Outdated Show resolved Hide resolved
@@ -101,6 +105,11 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
return err
}

err = c.Watch(&source.Kind{Type: &routev1.Route{}}, &handler.EnqueueRequestForObject{})
Copy link
Member

Choose a reason for hiding this comment

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

As watched routes are not managed by the apimanager controller, I think it makes sense to create a separate controller for this logic. Note that this apimanager controller always tries to read APIManager type out of reconcile request object (

instance, err := r.apiManagerInstance(request.NamespacedName)
)

Copy link
Author

Choose a reason for hiding this comment

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

added a new controller

pkg/controller/apimanager/apimanager_controller.go Outdated Show resolved Hide resolved
return nil, nil
}
return nil, err
}
if err := helper.ConsoleLinkSupported(); err == nil {
Copy link
Member

Choose a reason for hiding this comment

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

I do not think apimanager controller is the one appropriate for this logic. But if it was, this would not be the right place. It would be inside the reconcileAPIManagerLogic method

Copy link
Author

@myeung18 myeung18 Sep 16, 2020

Choose a reason for hiding this comment

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

moved to the new controller

pkg/helper/webconsole.go Outdated Show resolved Hide resolved
func CreateConsoleLink(ctx context.Context, c client.Client, apimanager *appsv1alpha1.APIManager) {
route := getRoute(ctx, c, apimanager)
if route != nil {
consoleLinkName := fmt.Sprintf("%s-%s", apimanager.ObjectMeta.Name, apimanager.Namespace)
Copy link
Member

Choose a reason for hiding this comment

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

Try to create ReconcileConsoleLink method of the BaseAPIManagerLogicReconciler type in base_apimanager_logic_reconciler.go. You should have everything you need and the implementation should be easy.

Copy link
Author

@myeung18 myeung18 Sep 16, 2020

Choose a reason for hiding this comment

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

moved to the new controller

@myeung18 myeung18 force-pushed the consolelink branch 2 times, most recently from 3b2f46c to 243c132 Compare September 9, 2020 22:17
@eguzki
Copy link
Member

eguzki commented Sep 16, 2020

Waiting for your input. Let us know.

@myeung18 myeung18 force-pushed the consolelink branch 3 times, most recently from 7f63a39 to da55461 Compare September 16, 2020 21:48
@myeung18
Copy link
Author

Waiting for your input. Let us know

sorry of the delay, now I'm back.

@myeung18 myeung18 force-pushed the consolelink branch 7 times, most recently from 97319fd to d7c334c Compare September 18, 2020 13:26
@myeung18
Copy link
Author

Waiting for your input. Let us know.

ready for further review

@myeung18 myeung18 force-pushed the consolelink branch 2 times, most recently from 4c077f3 to 6b4965f Compare September 28, 2020 13:46
@myeung18
Copy link
Author

@eguzki I just did a rebase, built and tested in my lab, 3scale worked ok.
I do see those ci test failures, but they seem to appear on other PRs as well.
Is there anything else I should on this PR?

@miguelsorianod
Copy link
Contributor

Hi @myeung18,

Yesterday we applied some changes to fix some issues that we had in our CI tests (#480). Could you rebase again from master so the tests are run with the new changes?

Thank you.

}
func getRoute(ctx context.Context, c client.Client, req *reconcile.Request) *routev1.Route {
// here the loop tries the best to collect a route, the reconcile event may comes
// before the route resources get created/updated
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure why this loop is needed.

Why would the reconcile event come before the route gets created/updated?
In the controller code there's a watch for Route resources. An event will be triggered when a route is created/updated/deleted

Copy link
Author

@myeung18 myeung18 Sep 29, 2020

Choose a reason for hiding this comment

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

I can't reproduce the case I saw before.
I removed the loop, and it also works.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

time.Sleep(time.Duration(100) * time.Microsecond)
deployedRoutes, err := reader.List(&routev1.RouteList{})
if err == nil {
for _, route := range deployedRoutes { //look for 3scale admin routes, capture route object
Copy link
Contributor

Choose a reason for hiding this comment

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

Outdated comment

Copy link
Author

Choose a reason for hiding this comment

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

changed

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

ObjectMeta: metav1.ObjectMeta{
Name: consoleLinkName,
Labels: map[string]string{
"3scale.net/name": req.Name,
Copy link
Contributor

Choose a reason for hiding this comment

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

Would 3scale.net/route-name make more sense than 3scale.net/name?

Copy link
Author

Choose a reason for hiding this comment

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

modified

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@myeung18
Copy link
Author

@eguzki I just did a rebase, built and tested in my lab, 3scale worked ok.
I do see those ci test failures, but they seem to appear on other PRs as well.
Is there anything else I should on this PR?

@myeung18 myeung18 closed this Sep 29, 2020
@myeung18 myeung18 reopened this Sep 29, 2020
@eguzki
Copy link
Member

eguzki commented Sep 29, 2020

I just hit re-run. If it keeps failing, it needs to be debugged. The issue is that 3scale did not deploy as expected. Maybe the expectation is what needs to be worked out. We will check.

@myeung18 myeung18 force-pushed the consolelink branch 4 times, most recently from f3ab53a to f137358 Compare September 29, 2020 17:48
@myeung18
Copy link
Author

Hi @myeung18,

Yesterday we applied some changes to fix some issues that we had in our CI tests (#480). Could you rebase again from master so the tests are run with the new changes?

Thank you.

rebased, all changes are ready for review

err := c.Get(ctx, types.NamespacedName{Name: consoleLinkName}, consoleLink)
if err != nil && apierrors.IsNotFound(err) {
consoleLink = getConsoleLink(consoleLinkName, route, req)
if err := c.Create(ctx, consoleLink); 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.

If creation fails we should also retry apart from logging

Copy link
Author

Choose a reason for hiding this comment

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

added requeue

logger.Info("Console link has been created:", consoleLinkName)
}
} else if err == nil && consoleLink != nil {
updateConsoleLink(ctx, route, consoleLink, c)
Copy link
Contributor

Choose a reason for hiding this comment

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

If update fails we should also retry apart from logging

Copy link
Author

Choose a reason for hiding this comment

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

added requeue

func ReconcileConsoleLink(ctx context.Context, c client.Client, req *reconcile.Request) error {
route := getRoute(ctx, c, req)
if route == nil {
removeConsoleLink(ctx, c, req)
Copy link
Contributor

Choose a reason for hiding this comment

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

Here if it fails to remove we should also requeue. There's an exception in this case: If it fails to remove because it does not exist anymore then we don't need to requeue

Copy link
Author

Choose a reason for hiding this comment

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

added requeue

@eguzki
Copy link
Member

eguzki commented Sep 30, 2020

Good, all checks passed.

logger.Info("Reconciling ReconcileWebConsole")

if err := helper.ConsoleLinkSupported(); err == nil {
if err = helper.ReconcileConsoleLink(r.Context(), r.Client(), &request); 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.

It would be nice to log the error here

// ReconcileConsoleLink creates/deletes/updates a ConsoleLink based on the Route
func ReconcileConsoleLink(ctx context.Context, c client.Client, req *reconcile.Request) error {
route := getRoute(ctx, c, req)
if route == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably a good idea to check the error and return the error to retry if it fails (the exception is if the error is not found of course)

consoleLink := &consolev1.ConsoleLink{}
consoleLinkName := fmt.Sprintf("%s-%s", ConsoleLinkNamePrefix, req.Namespace)
err := c.Get(ctx, types.NamespacedName{Name: consoleLinkName}, consoleLink)
if err == nil && consoleLink != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

This checking seems odd.

If err is nil ConsoleLink shouldn't be nil by definition right? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Additionally, if the error is not nil and it is not the isnotfound error then the error should be returned so it can be retried

@eguzki
Copy link
Member

eguzki commented Oct 1, 2020

Created PR myeung18#1 for some refactoring

@codeclimate
Copy link

codeclimate bot commented Oct 1, 2020

Code Climate has analyzed commit d0baac2 and detected 2 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 1
Duplication 1

View more on Code Climate.

@myeung18
Copy link
Author

myeung18 commented Oct 1, 2020

refactors are applied and tested.

@miguelsorianod
Copy link
Contributor

Looks good to me 👍

@eguzki
Copy link
Member

eguzki commented Oct 2, 2020

Congratulations @myeung18 for the very good job. 🎖️

Thank you very much for the contribution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants