Skip to content

Commit

Permalink
cdi-device-injector: exit if connection to runtime is lost.
Browse files Browse the repository at this point in the history
Signed-off-by: Krisztian Litkey <[email protected]>
  • Loading branch information
klihub committed Jul 17, 2024
1 parent 9409eba commit 118c0ab
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions cmd/plugins/cdi-device-injector/cdi-device-injector.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ type plugin struct {
w watch.Interface
}

func (p *plugin) onClose() {
log.Error("connection to NRI/runtime lost, exiting...")
os.Exit(1)
}

// CreateContainer handles container creation requests.
func (p *plugin) CreateContainer(ctx context.Context, pod *api.PodSandbox, container *api.Container) (_ *api.ContainerAdjustment, _ []*api.ContainerUpdate, err error) {
defer func() {
Expand Down Expand Up @@ -236,7 +241,6 @@ func main() {
pluginIdx string
defaultCDIDevicePattern string
kubeConfig string
opts []stub.Option
err error
)

Expand All @@ -252,13 +256,6 @@ func main() {
flag.BoolVar(&verbose, "verbose", false, "enable (more) verbose logging")
flag.Parse()

if pluginName != "" {
opts = append(opts, stub.WithPluginName(pluginName))
}
if pluginIdx != "" {
opts = append(opts, stub.WithPluginIdx(pluginIdx))
}

p := &plugin{
defaultCDIDevicePattern: defaultCDIDevicePattern,
cdiCache: &cdiCache{
Expand All @@ -268,6 +265,15 @@ func main() {
kubeConfig: kubeConfig,
}

opts := []stub.Option{stub.WithOnClose(p.onClose)}

if pluginName != "" {
opts = append(opts, stub.WithPluginName(pluginName))
}
if pluginIdx != "" {
opts = append(opts, stub.WithPluginIdx(pluginIdx))
}

p.setAllowedPattern(defaultCDIDevicePattern)

if err := p.setupNamespaceWatch(); err != nil {
Expand Down

0 comments on commit 118c0ab

Please sign in to comment.