Skip to content

Commit 2df6565

Browse files
committed
[plugins] support specifying a custom NRI socket path
Signed-off-by: Tariq Ibrahim <[email protected]>
1 parent 8f3e69e commit 2df6565

9 files changed

Lines changed: 67 additions & 16 deletions

File tree

plugins/device-injector/device-injector.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,9 +563,10 @@ func dump(args ...interface{}) {
563563

564564
func main() {
565565
var (
566-
pluginIdx string
567-
opts []stub.Option
568-
err error
566+
pluginIdx string
567+
socketPath string
568+
opts []stub.Option
569+
err error
569570
)
570571

571572
log = logrus.StandardLogger()
@@ -574,13 +575,18 @@ func main() {
574575
})
575576

576577
flag.StringVar(&pluginIdx, "idx", "", "plugin index to register to NRI")
578+
flag.StringVar(&socketPath, "socket-path", "", "path of the NRI socket file")
577579
flag.BoolVar(&verbose, "verbose", false, "enable (more) verbose logging")
578580
flag.Parse()
579581

580582
if pluginIdx != "" {
581583
opts = append(opts, stub.WithPluginIdx(pluginIdx))
582584
}
583585

586+
if socketPath != "" {
587+
opts = append(opts, stub.WithSocketPath(socketPath))
588+
}
589+
584590
p := &plugin{}
585591
if p.stub, err = stub.New(p, opts...); err != nil {
586592
log.Fatalf("failed to create plugin stub: %v", err)

plugins/differ/nri-differ.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
type config struct {
3939
Indices string `json:"indices"`
4040
LogFile string `json:"logFile"`
41+
SocketPath string `json:"socketPath"`
4142
VerboseLevel int `json:"verboseLevel"`
4243
Yaml bool `json:"yaml"`
4344
}
@@ -339,7 +340,7 @@ func (p *plugin) printYamlDiff(apifunc string, obj string, origValue interface{}
339340
}
340341
}
341342

342-
func startPlugin(wg *sync.WaitGroup, pluginIdx int) {
343+
func startPlugin(wg *sync.WaitGroup, pluginIdx int, socketPath string) {
343344
var (
344345
opts []stub.Option
345346
err error
@@ -353,6 +354,10 @@ func startPlugin(wg *sync.WaitGroup, pluginIdx int) {
353354
opts = append(opts, stub.WithPluginIdx(idxStr))
354355
}
355356

357+
if socketPath != "" {
358+
opts = append(opts, stub.WithSocketPath(socketPath))
359+
}
360+
356361
p := &plugin{}
357362
if p.mask, err = api.ParseEventMask("all"); err != nil {
358363
log.Fatalf("Failed to parse events: %v", err)
@@ -391,6 +396,7 @@ func main() {
391396
"indices 45, 50 and 80. Note that this plugin will install itself to index 0 and 99\n"+
392397
"if this parameter is not given.")
393398
flag.BoolVar(&cfg.Yaml, "yaml", false, "Print the diff in yaml")
399+
flag.StringVar(&cfg.SocketPath, "socket-path", "", "path of the NRI socket file")
394400
flag.Parse()
395401

396402
if cfg.LogFile != "" {
@@ -431,7 +437,7 @@ func main() {
431437

432438
wg.Add(1)
433439

434-
go startPlugin(wg, idx)
440+
go startPlugin(wg, idx, cfg.SocketPath)
435441
}
436442

437443
entry := indices[prevIndex]

plugins/hook-injector/hook-injector.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ func dump(args ...interface{}) {
136136
func main() {
137137
var (
138138
pluginIdx string
139+
socketPath string
139140
disableWatch bool
140141
opts []stub.Option
141142
mgr *hooks.Manager
@@ -148,6 +149,7 @@ func main() {
148149
})
149150

150151
flag.StringVar(&pluginIdx, "idx", "", "plugin index to register to NRI")
152+
flag.StringVar(&socketPath, "socket-path", "", "path of the NRI socket file")
151153
flag.BoolVar(&verbose, "verbose", false, "enable (more) verbose logging")
152154
flag.BoolVar(&disableWatch, "disableWatch", false, "disable watching hook directories for new hooks")
153155
flag.Parse()
@@ -156,6 +158,10 @@ func main() {
156158
opts = append(opts, stub.WithPluginIdx(pluginIdx))
157159
}
158160

161+
if socketPath != "" {
162+
opts = append(opts, stub.WithSocketPath(socketPath))
163+
}
164+
159165
if verbose {
160166
logrus.SetLevel(logrus.DebugLevel)
161167
}

plugins/logger/nri-logger.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,11 @@ func dump(args ...interface{}) {
217217

218218
func main() {
219219
var (
220-
pluginIdx string
221-
events string
222-
opts []stub.Option
223-
err error
220+
pluginIdx string
221+
socketPath string
222+
events string
223+
opts []stub.Option
224+
err error
224225
)
225226

226227
log = logrus.StandardLogger()
@@ -229,6 +230,7 @@ func main() {
229230
})
230231

231232
flag.StringVar(&pluginIdx, "idx", "", "plugin index to register to NRI")
233+
flag.StringVar(&socketPath, "socket-path", "", "path of the NRI socket file")
232234
flag.StringVar(&events, "events", "", "comma-separated list of events to subscribe for")
233235
flag.StringVar(&cfg.LogFile, "log-file", "", "logfile name, if logging to a file")
234236
flag.StringVar(&cfg.AddAnnotation, "add-annotation", "", "add this annotation to containers")
@@ -249,6 +251,10 @@ func main() {
249251
opts = append(opts, stub.WithPluginIdx(pluginIdx))
250252
}
251253

254+
if socketPath != "" {
255+
opts = append(opts, stub.WithSocketPath(socketPath))
256+
}
257+
252258
p := &plugin{}
253259
if events != "" {
254260
if p.mask, err = api.ParseEventMask(events); err != nil {

plugins/network-device-injector/network-device-injector.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,10 @@ func dump(args ...interface{}) {
273273

274274
func main() {
275275
var (
276-
pluginIdx string
277-
opts []stub.Option
278-
err error
276+
pluginIdx string
277+
socketPath string
278+
opts []stub.Option
279+
err error
279280
)
280281

281282
log = logrus.StandardLogger()
@@ -284,13 +285,18 @@ func main() {
284285
})
285286

286287
flag.StringVar(&pluginIdx, "idx", "", "plugin index to register to NRI")
288+
flag.StringVar(&socketPath, "socket", "", "path to NRI socket")
287289
flag.BoolVar(&verbose, "verbose", false, "enable (more) verbose logging")
288290
flag.Parse()
289291

290292
if pluginIdx != "" {
291293
opts = append(opts, stub.WithPluginIdx(pluginIdx))
292294
}
293295

296+
if socketPath != "" {
297+
opts = append(opts, stub.WithSocketPath(socketPath))
298+
}
299+
294300
p := &plugin{}
295301
if p.stub, err = stub.New(p, opts...); err != nil {
296302
log.Fatalf("failed to create plugin stub: %v", err)

plugins/network-logger/plugin.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ func (p *plugin) onClose() {
8383

8484
func main() {
8585
var (
86-
pluginIdx string
87-
err error
86+
pluginIdx string
87+
socketPath string
88+
err error
8889
)
8990

9091
log = logrus.StandardLogger()
@@ -93,6 +94,7 @@ func main() {
9394
})
9495

9596
flag.StringVar(&pluginIdx, "idx", "", "plugin index to register to NRI")
97+
flag.StringVar(&socketPath, "socket", "", "path to NRI socket")
9698
flag.Parse()
9799

98100
p := &plugin{}
@@ -103,6 +105,10 @@ func main() {
103105
opts = append(opts, stub.WithPluginIdx(pluginIdx))
104106
}
105107

108+
if socketPath != "" {
109+
opts = append(opts, stub.WithSocketPath(socketPath))
110+
}
111+
106112
if p.stub, err = stub.New(p, opts...); err != nil {
107113
log.Fatalf("failed to create plugin stub: %v", err)
108114
}

plugins/template/plugin.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ func main() {
169169
var (
170170
pluginName string
171171
pluginIdx string
172+
socketPath string
172173
err error
173174
)
174175

@@ -179,6 +180,7 @@ func main() {
179180

180181
flag.StringVar(&pluginName, "name", "", "plugin name to register to NRI")
181182
flag.StringVar(&pluginIdx, "idx", "", "plugin index to register to NRI")
183+
flag.StringVar(&socketPath, "socket", "", "path to the plugin socket")
182184
flag.Parse()
183185

184186
p := &plugin{}
@@ -191,6 +193,9 @@ func main() {
191193
if pluginIdx != "" {
192194
opts = append(opts, stub.WithPluginIdx(pluginIdx))
193195
}
196+
if socketPath != "" {
197+
opts = append(opts, stub.WithSocketPath(socketPath))
198+
}
194199

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

plugins/ulimit-adjuster/adjuster.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func main() {
6262
var (
6363
pluginName string
6464
pluginIdx string
65+
socketPath string
6566
verbose bool
6667
opts []stub.Option
6768
)
@@ -73,6 +74,7 @@ func main() {
7374

7475
flag.StringVar(&pluginName, "name", "", "plugin name to register to NRI")
7576
flag.StringVar(&pluginIdx, "idx", "", "plugin index to register to NRI")
77+
flag.StringVar(&socketPath, "socket", "", "path to the plugin socket")
7678
flag.BoolVar(&verbose, "verbose", false, "enable (more) verbose logging")
7779
flag.Parse()
7880
ctx := log.WithLogger(context.Background(), l.WithField("name", pluginName).WithField("idx", pluginIdx))
@@ -88,6 +90,9 @@ func main() {
8890
if pluginIdx != "" {
8991
opts = append(opts, stub.WithPluginIdx(pluginIdx))
9092
}
93+
if socketPath != "" {
94+
opts = append(opts, stub.WithSocketPath(socketPath))
95+
}
9196

9297
p := &plugin{l: log.G(ctx)}
9398
var err error

plugins/v010-adapter/v010-adapter.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,9 @@ func namespacesToSlice(namespaces []*api.LinuxNamespace) []oci.LinuxNamespace {
195195

196196
func main() {
197197
var (
198-
pluginIdx string
199-
err error
198+
pluginIdx string
199+
socketPath string
200+
err error
200201
)
201202

202203
log = logrus.StandardLogger()
@@ -205,6 +206,7 @@ func main() {
205206
})
206207

207208
flag.StringVar(&pluginIdx, "idx", "", "plugin index to register to NRI")
209+
flag.StringVar(&socketPath, "socket", "", "path to NRI socket")
208210
flag.Parse()
209211

210212
p := &plugin{}
@@ -214,6 +216,9 @@ func main() {
214216
if pluginIdx != "" {
215217
opts = append(opts, stub.WithPluginIdx(pluginIdx))
216218
}
219+
if socketPath != "" {
220+
opts = append(opts, stub.WithSocketPath(socketPath))
221+
}
217222

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

0 commit comments

Comments
 (0)