Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Talor Itzhak <titzhak@redhat.com>
  • Loading branch information
Tal-or committed Apr 17, 2024
1 parent 582131b commit 0ca7cdf
Show file tree
Hide file tree
Showing 25 changed files with 4,751 additions and 347 deletions.
61 changes: 55 additions & 6 deletions cmd/cluster-node-tuning-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import (
"crypto/tls"
"flag"
"fmt"
"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/controller/performanceprofile/components/handler"
"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/controller/performanceprofile/hypershift"
"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/controller/performanceprofile/status"
"net/http"
"os"
"runtime"
"time"
Expand All @@ -24,6 +28,7 @@ import (
"github.com/spf13/pflag"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
apiruntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
Expand All @@ -35,10 +40,12 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/cluster"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/webhook"

tunedv1 "github.com/openshift/cluster-node-tuning-operator/pkg/apis/tuned/v1"
ntoclient "github.com/openshift/cluster-node-tuning-operator/pkg/client"
"github.com/openshift/cluster-node-tuning-operator/pkg/config"
"github.com/openshift/cluster-node-tuning-operator/pkg/metrics"
"github.com/openshift/cluster-node-tuning-operator/pkg/operator"
Expand All @@ -65,7 +72,10 @@ func init() {

utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(tunedv1.AddToScheme(scheme))
utilruntime.Must(mcov1.AddToScheme(scheme))
if !config.InHyperShift() {
klog.Infof("Running in NOT hypershift")
utilruntime.Must(mcov1.AddToScheme(scheme))
}
utilruntime.Must(apiconfigv1.Install(scheme))
utilruntime.Must(performancev1alpha1.AddToScheme(scheme))
utilruntime.Must(performancev1.AddToScheme(scheme))
Expand Down Expand Up @@ -176,21 +186,60 @@ func operatorRun() {
klog.Exitf("failed to setup feature gates: %v", err)
}
if err = (&paocontroller.PerformanceProfileReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("performance-profile-controller"),
FeatureGate: fg,
Client: mgr.GetClient(),
ManagementClient: mgr.GetClient(),
Recorder: mgr.GetEventRecorderFor("performance-profile-controller"),
FeatureGate: fg,
ComponentsHandler: handler.NewHandler(mgr.GetClient(), mgr.GetScheme()),
StatusWriter: status.NewWriter(mgr.GetClient()),
}).SetupWithManager(mgr); err != nil {
klog.Exitf("unable to create PerformanceProfile controller: %v", err)
}

if err = (&performancev1.PerformanceProfile{}).SetupWebhookWithManager(mgr); err != nil {
klog.Exitf("unable to create PerformanceProfile v1 webhook: %v", err)
}

if err = (&performancev2.PerformanceProfile{}).SetupWebhookWithManager(mgr); err != nil {
klog.Exitf("unable to create PerformanceProfile v2 webhook: %v", err)
}
} else {
// Hypershift configuration
restConfig, err := ntoclient.GetInClusterConfig()
if err != nil {
klog.Exitf("unable to create get InClusterConfiguration while creating PerformanceProfile controller: %v", err)
}

fOps := func(opts *cluster.Options) {
operatorNamespace := config.OperatorNamespace()
opts.Cache.Namespaces = []string{operatorNamespace}
opts.Scheme = mgr.GetScheme()
opts.MapperProvider = func(c *rest.Config, httpClient *http.Client) (meta.RESTMapper, error) {
return mgr.GetRESTMapper(), nil
}
opts.NewClient = func(config *rest.Config, options client.Options) (client.Client, error) {
c, err := client.New(config, options)
if err != nil {
return nil, err
}
return hypershift.NewControlPlanClient(c, operatorNamespace), nil
}
}
managementCluster, err := cluster.New(restConfig, fOps)
if err != nil {
klog.Exitf("unable to create ManagementCluster while creating PerformanceProfile controller : %v", err)
}

if err := mgr.Add(managementCluster); err != nil {
klog.Exitf("unable to add ManagementCluster to manger while creating PerformanceProfile controller : %v", err)
}
if err = (&paocontroller.PerformanceProfileReconciler{
Client: mgr.GetClient(),
ManagementClient: managementCluster.GetClient(),
Recorder: managementCluster.GetEventRecorderFor("performance-profile-controller"),
ComponentsHandler: hypershift.NewHandler(managementCluster.GetClient(), mgr.GetClient(), mgr.GetScheme()),
}).HypershiftSetupWithManager(mgr, managementCluster); err != nil {
klog.Exitf("unable to create PerformanceProfile controller: %v", err)
}
}
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
klog.Exitf("manager exited with non-zero code: %v", err)
Expand Down

0 comments on commit 0ca7cdf

Please sign in to comment.