-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use better way to set up controller with Manager (#27)
- Loading branch information
Showing
4 changed files
with
167 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package controller | ||
|
||
import ( | ||
"github.com/aibrix/aibrix/pkg/controller/modeladapter" | ||
"github.com/aibrix/aibrix/pkg/controller/podautoscaler" | ||
"k8s.io/apimachinery/pkg/api/meta" | ||
"k8s.io/klog/v2" | ||
"sigs.k8s.io/controller-runtime/pkg/manager" | ||
) | ||
|
||
// Borrowed logic from Kruise | ||
// Original source: https://github.com/openkruise/kruise/blob/master/pkg/controller/controllers.go | ||
// Reason: We have single controller-manager as well and use the controller-runtime libraries. | ||
// Instead of registering every controller in the main.go, kruise's registration flow is much cleaner. | ||
|
||
var controllerAddFuncs []func(manager.Manager) error | ||
|
||
func init() { | ||
controllerAddFuncs = append(controllerAddFuncs, podautoscaler.Add) | ||
controllerAddFuncs = append(controllerAddFuncs, modeladapter.Add) | ||
} | ||
|
||
// SetupWithManager sets up the controller with the Manager. | ||
func SetupWithManager(m manager.Manager) error { | ||
for _, f := range controllerAddFuncs { | ||
if err := f(m); err != nil { | ||
if kindMatchErr, ok := err.(*meta.NoKindMatchError); ok { | ||
klog.InfoS("CRD is not installed, its controller will perform noops!", "CRD", kindMatchErr.GroupKind) | ||
continue | ||
} | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters