Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions pkg/controllers/openshift-controller-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package controllers

import (
"context"
"errors"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -102,12 +103,14 @@ servingInfo:

func (s *OCPControllerManager) Run(ctx context.Context, ready chan<- struct{}, stopped chan<- struct{}) error {
defer close(stopped)
errorChannel := make(chan error, 1)

// run readiness check
go func() {
healthcheckStatus := util.RetryTCPConnection("127.0.0.1", "8445")
if !healthcheckStatus {
klog.Fatalf(s.Name(), fmt.Errorf("healthcheck status"), "%s failed to start")
klog.Errorf(s.Name(), fmt.Errorf("healthcheck status"), "%s failed to start")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This log format doesn't look right. Errorf() takes a format string first, which here is passed as the last arg.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oh right, I was just changing severity, but you're right.

errorChannel <- errors.New("openshift-controller-manager healthcheck status failed")
}
klog.Infof("%s is ready", s.Name())
close(ready)
Expand All @@ -116,13 +119,24 @@ func (s *OCPControllerManager) Run(ctx context.Context, ready chan<- struct{}, s
if err := assets.ApplyNamespaces([]string{
"assets/core/0000_50_cluster-openshift-controller-manager_00_namespace.yaml",
}, s.kubeconfig); err != nil {
klog.Warningf("failed to apply openshift namespaces %v", err)
klog.Errorf("failed to apply openshift namespaces %v", err)

@copejon copejon Feb 4, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Assuming RetryTCPConnection writes an error to the chan, what's the expected sequence of events? It looks as though the err will be placed in the chan buffer, but ApplyNamespaces will be called. If ApplyNamespaces errors, then the error written to the chan is lost at the return. So the actual reason for the crash will be masked.

Or:
If RetryTCPConnection sends an error to the chan buff, but ApplyNamespaces returns nil, then the 2nd go func is run. The select statement will read from the chan buff and not block since there's a value to read, causing the function to return. The concurrent StartControllerManager() call will continue running however.

Question is: is it safe to assume the StartControllerManager routine will die gracefully and quietly (without spamming logs) if RetryTCPConnection returns an error?

To be clear, it'll eventually die when the runtime handles the error and shuts down. I'm interested in how readable/debugable the shutdown will be. Secondly, resources created/opened by StartControllerManager won't have a chance to be cleaned up gracefully, since the main routine doesn't wait for subroutines to complete.

return err
}

options := openshift_controller_manager.OpenShiftControllerManager{Output: os.Stdout}
options.ConfigFilePath = s.ConfigFilePath
if err := options.StartControllerManager(); err != nil {
klog.Fatalf("Failed to start openshift-controller-manager %v", err)

go func() {
if err := options.StartControllerManager(); err != nil {
klog.Errorf("Failed to start openshift-controller-manager %v", err)
errorChannel <- err
}
}()

select {
case <-ctx.Done():
return ctx.Err()
case err := <-errorChannel:
return err
}
return ctx.Err()
}