Skip to content
Merged
Show file tree
Hide file tree
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
39 changes: 11 additions & 28 deletions cmd/openmcp-operator/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ func NewOpenMCPOperatorCommand(ctx context.Context) *cobra.Command {

so := &SharedOptions{
RawSharedOptions: &RawSharedOptions{},
Clusters: &Clusters{
Onboarding: clusters.New("onboarding"),
Platform: clusters.New("platform"),
},
PlatformCluster: clusters.New("platform"),
}
so.AddPersistentFlags(cmd)
cmd.AddCommand(NewInitCommand(so))
Expand All @@ -39,16 +36,15 @@ func NewOpenMCPOperatorCommand(ctx context.Context) *cobra.Command {
}

type RawSharedOptions struct {
Environment string `json:"environment"`
DryRun bool `json:"dry-run"`
ConfigPaths []string `json:"configPaths"`
OnboardingClusterKubeconfigPath string `json:"onboarding-cluster"` // dummy for printing, actual path is in Clusters
PlatformClusterKubeconfigPath string `json:"platform-cluster"` // dummy for printing, actual path is in Clusters
Environment string `json:"environment"`
DryRun bool `json:"dry-run"`
ConfigPaths []string `json:"configPaths"`
PlatformClusterKubeconfigPath string `json:"kubeconfig"` // dummy for printing, actual path is in Clusters
}

type SharedOptions struct {
*RawSharedOptions
Clusters *Clusters
PlatformCluster *clusters.Cluster

// fields filled in Complete()
Log logging.Logger
Expand All @@ -59,8 +55,7 @@ func (o *SharedOptions) AddPersistentFlags(cmd *cobra.Command) {
// logging
logging.InitFlags(cmd.PersistentFlags())
// clusters
o.Clusters.Onboarding.RegisterConfigPathFlag(cmd.PersistentFlags())
o.Clusters.Platform.RegisterConfigPathFlag(cmd.PersistentFlags())
o.PlatformCluster.RegisterSingleConfigPathFlag(cmd.PersistentFlags())
// environment
cmd.PersistentFlags().StringVar(&o.Environment, "environment", "", "Environment name. Required. This is used to distinguish between different environments that are watching the same Onboarding cluster. Must be globally unique.")
// config
Expand All @@ -84,10 +79,7 @@ func (o *SharedOptions) Complete() error {
ctrl.SetLogger(o.Log.Logr())

// construct cluster clients
if err := o.Clusters.Platform.InitializeRESTConfig(); err != nil {
return err
}
if err := o.Clusters.Onboarding.InitializeRESTConfig(); err != nil {
if err := o.PlatformCluster.InitializeRESTConfig(); err != nil {
return err
}

Expand Down Expand Up @@ -115,15 +107,9 @@ func (o *SharedOptions) Complete() error {
return nil
}

type Clusters struct {
Onboarding *clusters.Cluster
Platform *clusters.Cluster
}

func (o *SharedOptions) PrintRaw(cmd *cobra.Command) {
// fill dummy paths
o.OnboardingClusterKubeconfigPath = o.Clusters.Onboarding.ConfigPath()
o.PlatformClusterKubeconfigPath = o.Clusters.Platform.ConfigPath()
o.PlatformClusterKubeconfigPath = o.PlatformCluster.ConfigPath()

data, err := yaml.Marshal(o.RawSharedOptions)
if err != nil {
Expand All @@ -135,11 +121,8 @@ func (o *SharedOptions) PrintRaw(cmd *cobra.Command) {

func (o *SharedOptions) PrintCompleted(cmd *cobra.Command) {
raw := map[string]any{
"clusters": map[string]any{
"onboarding": o.Clusters.Onboarding.APIServerEndpoint(),
"platform": o.Clusters.Platform.APIServerEndpoint(),
},
"config": o.Config,
"platformCluster": o.PlatformCluster.APIServerEndpoint(),
"config": o.Config,
}
data, err := yaml.Marshal(raw)
if err != nil {
Expand Down
9 changes: 2 additions & 7 deletions cmd/openmcp-operator/app/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ func (o *InitOptions) Complete(ctx context.Context) error {
}

func (o *InitOptions) Run(ctx context.Context) error {
if err := o.Clusters.Onboarding.InitializeClient(install.InstallCRDAPIs(runtime.NewScheme())); err != nil {
return err
}
if err := o.Clusters.Platform.InitializeClient(install.InstallCRDAPIs(runtime.NewScheme())); err != nil {
if err := o.PlatformCluster.InitializeClient(install.InstallCRDAPIs(runtime.NewScheme())); err != nil {
return err
}

Expand All @@ -77,9 +74,7 @@ func (o *InitOptions) Run(ctx context.Context) error {

// apply CRDs
crdManager := crdutil.NewCRDManager(apiconst.ClusterLabel, crds.CRDs)

crdManager.AddCRDLabelToClusterMapping(clustersv1alpha1.PURPOSE_ONBOARDING, o.Clusters.Onboarding)
crdManager.AddCRDLabelToClusterMapping(clustersv1alpha1.PURPOSE_PLATFORM, o.Clusters.Platform)
crdManager.AddCRDLabelToClusterMapping(clustersv1alpha1.PURPOSE_PLATFORM, o.PlatformCluster)

if err := crdManager.CreateOrUpdateCRDs(ctx, &log); err != nil {
return fmt.Errorf("error creating/updating CRDs: %w", err)
Expand Down
15 changes: 4 additions & 11 deletions cmd/openmcp-operator/app/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,7 @@ func (o *RunOptions) PrintCompletedOptions(cmd *cobra.Command) {
}

func (o *RunOptions) Run(ctx context.Context) error {
if err := o.Clusters.Onboarding.InitializeClient(install.InstallOperatorAPIs(runtime.NewScheme())); err != nil {
return err
}
if err := o.Clusters.Platform.InitializeClient(install.InstallOperatorAPIs(runtime.NewScheme())); err != nil {
if err := o.PlatformCluster.InitializeClient(install.InstallOperatorAPIs(runtime.NewScheme())); err != nil {
return err
}

Expand All @@ -263,7 +260,7 @@ func (o *RunOptions) Run(ctx context.Context) error {
TLSOpts: o.WebhookTLSOpts,
})

mgr, err := ctrl.NewManager(o.Clusters.Platform.RESTConfig(), ctrl.Options{
mgr, err := ctrl.NewManager(o.PlatformCluster.RESTConfig(), ctrl.Options{
Scheme: install.InstallOperatorAPIs(runtime.NewScheme()),
Metrics: o.MetricsServerOptions,
WebhookServer: webhookServer,
Expand All @@ -286,14 +283,10 @@ func (o *RunOptions) Run(ctx context.Context) error {
if err != nil {
return fmt.Errorf("unable to create manager: %w", err)
}
// add onboarding cluster to manager
if err := mgr.Add(o.Clusters.Onboarding.Cluster()); err != nil {
return fmt.Errorf("unable to add onboarding cluster to manager: %w", err)
}

// setup cluster scheduler
if slices.Contains(o.Controllers, strings.ToLower(scheduler.ControllerName)) {
sc, err := scheduler.NewClusterScheduler(&setupLog, o.Clusters.Platform, o.Config.Scheduler)
sc, err := scheduler.NewClusterScheduler(&setupLog, o.PlatformCluster, o.Config.Scheduler)
if err != nil {
return fmt.Errorf("unable to initialize cluster scheduler: %w", err)
}
Expand All @@ -308,7 +301,7 @@ func (o *RunOptions) Run(ctx context.Context) error {
if o.Config != nil {
arConfig = o.Config.AccessRequest
}
if err := accessrequest.NewAccessRequestReconciler(o.Clusters.Platform, arConfig).SetupWithManager(mgr); err != nil {
if err := accessrequest.NewAccessRequestReconciler(o.PlatformCluster, arConfig).SetupWithManager(mgr); err != nil {
return fmt.Errorf("unable to setup accessrequest controller: %w", err)
}
}
Expand Down