-
Notifications
You must be signed in to change notification settings - Fork 95
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
Conversation
fc531c7
to
ad21da0
Compare
This new PR is to replace #448. |
@@ -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{}) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a new controller
return nil, nil | ||
} | ||
return nil, err | ||
} | ||
if err := helper.ConsoleLinkSupported(); err == nil { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
3b2f46c
to
243c132
Compare
Waiting for your input. Let us know. |
7f63a39
to
da55461
Compare
sorry of the delay, now I'm back. |
97319fd
to
d7c334c
Compare
ready for further review |
4c077f3
to
6b4965f
Compare
@eguzki I just did a rebase, built and tested in my lab, 3scale worked ok. |
pkg/helper/webconsole.go
Outdated
} | ||
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
pkg/helper/webconsole.go
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Outdated comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
pkg/helper/webconsole.go
Outdated
ObjectMeta: metav1.ObjectMeta{ | ||
Name: consoleLinkName, | ||
Labels: map[string]string{ | ||
"3scale.net/name": req.Name, |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modified
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
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. |
f3ab53a
to
f137358
Compare
pkg/helper/webconsole.go
Outdated
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added requeue
pkg/helper/webconsole.go
Outdated
logger.Info("Console link has been created:", consoleLinkName) | ||
} | ||
} else if err == nil && consoleLink != nil { | ||
updateConsoleLink(ctx, route, consoleLink, c) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added requeue
pkg/helper/webconsole.go
Outdated
func ReconcileConsoleLink(ctx context.Context, c client.Client, req *reconcile.Request) error { | ||
route := getRoute(ctx, c, req) | ||
if route == nil { | ||
removeConsoleLink(ctx, c, req) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added requeue
Good, all checks passed. |
f137358
to
a77c4eb
Compare
logger.Info("Reconciling ReconcileWebConsole") | ||
|
||
if err := helper.ConsoleLinkSupported(); err == nil { | ||
if err = helper.ReconcileConsoleLink(r.Context(), r.Client(), &request); err != nil { |
There was a problem hiding this comment.
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
pkg/helper/webconsole.go
Outdated
// 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 { |
There was a problem hiding this comment.
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)
pkg/helper/webconsole.go
Outdated
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 { |
There was a problem hiding this comment.
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? 🤔
There was a problem hiding this comment.
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
Created PR myeung18#1 for some refactoring |
Code Climate has analyzed commit d0baac2 and detected 2 issues on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
refactors are applied and tested. |
Looks good to me 👍 |
Congratulations @myeung18 for the very good job. 🎖️ Thank you very much for the contribution |
Signed-off-by: Marco Yeung myeung@redhat.com
Added ConsoleLink Creation/Remove and upgraded client-go/RHsyseng libraries for OCP4.3 or above