Skip to content

Commit

Permalink
Working reconcile across clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
Kidswiss committed Dec 4, 2024
1 parent f178e04 commit 19524bf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
16 changes: 8 additions & 8 deletions cmd/sliexporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,18 @@ func (s *sliProber) executeSLIProber(cmd *cobra.Command, _ []string) error {

if utils.IsKindAvailable(managedupgradev1beta1.GroupVersion, "UpgradeJob", config) {
log.Info("Enable OC maintenance observer")
serviceCluster, err := getServiceCluster()
serviceCluster, err := getServiceCluster(config)
if err != nil {
return err
}
if err = maintenanceRecociler.SetupWithManager(mgr, serviceCluster); err != nil {
log.Error(err, "unable to create controller", "controller", "Maintenance Observer")
return err
}
err = mgr.Add(*serviceCluster)
if err != nil {
return err
}
}
if utils.IsKindAvailable(vshnv1.GroupVersion, "XVSHNMariaDB", ctrl.GetConfigOrDie()) {
log.Info("Enabling VSHNMariaDB controller")
Expand Down Expand Up @@ -198,19 +202,15 @@ func (s *sliProber) executeSLIProber(cmd *cobra.Command, _ []string) error {
return nil
}

// serviceCluster will create an incluster config by default.
// If serviceKubeConfig is set, it will use that instead.
func getServiceCluster() (*cluster.Cluster, error) {
config, err := getServiceClusterConfig()
if err != nil {
return nil, err
}
func getServiceCluster(config *rest.Config) (*cluster.Cluster, error) {
serviceCluster, err := cluster.New(config, func(o *cluster.Options) {
o.Scheme = pkg.SetupScheme()
})
return &serviceCluster, err
}

// getServiceClusterConfig will create an incluster config by default.
// If serviceKubeConfig is set, it will use that instead.
func getServiceClusterConfig() (*rest.Config, error) {

if s.serviceKubeConfig != "" {
Expand Down
6 changes: 5 additions & 1 deletion pkg/sliexporter/maintenance_controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,12 @@ func (r *MaintenanceReconciler) jobState(job managedupgradev1beta1.UpgradeJob) s
func (r *MaintenanceReconciler) SetupWithManager(mgr ctrl.Manager, serviceCluster *cluster.Cluster) error {
sc := *serviceCluster

// For external reconcile triggers we can't register a kind via `For()`
// instead we have to name the reconciler something
// usually the name is the lowercase of the kind
// so that's what I've used here.
return ctrl.NewControllerManagedBy(mgr).
For(&managedupgradev1beta1.UpgradeJob{}).
Named("upgradejob").
// This is the magic sauce, it makes the reconciler reconcile on events happening on the serviceCluster
WatchesRawSource(source.Kind(sc.GetCache(), &managedupgradev1beta1.UpgradeJob{}, &handler.TypedEnqueueRequestForObject[*managedupgradev1beta1.UpgradeJob]{})).
Complete(r)
Expand Down

0 comments on commit 19524bf

Please sign in to comment.