From 6e8d572b21b919913f5eec91079f3bd9fd012717 Mon Sep 17 00:00:00 2001 From: Mohamed Mahmoud Date: Tue, 28 May 2024 13:11:49 -0400 Subject: [PATCH] misc update to handle old apis Signed-off-by: Mohamed Mahmoud --- cmd/bpfman-agent/main.go | 47 ++++++++++++++----- cmd/bpfman-operator/main.go | 35 ++++++++++---- controllers/bpfman-agent/fentry-program.go | 3 +- controllers/bpfman-agent/fexit-program.go | 3 +- controllers/bpfman-agent/kprobe-program.go | 3 +- controllers/bpfman-agent/tc-program.go | 10 ++-- .../bpfman-agent/tracepoint-program.go | 8 ++-- controllers/bpfman-agent/uprobe-program.go | 10 ++-- controllers/bpfman-agent/xdp-program.go | 10 ++-- controllers/bpfman-operator/fentry-program.go | 8 ++-- controllers/bpfman-operator/fexit-program.go | 8 ++-- controllers/bpfman-operator/kprobe-program.go | 8 ++-- controllers/bpfman-operator/tc-program.go | 8 ++-- .../bpfman-operator/tracepoint-program.go | 8 ++-- controllers/bpfman-operator/uprobe-program.go | 8 ++-- controllers/bpfman-operator/xdp-program.go | 8 ++-- go.mod | 5 +- pkg/helpers/helpers.go | 36 +++++++------- 18 files changed, 118 insertions(+), 108 deletions(-) diff --git a/cmd/bpfman-agent/main.go b/cmd/bpfman-agent/main.go index c4554016c..c9ca38e89 100644 --- a/cmd/bpfman-agent/main.go +++ b/cmd/bpfman-agent/main.go @@ -18,28 +18,30 @@ package main import ( "context" + "crypto/tls" "flag" "fmt" "os" - "go.uber.org/zap/zapcore" - _ "k8s.io/client-go/plugin/pkg/client/auth" + bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1" + bpfmanagent "github.com/bpfman/bpfman-operator/controllers/bpfman-agent" + "github.com/bpfman/bpfman-operator/internal/conn" + gobpfman "github.com/bpfman/bpfman/clients/gobpfman/v1" + + "go.uber.org/zap/zapcore" "google.golang.org/grpc/credentials/insecure" + v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" clientgoscheme "k8s.io/client-go/kubernetes/scheme" + _ "k8s.io/client-go/plugin/pkg/client/auth" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/healthz" "sigs.k8s.io/controller-runtime/pkg/log/zap" - - bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1" - bpfmanagent "github.com/bpfman/bpfman-operator/controllers/bpfman-agent" - - "github.com/bpfman/bpfman-operator/internal/conn" - gobpfman "github.com/bpfman/bpfman/clients/gobpfman/v1" - v1 "k8s.io/api/core/v1" + "sigs.k8s.io/controller-runtime/pkg/metrics/server" + "sigs.k8s.io/controller-runtime/pkg/webhook" //+kubebuilder:scaffold:imports ) @@ -59,8 +61,11 @@ func main() { var metricsAddr string var probeAddr string var opts zap.Options + var enableHTTP2 bool + flag.StringVar(&metricsAddr, "metrics-bind-address", ":8174", "The address the metric endpoint binds to.") flag.StringVar(&probeAddr, "health-probe-bind-address", ":8175", "The address the probe endpoint binds to.") + flag.BoolVar(&enableHTTP2, "enable-http2", enableHTTP2, "If HTTP/2 should be enabled for the metrics and webhook servers.") flag.Parse() // Get the Log level for bpfman deployment where this pod is running @@ -85,16 +90,32 @@ func main() { } } + disableHTTP2 := func(c *tls.Config) { + if enableHTTP2 { + return + } + c.NextProtos = []string{"http/1.1"} + } + ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts))) mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ - Scheme: scheme, - MetricsBindAddress: metricsAddr, - Port: 9443, + Scheme: scheme, + Metrics: server.Options{ + BindAddress: metricsAddr, + TLSOpts: []func(*tls.Config){disableHTTP2}, + }, + WebhookServer: webhook.NewServer(webhook.Options{ + Port: 9443, + TLSOpts: []func(*tls.Config){disableHTTP2}, + }), HealthProbeBindAddress: probeAddr, LeaderElection: false, // Specify that Secrets's should not be cached. - ClientDisableCacheFor: []client.Object{&v1.Secret{}}, + Client: client.Options{Cache: &client.CacheOptions{ + DisableFor: []client.Object{&v1.Secret{}}, + }, + }, }) if err != nil { setupLog.Error(err, "unable to start manager") diff --git a/cmd/bpfman-operator/main.go b/cmd/bpfman-operator/main.go index 944a5bcbe..decf2eafd 100644 --- a/cmd/bpfman-operator/main.go +++ b/cmd/bpfman-operator/main.go @@ -17,22 +17,24 @@ limitations under the License. package main import ( + "crypto/tls" "flag" "os" - "go.uber.org/zap/zapcore" - _ "k8s.io/client-go/plugin/pkg/client/auth" + bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1" + bpfmanoperator "github.com/bpfman/bpfman-operator/controllers/bpfman-operator" + "github.com/bpfman/bpfman-operator/internal" + "go.uber.org/zap/zapcore" "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" clientgoscheme "k8s.io/client-go/kubernetes/scheme" + _ "k8s.io/client-go/plugin/pkg/client/auth" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/healthz" "sigs.k8s.io/controller-runtime/pkg/log/zap" - - bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1" - bpfmanoperator "github.com/bpfman/bpfman-operator/controllers/bpfman-operator" - "github.com/bpfman/bpfman-operator/internal" + "sigs.k8s.io/controller-runtime/pkg/metrics/server" + "sigs.k8s.io/controller-runtime/pkg/webhook" //+kubebuilder:scaffold:imports ) @@ -52,11 +54,13 @@ func main() { var enableLeaderElection bool var probeAddr string var opts zap.Options + var enableHTTP2 bool flag.StringVar(&metricsAddr, "metrics-bind-address", ":8174", "The address the metric endpoint binds to.") flag.StringVar(&probeAddr, "health-probe-bind-address", ":8175", "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", enableHTTP2, "If HTTP/2 should be enabled for the metrics and webhook servers.") flag.Parse() // Get the Log level for bpfman deployment where this pod is running @@ -81,12 +85,25 @@ func main() { } } + disableHTTP2 := func(c *tls.Config) { + if enableHTTP2 { + return + } + c.NextProtos = []string{"http/1.1"} + } + ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts))) mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ - Scheme: scheme, - MetricsBindAddress: metricsAddr, - Port: 9443, + Scheme: scheme, + Metrics: server.Options{ + BindAddress: metricsAddr, + TLSOpts: []func(*tls.Config){disableHTTP2}, + }, + WebhookServer: webhook.NewServer(webhook.Options{ + Port: 9443, + TLSOpts: []func(*tls.Config){disableHTTP2}, + }), HealthProbeBindAddress: probeAddr, LeaderElection: enableLeaderElection, LeaderElectionID: "8730d955.bpfman.io", diff --git a/controllers/bpfman-agent/fentry-program.go b/controllers/bpfman-agent/fentry-program.go index 8322d3c90..1d6e59ff4 100644 --- a/controllers/bpfman-agent/fentry-program.go +++ b/controllers/bpfman-agent/fentry-program.go @@ -34,7 +34,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/predicate" - "sigs.k8s.io/controller-runtime/pkg/source" ) //+kubebuilder:rbac:groups=bpfman.io,resources=fentryprograms,verbs=get;list;watch @@ -98,7 +97,7 @@ func (r *FentryProgramReconciler) SetupWithManager(mgr ctrl.Manager) error { // make the FentryProgram no longer select the Node. Additionally only // care about node events specific to our node Watches( - &source.Kind{Type: &v1.Node{}}, + &v1.Node{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(predicate.And(predicate.LabelChangedPredicate{}, nodePredicate(r.NodeName))), ). diff --git a/controllers/bpfman-agent/fexit-program.go b/controllers/bpfman-agent/fexit-program.go index 39b21e87e..e78cd6ad4 100644 --- a/controllers/bpfman-agent/fexit-program.go +++ b/controllers/bpfman-agent/fexit-program.go @@ -34,7 +34,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/predicate" - "sigs.k8s.io/controller-runtime/pkg/source" ) //+kubebuilder:rbac:groups=bpfman.io,resources=fexitprograms,verbs=get;list;watch @@ -98,7 +97,7 @@ func (r *FexitProgramReconciler) SetupWithManager(mgr ctrl.Manager) error { // make the FexitProgram no longer select the Node. Additionally only // care about node events specific to our node Watches( - &source.Kind{Type: &v1.Node{}}, + &v1.Node{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(predicate.And(predicate.LabelChangedPredicate{}, nodePredicate(r.NodeName))), ). diff --git a/controllers/bpfman-agent/kprobe-program.go b/controllers/bpfman-agent/kprobe-program.go index 9fcedb91e..18ace44f9 100644 --- a/controllers/bpfman-agent/kprobe-program.go +++ b/controllers/bpfman-agent/kprobe-program.go @@ -34,7 +34,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/predicate" - "sigs.k8s.io/controller-runtime/pkg/source" ) //+kubebuilder:rbac:groups=bpfman.io,resources=kprobeprograms,verbs=get;list;watch @@ -98,7 +97,7 @@ func (r *KprobeProgramReconciler) SetupWithManager(mgr ctrl.Manager) error { // make the KprobeProgram no longer select the Node. Additionally only // care about node events specific to our node Watches( - &source.Kind{Type: &v1.Node{}}, + &v1.Node{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(predicate.And(predicate.LabelChangedPredicate{}, nodePredicate(r.NodeName))), ). diff --git a/controllers/bpfman-agent/tc-program.go b/controllers/bpfman-agent/tc-program.go index ac5b04437..21386cd2a 100644 --- a/controllers/bpfman-agent/tc-program.go +++ b/controllers/bpfman-agent/tc-program.go @@ -22,17 +22,15 @@ import ( "k8s.io/apimachinery/pkg/types" + bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1" + bpfmanagentinternal "github.com/bpfman/bpfman-operator/controllers/bpfman-agent/internal" + "github.com/bpfman/bpfman-operator/internal" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/builder" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/predicate" - "sigs.k8s.io/controller-runtime/pkg/source" - - bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1" - bpfmanagentinternal "github.com/bpfman/bpfman-operator/controllers/bpfman-agent/internal" - "github.com/bpfman/bpfman-operator/internal" gobpfman "github.com/bpfman/bpfman/clients/gobpfman/v1" v1 "k8s.io/api/core/v1" @@ -145,7 +143,7 @@ func (r *TcProgramReconciler) SetupWithManager(mgr ctrl.Manager) error { // make the TcProgram no longer select the Node. Additionally only // care about events specific to our node Watches( - &source.Kind{Type: &v1.Node{}}, + &v1.Node{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(predicate.And(predicate.LabelChangedPredicate{}, nodePredicate(r.NodeName))), ). diff --git a/controllers/bpfman-agent/tracepoint-program.go b/controllers/bpfman-agent/tracepoint-program.go index 0bfbb1bd4..dc07ca655 100644 --- a/controllers/bpfman-agent/tracepoint-program.go +++ b/controllers/bpfman-agent/tracepoint-program.go @@ -23,16 +23,14 @@ import ( "k8s.io/apimachinery/pkg/types" + bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1" + bpfmanagentinternal "github.com/bpfman/bpfman-operator/controllers/bpfman-agent/internal" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/builder" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/predicate" - "sigs.k8s.io/controller-runtime/pkg/source" - - bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1" - bpfmanagentinternal "github.com/bpfman/bpfman-operator/controllers/bpfman-agent/internal" internal "github.com/bpfman/bpfman-operator/internal" gobpfman "github.com/bpfman/bpfman/clients/gobpfman/v1" @@ -100,7 +98,7 @@ func (r *TracepointProgramReconciler) SetupWithManager(mgr ctrl.Manager) error { // make the TracepointProgram no longer select the Node. Additionally only // care about node events specific to our node Watches( - &source.Kind{Type: &v1.Node{}}, + &v1.Node{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(predicate.And(predicate.LabelChangedPredicate{}, nodePredicate(r.NodeName))), ). diff --git a/controllers/bpfman-agent/uprobe-program.go b/controllers/bpfman-agent/uprobe-program.go index ddf24d52c..8e9ae980e 100644 --- a/controllers/bpfman-agent/uprobe-program.go +++ b/controllers/bpfman-agent/uprobe-program.go @@ -24,16 +24,14 @@ import ( "k8s.io/apimachinery/pkg/types" + bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1" + bpfmanagentinternal "github.com/bpfman/bpfman-operator/controllers/bpfman-agent/internal" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/builder" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/predicate" - "sigs.k8s.io/controller-runtime/pkg/source" - - bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1" - bpfmanagentinternal "github.com/bpfman/bpfman-operator/controllers/bpfman-agent/internal" internal "github.com/bpfman/bpfman-operator/internal" gobpfman "github.com/bpfman/bpfman/clients/gobpfman/v1" @@ -102,13 +100,13 @@ func (r *UprobeProgramReconciler) SetupWithManager(mgr ctrl.Manager) error { // for when uprobes are attached inside containers. In both cases, only // care about events specific to our node Watches( - &source.Kind{Type: &v1.Node{}}, + &v1.Node{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(predicate.And(predicate.LabelChangedPredicate{}, nodePredicate(r.NodeName))), ). // Watch for changes in Pod resources in case we are using a container selector. Watches( - &source.Kind{Type: &v1.Pod{}}, + &v1.Pod{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(podOnNodePredicate(r.NodeName)), ). diff --git a/controllers/bpfman-agent/xdp-program.go b/controllers/bpfman-agent/xdp-program.go index f71e5ddda..484a93278 100644 --- a/controllers/bpfman-agent/xdp-program.go +++ b/controllers/bpfman-agent/xdp-program.go @@ -20,17 +20,15 @@ import ( "context" "fmt" + bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1" + bpfmanagentinternal "github.com/bpfman/bpfman-operator/controllers/bpfman-agent/internal" + internal "github.com/bpfman/bpfman-operator/internal" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/builder" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/predicate" - "sigs.k8s.io/controller-runtime/pkg/source" - - bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1" - bpfmanagentinternal "github.com/bpfman/bpfman-operator/controllers/bpfman-agent/internal" - internal "github.com/bpfman/bpfman-operator/internal" gobpfman "github.com/bpfman/bpfman/clients/gobpfman/v1" v1 "k8s.io/api/core/v1" @@ -129,7 +127,7 @@ func (r *XdpProgramReconciler) SetupWithManager(mgr ctrl.Manager) error { // make the XdpProgram no longer select the Node. Additionally only // care about node events specific to our node Watches( - &source.Kind{Type: &v1.Node{}}, + &v1.Node{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(predicate.And(predicate.LabelChangedPredicate{}, nodePredicate(r.NodeName))), ). diff --git a/controllers/bpfman-operator/fentry-program.go b/controllers/bpfman-operator/fentry-program.go index ed50b8aeb..68f7d3c3b 100644 --- a/controllers/bpfman-operator/fentry-program.go +++ b/controllers/bpfman-operator/fentry-program.go @@ -24,13 +24,11 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/builder" + bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1" + "github.com/bpfman/bpfman-operator/internal" "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/predicate" - "sigs.k8s.io/controller-runtime/pkg/source" - - bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1" - "github.com/bpfman/bpfman-operator/internal" ) //+kubebuilder:rbac:groups=bpfman.io,resources=fentryprograms,verbs=get;list;watch;create;update;patch;delete @@ -55,7 +53,7 @@ func (r *FentryProgramReconciler) SetupWithManager(mgr ctrl.Manager) error { For(&bpfmaniov1alpha1.FentryProgram{}). // Watch bpfPrograms which are owned by FentryPrograms Watches( - &source.Kind{Type: &bpfmaniov1alpha1.BpfProgram{}}, + &bpfmaniov1alpha1.BpfProgram{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(predicate.And(statusChangedPredicate(), internal.BpfProgramTypePredicate(internal.FentryString))), ). diff --git a/controllers/bpfman-operator/fexit-program.go b/controllers/bpfman-operator/fexit-program.go index 8543de9b8..4578bd0d6 100644 --- a/controllers/bpfman-operator/fexit-program.go +++ b/controllers/bpfman-operator/fexit-program.go @@ -24,13 +24,11 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/builder" + bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1" + "github.com/bpfman/bpfman-operator/internal" "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/predicate" - "sigs.k8s.io/controller-runtime/pkg/source" - - bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1" - "github.com/bpfman/bpfman-operator/internal" ) //+kubebuilder:rbac:groups=bpfman.io,resources=fexitprograms,verbs=get;list;watch;create;update;patch;delete @@ -55,7 +53,7 @@ func (r *FexitProgramReconciler) SetupWithManager(mgr ctrl.Manager) error { For(&bpfmaniov1alpha1.FexitProgram{}). // Watch bpfPrograms which are owned by FexitPrograms Watches( - &source.Kind{Type: &bpfmaniov1alpha1.BpfProgram{}}, + &bpfmaniov1alpha1.BpfProgram{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(predicate.And(statusChangedPredicate(), internal.BpfProgramTypePredicate(internal.FexitString))), ). diff --git a/controllers/bpfman-operator/kprobe-program.go b/controllers/bpfman-operator/kprobe-program.go index 22e4add1e..f36af3c1c 100644 --- a/controllers/bpfman-operator/kprobe-program.go +++ b/controllers/bpfman-operator/kprobe-program.go @@ -24,13 +24,11 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/builder" + bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1" + "github.com/bpfman/bpfman-operator/internal" "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/predicate" - "sigs.k8s.io/controller-runtime/pkg/source" - - bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1" - "github.com/bpfman/bpfman-operator/internal" ) //+kubebuilder:rbac:groups=bpfman.io,resources=kprobeprograms,verbs=get;list;watch;create;update;patch;delete @@ -55,7 +53,7 @@ func (r *KprobeProgramReconciler) SetupWithManager(mgr ctrl.Manager) error { For(&bpfmaniov1alpha1.KprobeProgram{}). // Watch bpfPrograms which are owned by KprobePrograms Watches( - &source.Kind{Type: &bpfmaniov1alpha1.BpfProgram{}}, + &bpfmaniov1alpha1.BpfProgram{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(predicate.And(statusChangedPredicate(), internal.BpfProgramTypePredicate(internal.Kprobe.String()))), ). diff --git a/controllers/bpfman-operator/tc-program.go b/controllers/bpfman-operator/tc-program.go index fa9817d9d..f3bc673c7 100644 --- a/controllers/bpfman-operator/tc-program.go +++ b/controllers/bpfman-operator/tc-program.go @@ -24,13 +24,11 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/builder" + bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1" + "github.com/bpfman/bpfman-operator/internal" "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/predicate" - "sigs.k8s.io/controller-runtime/pkg/source" - - bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1" - "github.com/bpfman/bpfman-operator/internal" ) type TcProgramReconciler struct { @@ -51,7 +49,7 @@ func (r *TcProgramReconciler) SetupWithManager(mgr ctrl.Manager) error { For(&bpfmaniov1alpha1.TcProgram{}). // Watch bpfPrograms which are owned by TcPrograms Watches( - &source.Kind{Type: &bpfmaniov1alpha1.BpfProgram{}}, + &bpfmaniov1alpha1.BpfProgram{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(predicate.And(statusChangedPredicate(), internal.BpfProgramTypePredicate(internal.Tc.String()))), ). diff --git a/controllers/bpfman-operator/tracepoint-program.go b/controllers/bpfman-operator/tracepoint-program.go index 229016f01..84025f074 100644 --- a/controllers/bpfman-operator/tracepoint-program.go +++ b/controllers/bpfman-operator/tracepoint-program.go @@ -24,13 +24,11 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/builder" + bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1" + "github.com/bpfman/bpfman-operator/internal" "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/predicate" - "sigs.k8s.io/controller-runtime/pkg/source" - - bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1" - "github.com/bpfman/bpfman-operator/internal" ) //+kubebuilder:rbac:groups=bpfman.io,resources=tracepointprograms,verbs=get;list;watch;create;update;patch;delete @@ -55,7 +53,7 @@ func (r *TracepointProgramReconciler) SetupWithManager(mgr ctrl.Manager) error { For(&bpfmaniov1alpha1.TracepointProgram{}). // Watch bpfPrograms which are owned by TracepointPrograms Watches( - &source.Kind{Type: &bpfmaniov1alpha1.BpfProgram{}}, + &bpfmaniov1alpha1.BpfProgram{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(predicate.And(statusChangedPredicate(), internal.BpfProgramTypePredicate(internal.Tracepoint.String()))), ). diff --git a/controllers/bpfman-operator/uprobe-program.go b/controllers/bpfman-operator/uprobe-program.go index 35777bd64..16616202d 100644 --- a/controllers/bpfman-operator/uprobe-program.go +++ b/controllers/bpfman-operator/uprobe-program.go @@ -24,13 +24,11 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/builder" + bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1" + "github.com/bpfman/bpfman-operator/internal" "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/predicate" - "sigs.k8s.io/controller-runtime/pkg/source" - - bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1" - "github.com/bpfman/bpfman-operator/internal" ) //+kubebuilder:rbac:groups=bpfman.io,resources=uprobeprograms,verbs=get;list;watch;create;update;patch;delete @@ -55,7 +53,7 @@ func (r *UprobeProgramReconciler) SetupWithManager(mgr ctrl.Manager) error { For(&bpfmaniov1alpha1.UprobeProgram{}). // Watch bpfPrograms which are owned by UprobePrograms Watches( - &source.Kind{Type: &bpfmaniov1alpha1.BpfProgram{}}, + &bpfmaniov1alpha1.BpfProgram{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(predicate.And(statusChangedPredicate(), internal.BpfProgramTypePredicate(internal.UprobeString))), ). diff --git a/controllers/bpfman-operator/xdp-program.go b/controllers/bpfman-operator/xdp-program.go index 0a4896129..ea9bd7e9b 100644 --- a/controllers/bpfman-operator/xdp-program.go +++ b/controllers/bpfman-operator/xdp-program.go @@ -24,13 +24,11 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/builder" + bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1" + "github.com/bpfman/bpfman-operator/internal" "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/predicate" - "sigs.k8s.io/controller-runtime/pkg/source" - - bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1" - "github.com/bpfman/bpfman-operator/internal" ) //+kubebuilder:rbac:groups=bpfman.io,resources=xdpprograms,verbs=get;list;watch;create;update;patch;delete @@ -55,7 +53,7 @@ func (r *XdpProgramReconciler) SetupWithManager(mgr ctrl.Manager) error { For(&bpfmaniov1alpha1.XdpProgram{}). // Watch bpfPrograms which are owned by XdpPrograms Watches( - &source.Kind{Type: &bpfmaniov1alpha1.BpfProgram{}}, + &bpfmaniov1alpha1.BpfProgram{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(predicate.And(statusChangedPredicate(), internal.BpfProgramTypePredicate(internal.Xdp.String()))), ). diff --git a/go.mod b/go.mod index 6e3762ae7..c68a9333f 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,8 @@ module github.com/bpfman/bpfman-operator -go 1.21.0 -toolchain go1.22.2 +go 1.21.1 + +toolchain go1.21.7 require ( github.com/bpfman/bpfman v0.4.1 diff --git a/pkg/helpers/helpers.go b/pkg/helpers/helpers.go index dd759e6b6..c995cbf04 100644 --- a/pkg/helpers/helpers.go +++ b/pkg/helpers/helpers.go @@ -155,10 +155,9 @@ func isProgLoaded(conditions *[]metav1.Condition) (bool, string) { return true, condition.Type } -func isKprobebpfmanProgLoaded(c *bpfmanclientset.Clientset, progConfName string) wait.ConditionFunc { - ctx := context.Background() +func isKprobebpfmanProgLoaded(c *bpfmanclientset.Clientset, progConfName string) wait.ConditionWithContextFunc { - return func() (bool, error) { + return func(ctx context.Context) (bool, error) { log.Info(".") // progress bar! bpfProgConfig, err := c.BpfmanV1alpha1().KprobePrograms().Get(ctx, progConfName, metav1.GetOptions{}) if err != nil { @@ -176,10 +175,9 @@ func isKprobebpfmanProgLoaded(c *bpfmanclientset.Clientset, progConfName string) } } -func isFentrybpfmanProgLoaded(c *bpfmanclientset.Clientset, progConfName string) wait.ConditionFunc { - ctx := context.Background() +func isFentrybpfmanProgLoaded(c *bpfmanclientset.Clientset, progConfName string) wait.ConditionWithContextFunc { - return func() (bool, error) { + return func(ctx context.Context) (bool, error) { log.Info(".") // progress bar! bpfProgConfig, err := c.BpfmanV1alpha1().FentryPrograms().Get(ctx, progConfName, metav1.GetOptions{}) if err != nil { @@ -197,10 +195,9 @@ func isFentrybpfmanProgLoaded(c *bpfmanclientset.Clientset, progConfName string) } } -func isTcbpfmanProgLoaded(c *bpfmanclientset.Clientset, progConfName string) wait.ConditionFunc { - ctx := context.Background() +func isTcbpfmanProgLoaded(c *bpfmanclientset.Clientset, progConfName string) wait.ConditionWithContextFunc { - return func() (bool, error) { + return func(ctx context.Context) (bool, error) { log.Info(".") // progress bar! bpfProgConfig, err := c.BpfmanV1alpha1().TcPrograms().Get(ctx, progConfName, metav1.GetOptions{}) if err != nil { @@ -218,10 +215,9 @@ func isTcbpfmanProgLoaded(c *bpfmanclientset.Clientset, progConfName string) wai } } -func isTracepointbpfmanProgLoaded(c *bpfmanclientset.Clientset, progConfName string) wait.ConditionFunc { - ctx := context.Background() +func isTracepointbpfmanProgLoaded(c *bpfmanclientset.Clientset, progConfName string) wait.ConditionWithContextFunc { - return func() (bool, error) { + return func(ctx context.Context) (bool, error) { log.Info(".") // progress bar! bpfProgConfig, err := c.BpfmanV1alpha1().TracepointPrograms().Get(ctx, progConfName, metav1.GetOptions{}) if err != nil { @@ -239,10 +235,9 @@ func isTracepointbpfmanProgLoaded(c *bpfmanclientset.Clientset, progConfName str } } -func isXdpbpfmanProgLoaded(c *bpfmanclientset.Clientset, progConfName string) wait.ConditionFunc { - ctx := context.Background() +func isXdpbpfmanProgLoaded(c *bpfmanclientset.Clientset, progConfName string) wait.ConditionWithContextFunc { - return func() (bool, error) { + return func(ctx context.Context) (bool, error) { log.Info(".") // progress bar! bpfProgConfig, err := c.BpfmanV1alpha1().XdpPrograms().Get(ctx, progConfName, metav1.GetOptions{}) if err != nil { @@ -263,17 +258,18 @@ func isXdpbpfmanProgLoaded(c *bpfmanclientset.Clientset, progConfName string) wa // WaitForBpfProgConfLoad ensures the Program object is loaded and deployed successfully, specifically // it checks the config objects' conditions to look for the `Loaded` state. func WaitForBpfProgConfLoad(c *bpfmanclientset.Clientset, progName string, timeout time.Duration, progType ProgramType) error { + ctx := context.Background() switch progType { case Kprobe: - return wait.PollImmediate(time.Second, timeout, isKprobebpfmanProgLoaded(c, progName)) + return wait.PollUntilContextTimeout(ctx, time.Second, timeout, true, isKprobebpfmanProgLoaded(c, progName)) case Tc: - return wait.PollImmediate(time.Second, timeout, isTcbpfmanProgLoaded(c, progName)) + return wait.PollUntilContextTimeout(ctx, time.Second, timeout, true, isTcbpfmanProgLoaded(c, progName)) case Xdp: - return wait.PollImmediate(time.Second, timeout, isXdpbpfmanProgLoaded(c, progName)) + return wait.PollUntilContextTimeout(ctx, time.Second, timeout, true, isXdpbpfmanProgLoaded(c, progName)) case Tracepoint: - return wait.PollImmediate(time.Second, timeout, isTracepointbpfmanProgLoaded(c, progName)) + return wait.PollUntilContextTimeout(ctx, time.Second, timeout, true, isTracepointbpfmanProgLoaded(c, progName)) case Tracing: - return wait.PollImmediate(time.Second, timeout, isFentrybpfmanProgLoaded(c, progName)) + return wait.PollUntilContextTimeout(ctx, time.Second, timeout, true, isFentrybpfmanProgLoaded(c, progName)) // TODO: case Uprobe: not covered. Since Uprobe has the same ProgramType as // Kprobe, we need a different way to distinguish them. Options include // creating an internal ProgramType for Uprobe or using a different