Skip to content

Commit

Permalink
Merge pull request #207 from nilo19/t-qini-verify_stadnard_lb
Browse files Browse the repository at this point in the history
Add test cases for standard load balancer.
  • Loading branch information
k8s-ci-robot committed Aug 7, 2019
2 parents dd7ed4d + ead3e8f commit d354ff7
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 4 deletions.
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() {
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

0 comments on commit d354ff7

Please sign in to comment.