@@ -533,6 +533,71 @@ var _ = Describe("Operations", func() {
533533 multiPathTest (ver , singleNICIPAMWithMultiPath , fullNets , POOL_MASTER_NAMES )
534534 })
535535
536+ It (fmt .Sprintf ("[%s] check multi-config IPAM" , ver ), func () {
537+ conf , n := getSampleMultiIPAMConfig (ver , POOL_MASTER_NAMES , masterNets )
538+ confBytesArray , _ , err := loadIPVANConf ([]byte (conf ), "net1" , n , []* types100.IPConfig {})
539+ Expect (err ).NotTo (HaveOccurred ())
540+ Expect (len (confBytesArray )).To (Equal (len (POOL_MASTER_NAMES )))
541+ for index , confBytes := range confBytesArray {
542+ log .Printf ("%s" , confBytes )
543+ confObj := & IPVLANTypeNetConf {}
544+ err = json .Unmarshal (confBytes , confObj )
545+ Expect (err ).NotTo (HaveOccurred ())
546+ Expect (confObj .IPAM .Type ).To (Equal ("whereabouts" ))
547+ ipamObject := & IPAMExtract {}
548+ err = json .Unmarshal (confBytes , ipamObject )
549+ Expect (err ).NotTo (HaveOccurred ())
550+ Expect (ipamObject .IPAM ["range" ].(string )).To (Equal (POOL_IP_ADDRESSES [index ]))
551+ Expect (ipamObject .IPAM ["network_name" ].(string )).To (Equal (POOL_MASTER_NAMES [index ]))
552+ }
553+ })
554+
555+ It (fmt .Sprintf ("[%s] check multi-config IPAM with static IP" , ver ), func () {
556+ var ips []* types100.IPConfig
557+ for _ , podIP := range POOL_IP_ADDRESSES {
558+ ipVal , ipnet , err := net .ParseCIDR (podIP )
559+ ipnet .IP = ipVal
560+ Expect (err ).NotTo (HaveOccurred ())
561+ podIPConfig := & types100.IPConfig {Address : * ipnet }
562+ ips = append (ips , podIPConfig )
563+ }
564+ conf , n := getSampleMultiIPAMConfig (ver , POOL_MASTER_NAMES , masterNets )
565+ confBytesArray , _ , err := loadIPVANConf ([]byte (conf ), "net1" , n , ips )
566+ Expect (err ).NotTo (HaveOccurred ())
567+ Expect (len (confBytesArray )).To (Equal (len (POOL_MASTER_NAMES )))
568+ for index , confBytes := range confBytesArray {
569+ log .Printf ("%s" , confBytes )
570+ confObj := & IPVLANTypeNetConf {}
571+ err = json .Unmarshal (confBytes , confObj )
572+ Expect (err ).NotTo (HaveOccurred ())
573+ Expect (confObj .IPAM .Type ).To (Equal ("static" ))
574+ ipamObject := & IPAMExtract {}
575+ err = json .Unmarshal (confBytes , ipamObject )
576+ Expect (err ).NotTo (HaveOccurred ())
577+ addresses := ipamObject .IPAM ["addresses" ].([]interface {})
578+ Expect (len (addresses )).To (Equal (1 ))
579+ addressMap := addresses [0 ].(map [string ]interface {})
580+ Expect (addressMap ["address" ].(string )).To (Equal (POOL_IP_ADDRESSES [index ]))
581+ }
582+ })
583+
584+ It (fmt .Sprintf ("[%s] check getStaticIPs" , ver ), func () {
585+ var ips []string
586+ joinedIPs := strings .Join (POOL_IP_ADDRESSES , "," )
587+ argStr := fmt .Sprintf ("POD_NAME=a;IP=%s" , joinedIPs )
588+ ips , argStr = getStaticIPs (argStr )
589+ for index , podIP := range ips {
590+ Expect (podIP ).To (Equal (POOL_IP_ADDRESSES [index ]))
591+ }
592+ Expect (argStr ).To (Equal ("POD_NAME=a" ))
593+
594+ argStr = fmt .Sprintf ("POD_NAME=a;IP=%s;SOME_ARG=b" , joinedIPs )
595+ ips , argStr = getStaticIPs (argStr )
596+ for index , podIP := range ips {
597+ Expect (podIP ).To (Equal (POOL_IP_ADDRESSES [index ]))
598+ }
599+ Expect (argStr ).To (Equal ("POD_NAME=a;SOME_ARG=b" ))
600+ })
536601 }
537602})
538603
@@ -583,6 +648,48 @@ func getAwsIpvlanConfig(ver, masterNets string) ([]byte, *NetConf) {
583648 return conf , n
584649}
585650
651+ func getSampleMultiIPAMConfig (ver string , masterNames []string , masterNets string ) ([]byte , * NetConf ) {
652+ ipamArgs := ""
653+ for index , masterName := range masterNames {
654+ if index > 0 {
655+ ipamArgs += ","
656+ }
657+ ipamArgs += fmt .Sprintf (`
658+ "%s": {"range": "%s"}
659+ ` , masterName , POOL_IP_ADDRESSES [index ])
660+ }
661+ confStr := fmt .Sprintf (`{
662+ "cniVersion": "%s",
663+ "name": "multi-nic-sample",
664+ "type": "multi-nic",
665+ "plugin": {
666+ "cniVersion": "0.3.0",
667+ "type": "ipvlan",
668+ "mode": "l2"
669+ },
670+ "vlanMode": "l2",
671+ "ipam": {
672+ "type": "multi-config",
673+ "ipam_type": "whereabouts",
674+ "args": {
675+ %s
676+ }
677+ },
678+ "daemonIP": "%s",
679+ "daemonPort": %d,
680+ "subnet": "192.168.0.0/16",
681+ "masterNets": %s
682+ }` , ver , ipamArgs , BRIDGE_HOST_IP , daemonPort , masterNets )
683+ log .Printf ("%s" , confStr )
684+ conf := []byte (confStr )
685+ n := & NetConf {}
686+ err := json .Unmarshal (conf , n )
687+ Expect (err ).NotTo (HaveOccurred ())
688+ n .DeviceIDs = POOL_MASTER_NAMES
689+ n .Masters = POOL_MASTER_NAMES
690+ return conf , n
691+ }
692+
586693func closeServer (srv * http.Server , httpServerExitDone * sync.WaitGroup ) {
587694 if err := srv .Shutdown (context .TODO ()); err != nil {
588695 panic (err )
0 commit comments