Skip to content
Open
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
13 changes: 7 additions & 6 deletions controllers/controllers_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ var _ = BeforeSuite(func() {
fakeRecorder = record.NewFakeRecorder(20)
// Create a ReconcileNodeMaintenance object with the scheme and fake client
r = &NodeMaintenanceReconciler{
Client: k8sClient,
Scheme: scheme.Scheme,
MgrConfig: cfg,
LeaseManager: &mockLeaseManager{mockManager},
Recorder: fakeRecorder,
logger: ctrl.Log.WithName("unit test"),
Client: k8sClient,
Scheme: scheme.Scheme,
MgrConfig: cfg,
LeaseManager: &mockLeaseManager{mockManager},
Recorder: fakeRecorder,
logger: ctrl.Log.WithName("unit test"),
MaxConcurrentReconciles: 1,
}
ctx, cancel = context.WithCancel(ctrl.SetupSignalHandler())
drainer, err = createDrainer(ctx, cfg)
Expand Down
6 changes: 6 additions & 0 deletions controllers/nodemaintenance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/go-logr/logr"
commonLabels "github.com/medik8s/common/pkg/labels"
"github.com/medik8s/common/pkg/lease"
"sigs.k8s.io/controller-runtime/pkg/controller"

corev1 "k8s.io/api/core/v1"
apiErrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -67,11 +68,16 @@ type NodeMaintenanceReconciler struct {
LeaseManager lease.Manager
Recorder record.EventRecorder
logger logr.Logger

MaxConcurrentReconciles int
}

// SetupWithManager sets up the controller with the Manager.
func (r *NodeMaintenanceReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
WithOptions(controller.Options{
MaxConcurrentReconciles: r.MaxConcurrentReconciles,
}).
For(&v1beta1.NodeMaintenance{}).
Complete(r)
}
Expand Down
31 changes: 16 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const (
WebhookCertDir = "/apiserver.local.config/certificates"
WebhookCertName = "apiserver.crt"
WebhookKeyName = "apiserver.key"
operatorName = "NodeMaintenance"
operatorName = "NodeMaintenance"
)

var (
Expand All @@ -69,16 +69,18 @@ func init() {

func main() {
var (
metricsAddr, probeAddr string
metricsAddr, probeAddr string
enableLeaderElection, enableHTTP2 bool
webhookOpts webhook.Options
)
webhookOpts webhook.Options
maxConcurrentReconciles int
)
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.BoolVar(&enableHTTP2, "enable-http2", false, "If HTTP/2 should be enabled for the metrics and webhook servers.")
flag.IntVar(&maxConcurrentReconciles, "max-concurrent-reconciles", 1, "The number of max concurrent reconciles")

opts := zap.Options{
Development: true,
Expand All @@ -94,7 +96,7 @@ func main() {
configureWebhookOpts(&webhookOpts, enableHTTP2)

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
Scheme: scheme,
WebhookServer: webhook.NewServer(webhookOpts),
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
Expand All @@ -105,31 +107,30 @@ func main() {
os.Exit(1)
}


cl := mgr.GetClient()
leaseManagerInitializer := &leaseManagerInitializer{cl: cl}
if err := mgr.Add(leaseManagerInitializer); err != nil {
setupLog.Error(err, "unable to set up lease Manager", "lease", operatorName)
os.Exit(1)
}
openshiftCheck,err := utils.NewOpenshiftValidator(mgr.GetConfig())

openshiftCheck, err := utils.NewOpenshiftValidator(mgr.GetConfig())
if err != nil {
setupLog.Error(err, "failed to check if we run on Openshift")
os.Exit(1)
}
isOpenShift := openshiftCheck.IsOpenshiftSupported()
if isOpenShift{
if isOpenShift {
setupLog.Info("NMO was installed on Openshift cluster")
}


if err = (&controllers.NodeMaintenanceReconciler{
Client: cl,
Scheme: mgr.GetScheme(),
MgrConfig: mgr.GetConfig(),
LeaseManager: leaseManagerInitializer,
Recorder: mgr.GetEventRecorderFor(operatorName),
Client: cl,
Scheme: mgr.GetScheme(),
MgrConfig: mgr.GetConfig(),
LeaseManager: leaseManagerInitializer,
Recorder: mgr.GetEventRecorderFor(operatorName),
MaxConcurrentReconciles: maxConcurrentReconciles,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", operatorName)
os.Exit(1)
Expand Down