Skip to content
Open
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
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ PLUGINS ?= \
nri-memory-policy \
nri-memory-qos \
nri-memtierd \
nri-sgx-epc
nri-sgx-epc \
nri-resctrl-mon

BINARIES ?= \
config-manager \
Expand Down
40 changes: 40 additions & 0 deletions cmd/plugins/resctrl-mon/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
ARG GO_VERSION=1.26

FROM golang:${GO_VERSION}-bookworm AS builder

ARG IMAGE_VERSION
ARG BUILD_VERSION
ARG BUILD_BUILDID
ARG DEBUG=0
ARG NORACE=0
ARG SKIP_LICENSES=0

WORKDIR /go/builder

# Fetch go dependencies in a separate layer for caching
COPY go.mod go.sum .
COPY pkg/topology/ pkg/topology/
RUN --mount=type=cache,target=/go/pkg/mod/ go mod download

# Build nri-resctrl-mon
COPY . .

RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=cache,target="/root/.cache/go-build" \
make IMAGE_VERSION=${IMAGE_VERSION} \
BUILD_VERSION=${BUILD_VERSION} \
BUILD_BUILDID=${BUILD_BUILDID} \
DEBUG=$DEBUG \
NORACE=$NORACE \
OTHER_IMAGE_TARGETS="" \
BINARIES="" \
PLUGINS=nri-resctrl-mon \
clean install-go-licenses build-plugins-static licenses

FROM gcr.io/distroless/static

COPY --from=builder /go/builder/build/bin/nri-resctrl-mon /bin/nri-resctrl-mon
COPY --from=builder /go/builder/build/licenses/nri-resctrl-mon/ /licenses/nri-resctrl-mon/
COPY --from=builder /go/builder/sample-configs/nri-resctrl-mon.yaml /etc/nri/resctrl-mon/config.yaml

ENTRYPOINT ["/bin/nri-resctrl-mon", "-idx", "90", "-config", "/etc/nri/resctrl-mon/config.yaml"]
90 changes: 90 additions & 0 deletions cmd/plugins/resctrl-mon/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright The NRI Plugins Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"context"
"flag"
"os"

"github.com/containerd/nri/pkg/stub"
"github.com/sirupsen/logrus"
)

var (
log *logrus.Logger
)

func main() {
var (
pluginName string
pluginIdx string
configFile string
verbose bool
veryVerbose bool
err error
)

log = logrus.StandardLogger()
log.SetFormatter(&logrus.TextFormatter{
PadLevelText: true,
})

flag.StringVar(&pluginName, "name", "", "plugin name to register to NRI")
flag.StringVar(&pluginIdx, "idx", "", "plugin index to register to NRI")
flag.StringVar(&configFile, "config", "", "configuration file name")
flag.BoolVar(&verbose, "v", false, "verbose output")
flag.BoolVar(&veryVerbose, "vv", false, "very verbose output")
flag.Parse()

if verbose {
log.SetLevel(logrus.DebugLevel)
}
if veryVerbose {
log.SetLevel(logrus.TraceLevel)
}

p := newPlugin()

if configFile != "" {
log.Debugf("reading configuration from %q", configFile)
data, err := os.ReadFile(configFile)
if err != nil {
log.Fatalf("error reading configuration file %q: %s", configFile, err)
}
if err = p.setConfig(data); err != nil {
log.Fatalf("error applying configuration from file %q: %s", configFile, err)
}
}

opts := []stub.Option{
stub.WithOnClose(p.onClose),
}
if pluginName != "" {
opts = append(opts, stub.WithPluginName(pluginName))
}
if pluginIdx != "" {
opts = append(opts, stub.WithPluginIdx(pluginIdx))
}

if p.stub, err = stub.New(p, opts...); err != nil {
log.Fatalf("failed to create plugin stub: %v", err)
}

if err = p.stub.Run(context.Background()); err != nil {
log.Errorf("plugin exited (%v)", err)
os.Exit(1)
}
}
Loading