@@ -22,18 +22,22 @@ import (
2222 "time"
2323
2424 instascale "github.com/project-codeflare/instascale/controllers"
25- mcadoptions "github.com/project-codeflare/multi-cluster-app-dispatcher/cmd/kar-controllers/app/options"
2625 mcadv1beta1 "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1"
26+ mcadconfig "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/config"
2727 mcad "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/controller/queuejob"
2828 "go.uber.org/zap/zapcore"
2929
3030 "k8s.io/apimachinery/pkg/runtime"
3131 utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3232 clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3333 _ "k8s.io/client-go/plugin/pkg/client/auth"
34+ configv1alpha1 "k8s.io/component-base/config/v1alpha1"
35+ "k8s.io/utils/pointer"
3436 ctrl "sigs.k8s.io/controller-runtime"
3537 "sigs.k8s.io/controller-runtime/pkg/healthz"
3638 "sigs.k8s.io/controller-runtime/pkg/log/zap"
39+
40+ "github.com/project-codeflare/codeflare-operator/pkg/config"
3741 // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
3842 // to ensure that exec-entrypoint and run can make use of them.
3943 // +kubebuilder:scaffold:imports
@@ -51,73 +55,60 @@ func init() {
5155
5256func main () {
5357 var metricsAddr string
54- var enableLeaderElection bool
5558 var probeAddr string
56- var configsNamespace string
57- var ocmSecretNamespace string
5859
59- // Operator
6060 flag .StringVar (& metricsAddr , "metrics-bind-address" , ":8080" , "The address the metric endpoint binds to." )
6161 flag .StringVar (& probeAddr , "health-probe-bind-address" , ":8081" , "The address the probe endpoint binds to." )
62- flag .BoolVar (& enableLeaderElection , "leader-elect" , false ,
63- "Enable leader election for controller manager. " +
64- "Enabling this will ensure there is only one active controller manager." )
65-
66- // InstScale
67- flag .StringVar (& configsNamespace , "configs-namespace" , "kube-system" , "The namespace containing the Instacale configmap" )
68- flag .StringVar (& ocmSecretNamespace , "ocm-secret-namespace" , "default" , "The namespace containing the OCM secret" )
69-
70- mcadOptions := mcadoptions .NewServerOption ()
7162
7263 zapOptions := zap.Options {
7364 Development : true ,
7465 TimeEncoder : zapcore .TimeEncoderOfLayout (time .RFC3339 ),
7566 }
76-
77- flagSet := flag .NewFlagSet (os .Args [0 ], flag .ExitOnError )
78- flag .CommandLine .VisitAll (func (f * flag.Flag ) {
79- if f .Name != "kubeconfig" {
80- flagSet .Var (f .Value , f .Name , f .Usage )
81- }
82- })
83-
84- zapOptions .BindFlags (flagSet )
85- mcadOptions .AddFlags (flagSet )
86- _ = flagSet .Parse (os .Args [1 :])
67+ zapOptions .BindFlags (flag .CommandLine )
8768
8869 ctrl .SetLogger (zap .New (zap .UseFlagOptions (& zapOptions )))
8970
9071 ctx := ctrl .SetupSignalHandler ()
9172
73+ cfg := config.CodeFlareOperatorConfiguration {
74+ LeaderElection : & configv1alpha1.LeaderElectionConfiguration {},
75+ MCAD : & mcadconfig.MCADConfiguration {},
76+ InstaScale : & config.InstaScaleConfiguration {},
77+ }
78+
9279 mgr , err := ctrl .NewManager (ctrl .GetConfigOrDie (), ctrl.Options {
93- Scheme : scheme ,
94- MetricsBindAddress : metricsAddr ,
95- Port : 9443 ,
96- HealthProbeBindAddress : probeAddr ,
97- LeaderElection : enableLeaderElection ,
98- LeaderElectionID : "5a3ca514.codeflare.dev" ,
80+ Scheme : scheme ,
81+ MetricsBindAddress : metricsAddr ,
82+ HealthProbeBindAddress : probeAddr ,
83+ LeaderElection : pointer .BoolDeref (cfg .LeaderElection .LeaderElect , false ),
84+ LeaderElectionID : cfg .LeaderElection .ResourceName ,
85+ LeaderElectionNamespace : cfg .LeaderElection .ResourceNamespace ,
86+ LeaderElectionResourceLock : cfg .LeaderElection .ResourceLock ,
87+ LeaseDuration : & cfg .LeaderElection .LeaseDuration .Duration ,
88+ RetryPeriod : & cfg .LeaderElection .RetryPeriod .Duration ,
89+ RenewDeadline : & cfg .LeaderElection .RenewDeadline .Duration ,
9990 })
10091 if err != nil {
10192 setupLog .Error (err , "unable to start manager" )
10293 os .Exit (1 )
10394 }
10495
105- mcadQueueController := mcad .NewJobController (mgr .GetConfig (), mcadOptions )
96+ mcadQueueController := mcad .NewJobController (mgr .GetConfig (), cfg . MCAD , & mcadconfig. MCADConfigurationExtended {} )
10697 if mcadQueueController == nil {
10798 // FIXME: update NewJobController so it follows Go idiomatic error handling and return an error instead of a nil object
10899 os .Exit (1 )
109100 }
110101 mcadQueueController .Run (ctx .Done ())
111102
112- instascaleController := & instascale.AppWrapperReconciler {
113- Client : mgr .GetClient (),
114- Scheme : mgr .GetScheme (),
115- ConfigsNamespace : configsNamespace ,
116- OcmSecretNamespace : ocmSecretNamespace ,
103+ if pointer .BoolDeref (cfg .InstaScale .Enabled , false ) {
104+ instaScaleController := & instascale.AppWrapperReconciler {
105+ Client : mgr .GetClient (),
106+ Scheme : mgr .GetScheme (),
107+ Config : cfg .InstaScale .InstaScaleConfiguration ,
108+ }
109+ exitOnError (instaScaleController .SetupWithManager (mgr ), "Error setting up InstaScale controller" )
117110 }
118111
119- exitOnError (instascaleController .SetupWithManager (mgr ), "Error setting up InstaScale controller" )
120-
121112 if err := mgr .AddHealthzCheck ("healthz" , healthz .Ping ); err != nil {
122113 setupLog .Error (err , "unable to set up health check" )
123114 os .Exit (1 )
0 commit comments