Skip to content

Commit 01f9c71

Browse files
gkopelsGregory Kopels
andauthored
cnf network: add nad host-device (rh-ecosystem-edge#1001)
Co-authored-by: Gregory Kopels <[email protected]>
1 parent 26bd9e3 commit 01f9c71

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

pkg/nad/masterplugin.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,3 +573,76 @@ func (plugin *MasterBondPlugin) GetMasterPluginConfig() (*MasterPlugin, error) {
573573

574574
return plugin.masterPlugin, nil
575575
}
576+
577+
// MasterHostDevicePlugin provides struct for MasterPlugin host-device interface in NetworkAttachmentDefinition.
578+
type MasterHostDevicePlugin struct {
579+
masterPlugin *MasterPlugin
580+
errorMsg string
581+
}
582+
583+
// GetMasterPluginConfig returns master plugin if error does not occur.
584+
func (plugin *MasterHostDevicePlugin) GetMasterPluginConfig() (*MasterPlugin, error) {
585+
if plugin.errorMsg != "" {
586+
return nil, fmt.Errorf("error to build MasterPlugin config due to : %s", plugin.errorMsg)
587+
}
588+
589+
return plugin.masterPlugin, nil
590+
}
591+
592+
// NewMasterHostDevicePlugin creates new instance of Master hostDevice plugin.
593+
func NewMasterHostDevicePlugin(name, interfaceName string) *MasterHostDevicePlugin {
594+
glog.V(100).Infof(
595+
"Initializing new MasterHostDevicePlugin structure %s", name)
596+
597+
builder := &MasterHostDevicePlugin{
598+
masterPlugin: &MasterPlugin{
599+
CniVersion: "0.3.1",
600+
Name: name,
601+
Type: "host-device",
602+
Device: interfaceName,
603+
},
604+
}
605+
606+
if builder.masterPlugin.Name == "" {
607+
glog.V(100).Infof("error: MasterHostDevicePlugin can not be empty")
608+
609+
builder.errorMsg = "MasterHostDevicePlugin name is empty"
610+
611+
return builder
612+
}
613+
614+
return builder
615+
}
616+
617+
// WithIPAM defines IPAM configuration to MasterHostDevicePlugin. Default is empty.
618+
func (plugin *MasterHostDevicePlugin) WithIPAM(ipam *IPAM) *MasterHostDevicePlugin {
619+
glog.V(100).Infof("Adding IPAM configuration %v to MasterHostDevicePlugin", ipam)
620+
621+
if plugin.masterPlugin == nil {
622+
glog.V(100).Infof(msg.UndefinedCrdObjectErrString("MasterHostDevicePlugin"))
623+
plugin.errorMsg = msg.UndefinedCrdObjectErrString("MasterHostDevicePlugin")
624+
625+
return plugin
626+
}
627+
628+
if ipam == nil {
629+
glog.V(100).Infof("error adding empty ipam to MasterHostDevicePlugin")
630+
631+
plugin.errorMsg = invalidIpamParameterMsg
632+
633+
return plugin
634+
}
635+
636+
plugin.masterPlugin.Ipam = ipam
637+
638+
return plugin
639+
}
640+
641+
// GetHostDevicePluginConfig returns master plugin if error does not occur.
642+
func (plugin *MasterHostDevicePlugin) GetHostDevicePluginConfig() (*MasterPlugin, error) {
643+
if plugin.errorMsg != "" {
644+
return nil, fmt.Errorf("error to build masterPlugin config due to :%s", plugin.errorMsg)
645+
}
646+
647+
return plugin.masterPlugin, nil
648+
}

pkg/nad/nadtypes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type (
5151
Mode string `json:"mode,omitempty"`
5252
Plugins *[]Plugin `json:"plugins,omitempty"`
5353
Bridge string `json:"bridge,omitempty"`
54+
Device string `json:"device,omitempty"`
5455
Ipam *IPAM `json:"ipam,omitempty"`
5556
LinksInContainer bool `json:"linksInContainer,omitempty"`
5657
LinkInContainer bool `json:"linkInContainer,omitempty"`

0 commit comments

Comments
 (0)