@@ -573,3 +573,76 @@ func (plugin *MasterBondPlugin) GetMasterPluginConfig() (*MasterPlugin, error) {
573
573
574
574
return plugin .masterPlugin , nil
575
575
}
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
+ }
0 commit comments