Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add nat gw e2e #2639

Merged
merged 20 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,13 @@ kind-install-multus:
kubectl apply -f "$(MULTUS_YAML)"
kubectl -n kube-system rollout status ds kube-multus-ds

.PHONY: kind-install-vpc-nat-gw
kind-install-vpc-nat-gw: kind-load-image kind-untaint-control-plane
$(call kind_load_image,kube-ovn,$(VPC_NAT_GW_IMG))
@$(MAKE) ENABLE_NAT_GW=true CNI_CONFIG_PRIORITY=10 kind-install
@$(MAKE) kind-install-multus
kubectl apply -f yamls/vpc-nat-gw-attachment.yaml

.PHONY: kind-install-kubevirt
kind-install-kubevirt: kind-load-image kind-untaint-control-plane
$(call kind_load_image,kube-ovn,$(KUBEVIRT_OPERATOR_IMAGE),1)
Expand Down
2 changes: 1 addition & 1 deletion Makefile.e2e
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ iptables-vpc-nat-gw-conformance-e2e:
E2E_BRANCH=$(E2E_BRANCH) \
E2E_IP_FAMILY=$(E2E_IP_FAMILY) \
E2E_NETWORK_MODE=$(E2E_NETWORK_MODE) \
ginkgo --randomize-all --always-emit-ginkgo-writer \
ginkgo $(GINKGO_PARALLEL_OPT) --randomize-all --always-emit-ginkgo-writer \
--focus=CNI:Kube-OVN ./test/e2e/iptables-vpc-nat-gw/iptables-vpc-nat-gw.test

.PHONY: ovn-vpc-nat-gw-conformance-e2e
Expand Down
9 changes: 9 additions & 0 deletions dist/images/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ LS_DNAT_MOD_DL_DST=${LS_DNAT_MOD_DL_DST:-true}
ENABLE_EXTERNAL_VPC=${ENABLE_EXTERNAL_VPC:-true}
CNI_CONFIG_PRIORITY=${CNI_CONFIG_PRIORITY:-01}
ENABLE_LB_SVC=${ENABLE_LB_SVC:-false}
ENABLE_NAT_GW=${ENABLE_NAT_GW:-false}
ENABLE_KEEP_VM_IP=${ENABLE_KEEP_VM_IP:-true}
# exchange link names of OVS bridge and the provider nic
# in the default provider-network
Expand Down Expand Up @@ -3473,6 +3474,14 @@ metadata:
data:
image: $REGISTRY/$VPC_NAT_IMAGE:$VERSION
---
kind: ConfigMap
apiVersion: v1
metadata:
name: ovn-vpc-nat-gw-config
namespace: kube-system
data:
enable-vpc-nat-gw: "$ENABLE_NAT_GW"
---
kind: Deployment
apiVersion: apps/v1
metadata:
Expand Down
75 changes: 18 additions & 57 deletions test/e2e/iptables-vpc-nat-gw/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"testing"

