Skip to content
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
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ linters:
- govet
- unused
- misspell
- modernize
- revive
disable:
- errcheck
Expand Down
2 changes: 1 addition & 1 deletion pkg/adaptation/adaptation_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func TestPodAndContainerRequestsAndEvents(t *testing.T) {

require.NoError(t, runtime.startStopPodAndContainer(ctx, pod, ctr))
for _, events := range subscriptions {
for _, event := range strings.Split(events, ",") {
for event := range strings.SplitSeq(events, ",") {
match := &Event{Type: EventType(event)}
require.True(t, plugin.EventQ().Has(match))
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/adaptation/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (r *result) stopContainerResponse() *StopContainerResponse {
}
}

func (r *result) apply(response interface{}, plugin string) error {
func (r *result) apply(response any, plugin string) error {
switch rpl := response.(type) {
case *CreateContainerResponse:
if rpl == nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/adaptation/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (s *Suite) plugin(fullName string) *mockPlugin {

// ------------------------------------

func Log(format string, args ...interface{}) {
func Log(format string, args ...any) {
logrus.Debugf(format, args...)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/api/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func ParseEventMask(events ...string) (EventMask, error) {

for _, event := range events {
lcEvents := strings.ToLower(event)
for _, name := range strings.Split(lcEvents, ",") {
for name := range strings.SplitSeq(lcEvents, ",") {
switch name {
case "all":
mask |= ValidEvents
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package api

import "maps"

// DupStringSlice creates a copy of a string slice.
func DupStringSlice(in []string) []string {
if in == nil {
Expand All @@ -32,9 +34,7 @@ func DupStringMap(in map[string]string) map[string]string {
return nil
}
out := map[string]string{}
for k, v := range in {
out[k] = v
}
maps.Copy(out, in)
return out
}

Expand Down
18 changes: 9 additions & 9 deletions pkg/api/optional.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
//

// String creates an Optional wrapper from its argument.
func String(v interface{}) *OptionalString {
func String(v any) *OptionalString {
var value string

switch o := v.(type) {
Expand Down Expand Up @@ -73,7 +73,7 @@ func (o *OptionalString) Get() *string {
}

// RepeatedString creates an Optional wrapper from its argument.
func RepeatedString(v interface{}) *OptionalRepeatedString {
func RepeatedString(v any) *OptionalRepeatedString {
var value []string

switch o := v.(type) {
Expand Down Expand Up @@ -108,7 +108,7 @@ func (o *OptionalRepeatedString) Get() *[]string {
}

// Int creates an Optional wrapper from its argument.
func Int(v interface{}) *OptionalInt {
func Int(v any) *OptionalInt {
var value int64

switch o := v.(type) {
Expand Down Expand Up @@ -143,7 +143,7 @@ func (o *OptionalInt) Get() *int {
}

// Int32 creates an Optional wrapper from its argument.
func Int32(v interface{}) *OptionalInt32 {
func Int32(v any) *OptionalInt32 {
var value int32

switch o := v.(type) {
Expand Down Expand Up @@ -178,7 +178,7 @@ func (o *OptionalInt32) Get() *int32 {
}

// UInt32 creates an Optional wrapper from its argument.
func UInt32(v interface{}) *OptionalUInt32 {
func UInt32(v any) *OptionalUInt32 {
var value uint32

switch o := v.(type) {
Expand Down Expand Up @@ -213,7 +213,7 @@ func (o *OptionalUInt32) Get() *uint32 {
}

// Int64 creates an Optional wrapper from its argument.
func Int64(v interface{}) *OptionalInt64 {
func Int64(v any) *OptionalInt64 {
var value int64

switch o := v.(type) {
Expand Down Expand Up @@ -259,7 +259,7 @@ func (o *OptionalInt64) Get() *int64 {
}

// UInt64 creates an Optional wrapper from its argument.
func UInt64(v interface{}) *OptionalUInt64 {
func UInt64(v any) *OptionalUInt64 {
var value uint64

switch o := v.(type) {
Expand Down Expand Up @@ -305,7 +305,7 @@ func (o *OptionalUInt64) Get() *uint64 {
}

// Bool creates an Optional wrapper from its argument.
func Bool(v interface{}) *OptionalBool {
func Bool(v any) *OptionalBool {
var value bool

switch o := v.(type) {
Expand Down Expand Up @@ -340,7 +340,7 @@ func (o *OptionalBool) Get() *bool {
}

// FileMode creates an Optional wrapper from its argument.
func FileMode(v interface{}) *OptionalFileMode {
func FileMode(v any) *OptionalFileMode {
var value os.FileMode

switch o := v.(type) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/optional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestOptionalRepeatedString(t *testing.T) {
nilSlice := []string(nil)
tcs := []struct {
name string
input interface{}
input any
expectNil bool
expectedValue *[]string
}{
Expand Down
14 changes: 5 additions & 9 deletions pkg/api/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package api

import (
"maps"

rspec "github.com/opencontainers/runtime-spec/specs-go"
)

Expand Down Expand Up @@ -79,9 +81,7 @@ func FromOCILinuxResources(o *rspec.LinuxResources, _ map[string]string) *LinuxR
}
if len(o.Unified) != 0 {
l.Unified = make(map[string]string)
for k, v := range o.Unified {
l.Unified[k] = v
}
maps.Copy(l.Unified, o.Unified)
}
return l
}
Expand Down Expand Up @@ -126,9 +126,7 @@ func (r *LinuxResources) ToOCI() *rspec.LinuxResources {
}
if len(r.Unified) != 0 {
o.Unified = make(map[string]string)
for k, v := range r.Unified {
o.Unified[k] = v
}
maps.Copy(o.Unified, r.Unified)
}
for _, d := range r.Devices {
o.Devices = append(o.Devices, rspec.LinuxDeviceCgroup{
Expand Down Expand Up @@ -186,9 +184,7 @@ func (r *LinuxResources) Copy() *LinuxResources {
}
if len(r.Unified) != 0 {
o.Unified = make(map[string]string)
for k, v := range r.Unified {
o.Unified[k] = v
}
maps.Copy(o.Unified, r.Unified)
}
if r.Pids != nil {
o.Pids = &LinuxPids{
Expand Down
24 changes: 12 additions & 12 deletions pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ var (

// Logger is the interface NRI uses for logging.
type Logger interface {
Debugf(ctx context.Context, format string, args ...interface{})
Infof(ctx context.Context, format string, args ...interface{})
Warnf(ctx context.Context, format string, args ...interface{})
Errorf(ctx context.Context, format string, args ...interface{})
Debugf(ctx context.Context, format string, args ...any)
Infof(ctx context.Context, format string, args ...any)
Warnf(ctx context.Context, format string, args ...any)
Errorf(ctx context.Context, format string, args ...any)
}

// Set the logger used by NRI.
Expand All @@ -45,43 +45,43 @@ func Get() Logger {
}

// Debugf logs a formatted debug message.
func Debugf(ctx context.Context, format string, args ...interface{}) {
func Debugf(ctx context.Context, format string, args ...any) {
log.Debugf(ctx, format, args...)
}

// Infof logs a formatted informational message.
func Infof(ctx context.Context, format string, args ...interface{}) {
func Infof(ctx context.Context, format string, args ...any) {
log.Infof(ctx, format, args...)
}

// Warnf logs a formatted warning message.
func Warnf(ctx context.Context, format string, args ...interface{}) {
func Warnf(ctx context.Context, format string, args ...any) {
log.Warnf(ctx, format, args...)
}

// Errorf logs a formatted error message.
func Errorf(ctx context.Context, format string, args ...interface{}) {
func Errorf(ctx context.Context, format string, args ...any) {
log.Errorf(ctx, format, args...)
}

type fallbackLogger struct{}

// Debugf logs a formatted debug message.
func (f *fallbackLogger) Debugf(ctx context.Context, format string, args ...interface{}) {
func (f *fallbackLogger) Debugf(ctx context.Context, format string, args ...any) {
logrus.WithContext(ctx).Debugf(format, args...)
}

// Infof logs a formatted informational message.
func (f *fallbackLogger) Infof(ctx context.Context, format string, args ...interface{}) {
func (f *fallbackLogger) Infof(ctx context.Context, format string, args ...any) {
logrus.WithContext(ctx).Infof(format, args...)
}

// Warnf logs a formatted warning message.
func (f *fallbackLogger) Warnf(ctx context.Context, format string, args ...interface{}) {
func (f *fallbackLogger) Warnf(ctx context.Context, format string, args ...any) {
logrus.WithContext(ctx).Warnf(format, args...)
}

// Errorf logs a formatted error message.
func (f *fallbackLogger) Errorf(ctx context.Context, format string, args ...interface{}) {
func (f *fallbackLogger) Errorf(ctx context.Context, format string, args ...any) {
logrus.WithContext(ctx).Errorf(format, args...)
}
2 changes: 1 addition & 1 deletion pkg/net/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestPreconnectedReadWrite(t *testing.T) {
require.NoError(t, err, "Accept()")
require.NotNil(t, lconn, "Accept()")

for i := 0; i < 32; i++ {
for i := range 32 {
msg := fmt.Sprintf("message #%d\n", i)
_, err := lconn.Write([]byte(msg))
require.NoError(t, err, "Write()")
Expand Down
6 changes: 3 additions & 3 deletions pkg/net/multiplex/mux_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func openMuxes(lMux, pMux mux.Mux, count int) ([]net.Conn, []net.Conn, error) {
err error
)

for i := 0; i < count; i++ {
for i := range count {
conn, err = lMux.Open(mux.LowestConnID + mux.ConnID(i))
if err != nil {
lMux.Trunk().Close()
Expand Down Expand Up @@ -383,7 +383,7 @@ func sendAndReceive(lConn, pConn []net.Conn, msgCount int) error {

write := func(id int, conn net.Conn, messages []string) ([]string, error) {
if messages == nil {
for i := 0; i < msgCount; i++ {
for i := range msgCount {
msg := fmt.Sprintf("[%d] message #%d/%d", id, i+1, msgCount)
if len(msg) > maxMsg {
return nil, fmt.Errorf("message length %d exceeds maximum %d", len(msg), maxMsg)
Expand Down Expand Up @@ -459,7 +459,7 @@ func sendAndReceive(lConn, pConn []net.Conn, msgCount int) error {
}
}

for i := 0; i < len(lConn); i++ {
for i := range lConn {
wg.Add(2)
go sendrecv(i, lConn[i], true)
go sendrecv(i, pConn[i], false)
Expand Down
4 changes: 2 additions & 2 deletions pkg/net/socketpair_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestConnReadWrite(t *testing.T) {

go reader()

for i := 0; i < 32; i++ {
for i := range 32 {
msg := fmt.Sprintf("message #%d\n", i)
_, err := conn.Write([]byte(msg))
require.NoError(t, err, "Write()")
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestFileReadWrite(t *testing.T) {

go reader()

for i := 0; i < 32; i++ {
for i := range 32 {
msg := fmt.Sprintf("message #%d\n", i)
_, err := f.Write([]byte(msg))
require.NoError(t, err, "Write()")
Expand Down
9 changes: 4 additions & 5 deletions pkg/runtime-tools/generate/helpers_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package generate
import (
"fmt"
"path/filepath"
"slices"
"strings"

"github.com/moby/sys/mountinfo"
Expand Down Expand Up @@ -48,7 +49,7 @@ func getPropagation(path string) (string, error) {
}
}

for _, opt := range strings.Split(mnt.Optional, " ") {
for opt := range strings.SplitSeq(mnt.Optional, " ") {
switch {
case strings.HasPrefix(opt, "shared:"):
return "rshared", nil
Expand All @@ -66,10 +67,8 @@ func ensurePropagation(path string, accepted ...string) error {
return err
}

for _, p := range accepted {
if p == prop {
return nil
}
if slices.Contains(accepted, prop) {
return nil
}

return fmt.Errorf("path %q mount propagation is %q, not %q",
Expand Down
6 changes: 3 additions & 3 deletions pkg/stub/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import (
// least one of these interfaces and this is verified during stub creation.
// Trying to create a stub for a plugin violating this requirement will fail
// with and error.
type Plugin interface{}
type Plugin any

// ConfigureInterface handles Configure API request.
type ConfigureInterface interface {
Expand Down Expand Up @@ -309,7 +309,7 @@ func WithFailurePolicy(policy *api.FailurePolicy) Option {
// stub implements Stub.
type stub struct {
sync.Mutex
plugin interface{}
plugin any
handlers handlers
events api.EventMask
name string
Expand Down Expand Up @@ -361,7 +361,7 @@ type handlers struct {
}

// New creates a stub with the given plugin and options.
func New(p interface{}, opts ...Option) (Stub, error) {
func New(p any, opts ...Option) (Stub, error) {
stub := &stub{
plugin: p,
name: os.Getenv(api.PluginNameEnvVar),
Expand Down
7 changes: 4 additions & 3 deletions plugins/default-validator/default-validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,17 @@ func (v *DefaultValidator) validateNamespaces(req *api.ValidateContainerAdjustme
return nil
}

offenders := "plugin(s) "
var offenders strings.Builder
offenders.WriteString("plugin(s) ")
sep := ""

for ns, plugin := range owners {
offenders += sep + fmt.Sprintf("%q (namespace %q)", plugin, ns)
offenders.WriteString(sep + fmt.Sprintf("%q (namespace %q)", plugin, ns))
sep = ", "
}

return fmt.Errorf("%w: attempted restricted namespace adjustment by %s",
ErrValidation, offenders)
ErrValidation, offenders.String())
}

func (v *DefaultValidator) validateSysctl(req *api.ValidateContainerAdjustmentRequest) error {
Expand Down
Loading
Loading