Skip to content

Allow users to specify instascale configmap namespace #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
24 changes: 14 additions & 10 deletions controllers/appwrapper_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ package controllers
import (
"context"
"fmt"
"strconv"

"os"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -49,7 +48,8 @@ import (
// AppWrapperReconciler reconciles a AppWrapper object
type AppWrapperReconciler struct {
client.Client
Scheme *runtime.Scheme
Scheme *runtime.Scheme
ConfigmapNamespace string
}

//var nodeCache []string
Expand Down Expand Up @@ -118,17 +118,21 @@ func (r *AppWrapperReconciler) Reconcile(ctx context.Context, req ctrl.Request)
informer := factory.Machine().V1beta1().MachineSets().Informer()
msLister = factory.Machine().V1beta1().MachineSets().Lister()
machineLister = factory.Machine().V1beta1().Machines().Lister()
nodesTobeadded, err := kubeClient.CoreV1().ConfigMaps("kube-system").Get(ctx, "instascale-config", metav1.GetOptions{})
instascaleConfigs, err := kubeClient.CoreV1().ConfigMaps(r.ConfigmapNamespace).Get(ctx, "instascale-config", metav1.GetOptions{})
if err != nil {
klog.Infof("Config map named instascale-config is not available in namespace kube-system")
klog.Infof("Config map named instascale-config is not available in namespace %v", r.ConfigmapNamespace)
}
for _, v := range nodesTobeadded.Data {
if maxScaleNodesAllowed, err = strconv.Atoi(v); err != nil {
klog.Infof("Error configuring value of configmap %v using value 3", maxScaleNodesAllowed)
maxScaleNodesAllowed = 3

for key, value := range instascaleConfigs.Data {
if key == "maxScaleoutAllowed" {
if maxScaleNodesAllowed, err = strconv.Atoi(value); err != nil {
klog.Infof("Error converting %v to int. Setting maxScaleNodesAllowed to 3", maxScaleNodesAllowed)
maxScaleNodesAllowed = 3
}
}
}
klog.Infof("Got config map named: %v that configures max nodes in cluster to value %v", nodesTobeadded.Name, maxScaleNodesAllowed)
klog.Infof("Got config map named %v from namespace %v that configures max nodes in cluster to value %v", instascaleConfigs.Name, instascaleConfigs.Namespace, maxScaleNodesAllowed)

stopper := make(chan struct{})
defer close(stopper)
informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
Expand Down
11 changes: 7 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (

"github.com/project-codeflare/instascale/controllers"
//+kubebuilder:scaffold:imports
mygroupv1beta1 "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1"
mcadv1beta1 "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1"
)

var (
Expand All @@ -45,15 +45,17 @@ func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))

//+kubebuilder:scaffold:scheme
_ = mygroupv1beta1.AddToScheme(scheme)
_ = mcadv1beta1.AddToScheme(scheme)
}

func main() {
var metricsAddr string
var enableLeaderElection bool
var probeAddr string
var configmapNamespace string
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.StringVar(&configmapNamespace, "configmap-namespace", "kube-system", "The namespace containing the InstaScale configmap")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
Expand All @@ -79,8 +81,9 @@ func main() {
}

if err = (&controllers.AppWrapperReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
ConfigmapNamespace: configmapNamespace,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "AppWrapper")
os.Exit(1)
Expand Down