Skip to content
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,49 @@ import (
"sigs.k8s.io/controller-runtime/pkg/source"
)

var log = logf.Log.WithName("controller_wmc")
const (
// ControllerName is the name of the WMC controller
ControllerName = "windowsmachineconfig-controller"
)

/**
* USER ACTION REQUIRED: This is a scaffold file intended for the user to modify with their own Controller
* business logic. Delete these comments after modifying this file.*
*/
var log = logf.Log.WithName("controller_wmc")

// Add creates a new WindowsMachineConfig Controller and adds it to the Manager. The Manager will set fields on the Controller
// and Start it when the Manager is Started.
func Add(mgr manager.Manager) error {
return add(mgr, newReconciler(mgr))
reconciler, err := newReconciler(mgr)
if err != nil {
return errors.Wrapf(err, "could not create %s reconciler", ControllerName)
}
return add(mgr, reconciler)
}

// newReconciler returns a new reconcile.Reconciler
func newReconciler(mgr manager.Manager) reconcile.Reconciler {
func newReconciler(mgr manager.Manager) (reconcile.Reconciler, error) {
// TODO: This should be moved out to validation for reconciler struct.
// Jira story: https://issues.redhat.com/browse/WINC-277
clientset, err := kubernetes.NewForConfig(mgr.GetConfig())
if err != nil {
log.Error(err, "error while getting clientset")
return nil, errors.Wrap(err, "error creating kubernetes clientset")
}
return &ReconcileWindowsMachineConfig{client: mgr.GetClient(), scheme: mgr.GetScheme(), k8sclientset: clientset}
return &ReconcileWindowsMachineConfig{client: mgr.GetClient(), scheme: mgr.GetScheme(), k8sclientset: clientset},
nil
}

// add adds a new Controller to mgr with r as the reconcile.Reconciler
func add(mgr manager.Manager, r reconcile.Reconciler) error {
// Create a new controller
c, err := controller.New("windowsmachineconfig-controller", mgr, controller.Options{Reconciler: r})
c, err := controller.New(ControllerName, mgr, controller.Options{Reconciler: r})
if err != nil {
return err
return errors.Wrapf(err, "could not create %s", ControllerName)
}
// TODO: Add a predicate here. As of now, we get event notifications for all the WindowsMachineConfig objects, we
// want the predicate to filter the WMC object called `instance`
// Jira Story: https://issues.redhat.com/browse/WINC-282
// Watch for changes to primary resource WindowsMachineConfig
err = c.Watch(&source.Kind{Type: &wmcapi.WindowsMachineConfig{}}, &handler.EnqueueRequestForObject{})
if err != nil {
return err
return errors.Wrap(err, "could not create watch on WindowsMachineConfig objects")
}

// TODO(user): Modify this to be the types you create that are owned by the primary resource
Expand Down Expand Up @@ -145,9 +150,6 @@ func (r *ReconcileWindowsMachineConfig) Reconcile(request reconcile.Request) (re
return reconcile.Result{}, fmt.Errorf("error instantiating cloud provider: %v", err)
}
}
if r.k8sclientset == nil {
return reconcile.Result{}, nil
}
if r.windowsVMs == nil {
// populate the windowsVM map here from ConfigMap as source of truth
r.windowsVMs = make(map[types.WindowsVM]bool)
Expand Down