|
4 | 4 | "encoding/json"
|
5 | 5 | "flag"
|
6 | 6 | "fmt"
|
| 7 | + "strings" |
7 | 8 | "testing"
|
8 | 9 |
|
9 | 10 | nadv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
|
@@ -498,4 +499,47 @@ var _ = framework.SerialDescribe("[group:multus]", func() {
|
498 | 499 | framework.ExpectContainElement(actualRoutes, request.Route{Destination: ipv6RouteDst, Gateway: ipv6RouteGw})
|
499 | 500 | }
|
500 | 501 | })
|
| 502 | + |
| 503 | + framework.ConformanceIt("should be able to use mac and ip provided by k8s.v1.cni.cncf.io/networks annotation", func() { |
| 504 | + provider := fmt.Sprintf("%s.%s.%s", nadName, namespaceName, util.OvnProvider) |
| 505 | + ginkgo.By("Creating network attachment definition " + nadName) |
| 506 | + nad := framework.MakeOVNNetworkAttachmentDefinition(nadName, namespaceName, provider, nil) |
| 507 | + nad = nadClient.Create(nad) |
| 508 | + framework.Logf("created network attachment definition config:\n%s", nad.Spec.Config) |
| 509 | + |
| 510 | + ginkgo.By("Creating subnet " + subnetName) |
| 511 | + subnet = framework.MakeSubnet(subnetName, "", cidr, "", "", provider, nil, nil, nil) |
| 512 | + subnet = subnetClient.CreateSync(subnet) |
| 513 | + |
| 514 | + ginkgo.By("Creating pod " + podName) |
| 515 | + mac := "00:00:00:11:22:33" |
| 516 | + randomIP := framework.RandomIPs(subnet.Spec.CIDRBlock, "", 1) |
| 517 | + |
| 518 | + randomIPArray := strings.Split(randomIP, ",") |
| 519 | + var requestIPString string |
| 520 | + for i, ip := range randomIPArray { |
| 521 | + if i == len(randomIPArray)-1 { |
| 522 | + requestIPString += fmt.Sprintf(`"%s"`, ip) |
| 523 | + } else { |
| 524 | + requestIPString += fmt.Sprintf(`"%s",`, ip) |
| 525 | + } |
| 526 | + } |
| 527 | + |
| 528 | + framework.Logf("requestIPString: %s", requestIPString) |
| 529 | + annotations := map[string]string{nadv1.NetworkAttachmentAnnot: fmt.Sprintf(`[{"name": "%s", "namespace": "%s", "mac": "%s", "ips": [%s]}]`, nad.Name, nad.Namespace, mac, requestIPString)} |
| 530 | + annotations[fmt.Sprintf(util.LogicalSwitchAnnotationTemplate, provider)] = subnetName |
| 531 | + |
| 532 | + cmd := []string{"sh", "-c", "sleep infinity"} |
| 533 | + pod := framework.MakePrivilegedPod(namespaceName, podName, nil, annotations, f.KubeOVNImage, cmd, nil) |
| 534 | + pod = podClient.CreateSync(pod) |
| 535 | + |
| 536 | + ginkgo.By("Validating pod annotations") |
| 537 | + framework.ExpectHaveKey(pod.Annotations, nadv1.NetworkStatusAnnot) |
| 538 | + framework.Logf("pod network status:\n%s", pod.Annotations[nadv1.NetworkStatusAnnot]) |
| 539 | + retMac := pod.Annotations[fmt.Sprintf(util.MacAddressAnnotationTemplate, provider)] |
| 540 | + retIP := pod.Annotations[fmt.Sprintf(util.IPAddressAnnotationTemplate, provider)] |
| 541 | + |
| 542 | + framework.ExpectEqual(mac, retMac) |
| 543 | + framework.ExpectEqual(strings.Join(randomIPArray, ","), retIP) |
| 544 | + }) |
501 | 545 | })
|
0 commit comments