diff --git a/cmd/noderesourcetopology-plugin/main.go b/cmd/noderesourcetopology-plugin/main.go index a55174b3c..cee6f6a5d 100644 --- a/cmd/noderesourcetopology-plugin/main.go +++ b/cmd/noderesourcetopology-plugin/main.go @@ -17,52 +17,31 @@ limitations under the License. package main import ( - "context" "math/rand" "os" "time" "k8s.io/component-base/logs" - "k8s.io/klog/v2" "k8s.io/klog/v2/klogr" "k8s.io/kubernetes/cmd/kube-scheduler/app" "sigs.k8s.io/scheduler-plugins/pkg-kni/knidebug" - "sigs.k8s.io/scheduler-plugins/pkg-kni/pfpstatus" "sigs.k8s.io/scheduler-plugins/pkg/noderesourcetopology" // Ensure scheme package is initialized. _ "sigs.k8s.io/scheduler-plugins/apis/config/scheme" + knistatus "sigs.k8s.io/scheduler-plugins/pkg-kni/pfpstatus" kniinformer "sigs.k8s.io/scheduler-plugins/pkg-kni/podinformer" - - "github.com/k8stopologyawareschedwg/podfingerprint" -) - -const ( - PFPStatusDumpEnvVar string = "PFP_STATUS_DUMP" ) -func setupPFPStatusDump() { - dumpDir, ok := os.LookupEnv(PFPStatusDumpEnvVar) - if !ok || dumpDir == "" { - klog.InfoS("PFP Status dump disabled", "variableFound", ok, "valueGiven", dumpDir != "") - return - } - - klog.InfoS("PFP Status dump enabled", "statusDirectory", dumpDir) - - ch := make(chan podfingerprint.Status) - logh := klogr.NewWithOptions(klogr.WithFormat(klogr.FormatKlog)) - - podfingerprint.SetCompletionSink(ch) - go pfpstatus.RunForever(context.Background(), logh, dumpDir, ch) -} - func main() { rand.Seed(time.Now().UnixNano()) - kniinformer.Setup() + logh := klogr.NewWithOptions(klogr.WithFormat(klogr.FormatKlog)) + + kniinformer.Setup(logh) + knistatus.Setup(logh) // Register custom plugins to the scheduler framework. // Later they can consist of scheduler profile(s) and hence @@ -79,8 +58,6 @@ func main() { logs.InitLogs() defer logs.FlushLogs() - setupPFPStatusDump() - if err := command.Execute(); err != nil { os.Exit(1) } diff --git a/pkg-kni/pfpstatus/pfpstatus.go b/pkg-kni/pfpstatus/pfpstatus.go index cb240628a..f7a8c0679 100644 --- a/pkg-kni/pfpstatus/pfpstatus.go +++ b/pkg-kni/pfpstatus/pfpstatus.go @@ -25,15 +25,35 @@ import ( "time" "github.com/go-logr/logr" + "github.com/k8stopologyawareschedwg/podfingerprint" ) +const ( + PFPStatusDumpEnvVar string = "PFP_STATUS_DUMP" +) + type StatusInfo struct { podfingerprint.Status LastWrite time.Time `json:"lastWrite"` SeqNo int64 `json:"seqNo"` } +func Setup(logh logr.Logger) { + dumpDir, ok := os.LookupEnv(PFPStatusDumpEnvVar) + if !ok || dumpDir == "" { + logh.Info("PFP Status dump disabled", "variableFound", ok, "valueGiven", dumpDir != "") + return + } + + logh.Info("PFP Status dump enabled", "statusDirectory", dumpDir) + + ch := make(chan podfingerprint.Status) + + podfingerprint.SetCompletionSink(ch) + go RunForever(context.Background(), logh, dumpDir, ch) +} + func RunForever(ctx context.Context, logger logr.Logger, baseDirectory string, updates <-chan podfingerprint.Status) { // let's try to keep the amount of code we do in init() at minimum. // This may happen if the container didn't have the directory mounted diff --git a/pkg-kni/podinformer/podinformer.go b/pkg-kni/podinformer/podinformer.go index 10e9bbe54..09e285ca1 100644 --- a/pkg-kni/podinformer/podinformer.go +++ b/pkg-kni/podinformer/podinformer.go @@ -21,6 +21,7 @@ import ( "os" "strconv" + "github.com/go-logr/logr" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" coreinformers "k8s.io/client-go/informers/core/v1" @@ -43,18 +44,18 @@ func IsEnabled() bool { return enabled } -func Setup() { +func Setup(logh logr.Logger) { hasNRTInf, ok := os.LookupEnv(nrtInformerEnvVar) if !ok || hasNRTInf == "" { - klog.InfoS("NRT specific informer disabled", "variableFound", ok, "valueGiven", hasNRTInf != "") + logh.Info("NRT specific informer disabled", "variableFound", ok, "valueGiven", hasNRTInf != "") return } val, err := strconv.ParseBool(hasNRTInf) if err != nil { - klog.Error(err, "NRT specific informer disabled") + logh.Error(err, "NRT specific informer disabled") return } - klog.InfoS("NRT specific informer status", "value", val) + logh.Info("NRT specific informer status", "value", val) enabled = val }