dockertypes "github.com/docker/docker/api/types"
nadv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
attachnetclientset "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/client/clientset/versioned"
"github.com/onsi/ginkgo/v2"
clientset "k8s.io/client-go/kubernetes"
Expand All @@ -24,10 +23,8 @@ import (
"github.com/kubeovn/kube-ovn/pkg/util"
"github.com/kubeovn/kube-ovn/test/e2e/framework"
"github.com/kubeovn/kube-ovn/test/e2e/framework/docker"
"github.com/kubeovn/kube-ovn/test/e2e/framework/iproute"
"github.com/kubeovn/kube-ovn/test/e2e/framework/kind"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -36,25 +33,13 @@ const vpcNatGWConfigMapName = "ovn-vpc-nat-gw-config"
const networkAttachDefName = "ovn-vpc-external-network"
const externalSubnetProvider = "ovn-vpc-external-network.kube-system"

func makeNetworkAttachmentDefinition(name, config string) *nadv1.NetworkAttachmentDefinition {
netAttachDef := nadv1.NetworkAttachmentDefinition{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: nadv1.NetworkAttachmentDefinitionSpec{Config: config},
}
return &netAttachDef
}

var _ = framework.Describe("[group:iptables-vpc-nat-gw]", func() {
f := framework.NewDefaultFramework("iptables-vpc-nat-gw")

var skip bool
var cs clientset.Interface
var attachNetClient attachnetclientset.Interface
var nodeNames []string
var clusterName, vpcName, vpcNatGwName, overlaySubnetName string
var linkMap map[string]*iproute.Link
var vpcClient *framework.VpcClient
var vpcNatGwClient *framework.VpcNatGatewayClient
var subnetClient *framework.SubnetClient
Expand Down Expand Up @@ -138,24 +123,26 @@ var _ = framework.Describe("[group:iptables-vpc-nat-gw]", func() {
nodes, err = kind.ListNodes(clusterName, "")
framework.ExpectNoError(err, "getting nodes in kind cluster")

linkMap = make(map[string]*iproute.Link, len(nodes))
nodeNames = make([]string, 0, len(nodes))

ginkgo.By("Validating node links")
var eth0Exist, eth1Exist bool
for _, node := range nodes {
links, err := node.ListLinks()
framework.ExpectNoError(err, "failed to list links on node %s: %v", node.Name(), err)

for _, link := range links {
if link.Address == node.NetworkSettings.Networks[dockerNetworkName].MacAddress {
linkMap[node.ID] = &link
break
ginkgo.By("exist node nic " + link.IfName)
if link.IfName == "eth0" {
eth0Exist = true
}
if link.IfName == "eth1" {
eth1Exist = true
}
}
framework.ExpectHaveKey(linkMap, node.ID)
linkMap[node.Name()] = linkMap[node.ID]
nodeNames = append(nodeNames, node.Name())
framework.ExpectTrue(eth0Exist)
// nat gw pod use eth1 in this case
// retest this case should rebuild kind cluster
framework.ExpectTrue(eth1Exist)
}

})

ginkgo.AfterEach(func() {
Expand Down Expand Up @@ -194,27 +181,11 @@ var _ = framework.Describe("[group:iptables-vpc-nat-gw]", func() {
_, err = e2enode.GetReadySchedulableNodes(cs)
framework.ExpectNoError(err)

ginkgo.By("Creating network attachment fefinition " + networkAttachDefName)
nadConfig := `{
"cniVersion": "0.3.0",
"type": "macvlan",
"master": "eth1",
"mode": "bridge",
"ipam": {
"type": "kube-ovn",
"server_socket": "/run/openvswitch/kube-ovn-daemon.sock",
"provider": "ovn-vpc-external-network.kube-system"
}
}`

ginkgo.By("Getting network attachment fefinition " + networkAttachDefName)
networkClient := attachNetClient.K8sCniCncfIoV1().NetworkAttachmentDefinitions("kube-system")
nad := makeNetworkAttachmentDefinition(networkAttachDefName, nadConfig)
_, err = networkClient.Create(context.Background(), nad, metav1.CreateOptions{})
framework.ExpectNoError(err, "failed to create")

nad, err = networkClient.Get(context.Background(), networkAttachDefName, metav1.GetOptions{})
ginkgo.By("Got network attachment fefinition " + nad.Name)
nad, err := networkClient.Get(context.Background(), networkAttachDefName, metav1.GetOptions{})
framework.ExpectNoError(err, "failed to get")
ginkgo.By("Got network attachment fefinition " + nad.Name)
zbb88888 marked this conversation as resolved.
Show resolved Hide resolved

ginkgo.By("Creating underlay macvlan subnet " + networkAttachDefName)
cidr := make([]string, 0, 2)
Expand Down Expand Up @@ -245,19 +216,9 @@ var _ = framework.Describe("[group:iptables-vpc-nat-gw]", func() {
macvlanSubnet := framework.MakeSubnet(networkAttachDefName, "", strings.Join(cidr, ","), strings.Join(gateway, ","), "", externalSubnetProvider, excludeIPs, nil, nil)
_ = subnetClient.CreateSync(macvlanSubnet)

ginkgo.By("Creating config map " + vpcNatGWConfigMapName)
cmData := map[string]string{
"enable-vpc-nat-gw": "true",
}
configMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: vpcNatGWConfigMapName,
Namespace: "kube-system",
},
Data: cmData,
}
_, err = cs.CoreV1().ConfigMaps("kube-system").Create(context.Background(), configMap, metav1.CreateOptions{})
framework.ExpectNoError(err, "failed to create ConfigMap")
ginkgo.By("Getting config map " + vpcNatGWConfigMapName)
_, err = cs.CoreV1().ConfigMaps("kube-system").Get(context.Background(), vpcNatGWConfigMapName, metav1.GetOptions{})
framework.ExpectNoError(err, "failed to get ConfigMap")

ginkgo.By("Creating custom vpc")
overlaySubnetV4Cidr := "192.168.0.0/24"
Expand Down
7 changes: 7 additions & 0 deletions yamls/vpc-nat-gw-attachment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: k8s.cni.cncf.io/v1
kind: NetworkAttachmentDefinition
metadata:
name: ovn-vpc-external-network
namespace: kube-system
spec:
config: '{"cniVersion": "0.3.0","type": "macvlan","master": "eth1","mode": "bridge"}'
zbb88888 marked this conversation as resolved.
Show resolved Hide resolved