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 test cases for standard load balancer. #207

Merged
merged 1 commit into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion tests/e2e/network/cross_rg_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"k8s.io/cloud-provider-azure/tests/e2e/utils"
)

var vmNameRE = regexp.MustCompile(`(k8s-.+-\d+)-\d+`)
var vmNameRE = regexp.MustCompile(`(k8s-.+-\d+)-.+`)

var _ = Describe("Cloud Provider Azure cross resource group nodes", func() {
basename := "service-lb"
Expand Down
112 changes: 112 additions & 0 deletions tests/e2e/network/standard_lb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
Copyright 2019 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package network

import (
"strings"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/intstr"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/cloud-provider-azure/tests/e2e/utils"
)

var _ = Describe("[StandardLoadBalancer] Standard load balancer", func() {
basename := "service-lb"
serviceName := "servicelb-test"

var cs clientset.Interface
var ns *v1.Namespace
var tc *utils.AzureTestClient

labels := map[string]string{
"app": serviceName,
}
ports := []v1.ServicePort{{
Port: nginxPort,
TargetPort: intstr.FromInt(nginxPort),
}}

BeforeEach(func() {
var err error
cs, err = utils.CreateKubeClientSet()
Expect(err).NotTo(HaveOccurred())

ns, err = utils.CreateTestingNamespace(basename, cs)
Expect(err).NotTo(HaveOccurred())

tc, err = utils.CreateAzureTestClient()
Expect(err).NotTo(HaveOccurred())

utils.Logf("Creating deployment " + serviceName)
deployment := createNginxDeploymentManifest(serviceName, labels)
_, err = cs.AppsV1().Deployments(ns.Name).Create(deployment)
Expect(err).NotTo(HaveOccurred())
})

AfterEach(func() {
err := cs.AppsV1().Deployments(ns.Name).Delete(serviceName, nil)
Expect(err).NotTo(HaveOccurred())

err = utils.DeleteNamespace(cs, ns.Name)
Expect(err).NotTo(HaveOccurred())

cs = nil
ns = nil
})

It("should add all nodes in different agent pools to backends [MultipleAgentPools]", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L89 could be moved here, and then use lb.sku.Name to check whether it's Standard LB.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remember use strings.EqualFold() instead of ==

rgName := tc.GetResourceGroup()
publicIP := createServiceWithAnnotation(cs, serviceName, ns.Name, labels, map[string]string{}, ports)
lb := getAzureLoadBalancerFromPIP(publicIP, rgName, rgName)

if !strings.EqualFold(string(lb.Sku.Name), "standard") {
Skip("only support standard load balancer")
}

nodeList, err := utils.GetAgentNodes(cs)
Expect(err).NotTo(HaveOccurred())
if len(nodeList) < 2 {
Skip("only support cluster with multiple agent pools")
}

lbBackendAddressPoolsIDMap := make(map[string]bool)
for _, backendAddressPool := range *lb.BackendAddressPools {
lbBackendAddressPoolsIDMap[*backendAddressPool.ID] = true
}

NICList, err := utils.ListNICs(tc, rgName)
Expect(err).NotTo(HaveOccurred())
var found bool
for _, nic := range *NICList {
if strings.Split(*nic.Name, "-")[1] == "master" {
continue
}
for _, ipConfig := range *nic.IPConfigurations {
for _, backendAddressPool := range *ipConfig.LoadBalancerBackendAddressPools {
if lbBackendAddressPoolsIDMap[*backendAddressPool.ID] {
found = true
}
}
}
Expect(found).To(BeTrue())
}
})
})
8 changes: 5 additions & 3 deletions tests/e2e/utils/network_interface_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ import (

var (
nicIDConfigurationRE = regexp.MustCompile(`^/subscriptions/(?:.*)/resourceGroups/(?:.*)/providers/Microsoft.Network/networkInterfaces/(.+)`)
vmNamePrefixRE = regexp.MustCompile(`(.+)-nic-\d+`)
vmasNamePrefixRE = regexp.MustCompile(`(.+)-nic-\d+`)
nicNameRE = regexp.MustCompile(`k8s-.+-\d+-.+`)
)

// ListNICs returns the NIC list in the given resource group
func ListNICs(tc *AzureTestClient, rgName string) (*[]network.Interface, error) {
Logf("Getting network interfaces list in resource group %s", rgName)
Logf("getting network interfaces list in resource group %s", rgName)

ic := tc.createInterfacesClient()

Expand All @@ -47,12 +48,13 @@ func ListNICs(tc *AzureTestClient, rgName string) (*[]network.Interface, error)
return &value, err
}

// virtual machine availability set only, NIC on VMSS has another naming pattern
func getVMNamePrefixFromNICID(nicID string) (string, error) {
nicMatches := nicIDConfigurationRE.FindStringSubmatch(nicID)
if len(nicMatches) != 2 {
return "", fmt.Errorf("cannot obtain the name of virtual machine from nicID")
}
vmMatches := vmNamePrefixRE.FindStringSubmatch(nicMatches[1])
vmMatches := vmasNamePrefixRE.FindStringSubmatch(nicMatches[1])
if len(vmMatches) != 2 {
return "", fmt.Errorf("cannot obtain the name of virtual machine from nicID")
}
Expand Down