Skip to content
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

[KNI] package cleanups #128

Merged
merged 2 commits into from
Oct 7, 2023
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
33 changes: 5 additions & 28 deletions cmd/noderesourcetopology-plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -79,8 +58,6 @@ func main() {
logs.InitLogs()
defer logs.FlushLogs()

setupPFPStatusDump()

if err := command.Execute(); err != nil {
os.Exit(1)
}
Expand Down
20 changes: 20 additions & 0 deletions pkg-kni/pfpstatus/pfpstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions pkg-kni/podinformer/podinformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}

Expand Down