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 Oct 3, 2024
1 parent 8bebb1a commit 87812cd
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 @@ -38,6 +38,10 @@ type Component struct {
DevFlags *DevFlags `json:"devFlags,omitempty"`
}

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

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

type ComponentInterface interface {
Init(ctx context.Context, 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, owner metav1.Object, 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 @@ -102,6 +103,22 @@ func init() { //nolint:gochecknoinits
utilruntime.Must(operatorv1.Install(scheme))
}

func initComponents(ctx context.Context, 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(ctx, p))
}

return errs.ErrorOrNil()
}

func main() { //nolint:funlen,maintidx
var metricsAddr string
var enableLeaderElection bool
Expand Down Expand Up @@ -323,6 +340,10 @@ func main() { //nolint:funlen,maintidx
setupLog.Error(err, "unable to set up ready check")
os.Exit(1)
}
if err := initComponents(ctx, 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 87812cd

Please sign in to comment.