Skip to content

Commit

Permalink
components, main: add Component Init method
Browse files Browse the repository at this point in the history
Add Init() method to the Component interface and call it from main on
startup.

Will be used to move startup-time code from ReconcileComponent
(like adjusting params.env).

Signed-off-by: Yauheni Kaliuta <[email protected]>
  • Loading branch information
ykaliuta committed Aug 29, 2024
1 parent 1a8ce2c commit dfa9f1f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions components/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ type Component struct {
DevFlags *DevFlags `json:"devFlags,omitempty"`
}

func (c *Component) Init(_ cluster.Platform) error {
return nil
}

func (c *Component) GetManagementState() operatorv1.ManagementState {
return c.ManagementState
}
Expand Down Expand Up @@ -78,6 +82,7 @@ type ManifestsConfig struct {
}

type ComponentInterface interface {
Init(platform cluster.Platform) error
ReconcileComponent(ctx context.Context, cli client.Client, logger logr.Logger,
owner metav1.Object, DSCISpec *dsciv1.DSCInitializationSpec, platform cluster.Platform, currentComponentStatus bool) error
Cleanup(ctx context.Context, cli client.Client, DSCISpec *dsciv1.DSCInitializationSpec) error
Expand Down
21 changes: 21 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"flag"
"os"

"github.com/hashicorp/go-multierror"
addonv1alpha1 "github.com/openshift/addon-operator/apis/addons/v1alpha1"
ocappsv1 "github.com/openshift/api/apps/v1" //nolint:importas //reason: conflicts with appsv1 "k8s.io/api/apps/v1"
buildv1 "github.com/openshift/api/build/v1"
Expand Down Expand Up @@ -98,6 +99,22 @@ func init() { //nolint:gochecknoinits
utilruntime.Must(operatorv1.Install(scheme))
}

func initComponents(p cluster.Platform) error {
var errs *multierror.Error
var dummyDSC = &dscv1.DataScienceCluster{}

components, err := dummyDSC.GetComponents()
if err != nil {
return err
}

for _, c := range components {
errs = multierror.Append(errs, c.Init(p))
}

return errs.ErrorOrNil()
}

func main() { //nolint:funlen
var metricsAddr string
var enableLeaderElection bool
Expand Down Expand Up @@ -278,6 +295,10 @@ func main() { //nolint:funlen
setupLog.Error(err, "unable to set up ready check")
os.Exit(1)
}
if err := initComponents(platform); err != nil {
setupLog.Error(err, "unable to init components")
os.Exit(1)
}

setupLog.Info("starting manager")
if err := mgr.Start(ctx); err != nil {
Expand Down

0 comments on commit dfa9f1f

Please sign in to comment.