Skip to content

Commit

Permalink
pao:hypershift: configure controller
Browse files Browse the repository at this point in the history
Add the necessary configuration for the controller, so it would be able to run on a hypershift platform.

1. It needs to configure predicates for ConfigMaps instead of actual objects.
2. It needs to setup different clients for the management cluster and hosted cluster.

Signed-off-by: Talor Itzhak <[email protected]>
  • Loading branch information
Tal-or committed May 15, 2024
1 parent be1e986 commit d2b5184
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions pkg/performanceprofile/controller/performanceprofile_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,54 @@ func (r *PerformanceProfileReconciler) SetupWithManager(mgr ctrl.Manager) error
Complete(r)
}

func (r *PerformanceProfileReconciler) SetupWithManagerForHypershift(mgr ctrl.Manager, managementCluster cluster.Cluster) error {
// Running on hypershift controller should watch for the ConfigMaps created by Hypershift Operator in the
// controller namespace with the right label.
p := predicate.Funcs{
UpdateFunc: func(ue event.UpdateEvent) bool {
if !validateUpdateEvent(&ue) {
klog.InfoS("UpdateEvent NOT VALID", "objectName", ue.ObjectOld.GetName())
return false
}

_, hasLabel := ue.ObjectNew.GetLabels()[controllerGeneratedMachineConfig]
if hasLabel {
klog.InfoS("UpdateEvent has label", "objectName", ue.ObjectOld.GetName(), "label", controllerGeneratedMachineConfig)
}
return hasLabel
},
CreateFunc: func(ce event.CreateEvent) bool {
if ce.Object == nil {
klog.Error("Create event has no runtime object")
return false
}

_, hasLabel := ce.Object.GetLabels()[controllerGeneratedMachineConfig]
if hasLabel {
klog.InfoS("CreateEvent has label", "objectName", ce.Object.GetName(), "label", controllerGeneratedMachineConfig)
}
return hasLabel
},
DeleteFunc: func(de event.DeleteEvent) bool {
if de.Object == nil {
klog.Error("Delete event has no runtime object")
return false
}
_, hasLabel := de.Object.GetLabels()[controllerGeneratedMachineConfig]
if hasLabel {
klog.InfoS("DeleteEvent has label", "objectName", de.Object.GetName(), "label", controllerGeneratedMachineConfig)
}
return hasLabel
},
}

return ctrl.NewControllerManagedBy(mgr).
Named("performanceprofile_controller").
WatchesRawSource(source.Kind(managementCluster.GetCache(), &corev1.ConfigMap{}),
&handler.EnqueueRequestForObject{},
builder.WithPredicates(p)).Complete(r)
}

func (r *PerformanceProfileReconciler) mcpToPerformanceProfile(ctx context.Context, mcpObj client.Object) []reconcile.Request {
mcp := &mcov1.MachineConfigPool{}

Expand Down

0 comments on commit d2b5184

Please sign in to comment.