github.com/midokura/kubeedge@v1.2.0-mido.0/tests/performance/loadtest/loadtest_suite_test.go (about)

     1  /*
     2  Copyright 2019 The KubeEdge Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8     http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  package loadtest
    17  
    18  import (
    19  	"strconv"
    20  	"strings"
    21  	"testing"
    22  	"time"
    23  
    24  	. "github.com/onsi/ginkgo"
    25  	. "github.com/onsi/gomega"
    26  	metav1 "k8s.io/api/core/v1"
    27  
    28  	"github.com/kubeedge/kubeedge/tests/e2e/utils"
    29  	. "github.com/kubeedge/kubeedge/tests/performance/common"
    30  	"github.com/kubeedge/viaduct/pkg/api"
    31  )
    32  
    33  //context to load config and access across the package
    34  var (
    35  	ctx               *utils.TestContext
    36  	cfg               utils.Config
    37  	nodeSelector      string
    38  	cloudHubURL       string
    39  	wsscloudHubURL    string
    40  	quiccloudHubURL   string
    41  	cloudCoreNodeName string
    42  )
    43  
    44  func TestEdgecoreK8sDeployment(t *testing.T) {
    45  	var cloudCoreHostIP string
    46  	var podlist metav1.PodList
    47  	//var toTaint bool
    48  	RegisterFailHandler(Fail)
    49  	var _ = BeforeSuite(func() {
    50  		utils.Infof("Kubeedge deployment Load test Begin !!")
    51  		cfg = utils.LoadConfig()
    52  		ctx = utils.NewTestContext(cfg)
    53  		//apply label to all cluster nodes, use the selector to deploy all edgenodes to cluster nodes
    54  		err := ApplyLabel(ctx.Cfg.K8SMasterForProvisionEdgeNodes + NodeHandler)
    55  		Expect(err).Should(BeNil())
    56  		//Create configMap for CloudCore
    57  		CloudConfigMap = "cloudcore-configmap-" + utils.GetRandomString(5)
    58  		CloudCoreDeployment = "cloudcore-deployment-" + utils.GetRandomString(5)
    59  		//protocol to be used for test between edge and cloud
    60  		if ctx.Cfg.Protocol == api.ProtocolTypeQuic {
    61  			IsQuicProtocol = true
    62  		} else {
    63  			IsQuicProtocol = false
    64  		}
    65  		//Deploye cloudcore as a k8s resource to cluster-1
    66  		err = HandleCloudDeployment(CloudConfigMap, CloudCoreDeployment, ctx.Cfg.K8SMasterForKubeEdge,
    67  			ctx.Cfg.K8SMasterForKubeEdge+ConfigmapHandler, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler, ctx.Cfg.CloudImageUrl, ctx.Cfg.NumOfNodes)
    68  		Expect(err).Should(BeNil())
    69  		time.Sleep(1 * time.Second)
    70  		//Get the cloudCore pod Node name and IP
    71  		podlist, err = utils.GetPods(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, "")
    72  		Expect(err).To(BeNil())
    73  		for _, pod := range podlist.Items {
    74  			if strings.Contains(pod.Name, "cloudcore-deployment") {
    75  				cloudCoreHostIP = pod.Status.HostIP
    76  				cloudCoreNodeName = pod.Spec.NodeName
    77  			}
    78  			break
    79  		}
    80  		utils.CheckPodRunningState(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, podlist)
    81  		time.Sleep(5 * time.Second)
    82  		//Create service for cloud
    83  		err = utils.ExposeCloudService(CloudCoreDeployment, ctx.Cfg.K8SMasterForKubeEdge+ServiceHandler)
    84  		Expect(err).Should(BeNil())
    85  		//Create a nodePort Service to access the cloud Service from the cluster nodes
    86  		wsPort, quicPort := utils.GetServicePort(CloudCoreDeployment, ctx.Cfg.K8SMasterForKubeEdge+ServiceHandler)
    87  		wsNodePort := strconv.FormatInt(int64(wsPort), 10)
    88  		quicNodePort := strconv.FormatInt(int64(quicPort), 10)
    89  		quiccloudHubURL = cloudCoreHostIP + ":" + quicNodePort
    90  		cloudHubURL = quiccloudHubURL
    91  		wsscloudHubURL = "wss://" + cloudCoreHostIP + ":" + wsNodePort
    92  		cloudHubURL = wsscloudHubURL
    93  
    94  		//Deploye edgecore as a k8s resource to cluster-2
    95  		podlist = HandleEdgeDeployment(cloudHubURL, ctx.Cfg.K8SMasterForProvisionEdgeNodes+DeploymentHandler, ctx.Cfg.K8SMasterForKubeEdge+NodeHandler,
    96  			ctx.Cfg.K8SMasterForProvisionEdgeNodes+ConfigmapHandler, ctx.Cfg.EdgeImageUrl, ctx.Cfg.K8SMasterForProvisionEdgeNodes+AppHandler, ctx.Cfg.NumOfNodes)
    97  
    98  		//skip the pod scheduling in k8s node while kubeedge nodes are available to schedule
    99  		ToTaint = true
   100  		err = utils.TaintEdgeDeployedNode(ToTaint, ctx.Cfg.K8SMasterForKubeEdge+NodeHandler+"/"+cloudCoreNodeName)
   101  		Expect(err).Should(BeNil())
   102  		ToTaint = false
   103  	})
   104  	AfterSuite(func() {
   105  		By("Kubeedge deployment Load test End !!....!")
   106  
   107  		DeleteEdgeDeployments(ctx.Cfg.K8SMasterForKubeEdge, ctx.Cfg.K8SMasterForProvisionEdgeNodes, ctx.Cfg.NumOfNodes)
   108  		utils.CheckDeploymentPodDeleteState(ctx.Cfg.K8SMasterForProvisionEdgeNodes, podlist)
   109  		//untaint Node
   110  		err := utils.TaintEdgeDeployedNode(ToTaint, ctx.Cfg.K8SMasterForKubeEdge+NodeHandler+"/"+cloudCoreNodeName)
   111  		Expect(err).Should(BeNil())
   112  		DeleteCloudDeployment(ctx.Cfg.K8SMasterForKubeEdge)
   113  
   114  	})
   115  
   116  	RunSpecs(t, "kubeedge Performace Load test Suite")
   117  }