diff --git a/test/e2e/kubernetes/deployment/deployment.go b/test/e2e/kubernetes/deployment/deployment.go index cd109ff5e1..8da1f8366a 100644 --- a/test/e2e/kubernetes/deployment/deployment.go +++ b/test/e2e/kubernetes/deployment/deployment.go @@ -187,6 +187,17 @@ func (d *Deployment) Expose(svcType string, targetPort, exposedPort int) error { return nil } +// ScaleDeployment scales a deployment to n instancees +func (d *Deployment) ScaleDeployment(n int) error { + cmd := exec.Command("kubectl", "scale", fmt.Sprintf("--replicas=%d", n), "deployment", d.Metadata.Name) + out, err := util.RunAndLogCommand(cmd) + if err != nil { + log.Printf("Error while scaling deployment %s to %d pods:%s\n", d.Metadata.Name, n, string(out)) + return err + } + return nil +} + // CreateDeploymentHPA applies autoscale characteristics to deployment func (d *Deployment) CreateDeploymentHPA(cpuPercent, min, max int) error { cmd := exec.Command("kubectl", "autoscale", "deployment", d.Metadata.Name, fmt.Sprintf("--cpu-percent=%d", cpuPercent), diff --git a/test/e2e/kubernetes/kubernetes_test.go b/test/e2e/kubernetes/kubernetes_test.go index 895a4ace75..ee7b454bbf 100644 --- a/test/e2e/kubernetes/kubernetes_test.go +++ b/test/e2e/kubernetes/kubernetes_test.go @@ -1014,6 +1014,109 @@ var _ = Describe("Azure Container Cluster using the Kubernetes Orchestrator", fu } }) + It("should be able to scale an iis webserver", func() { + if eng.HasWindowsAgents() { + iisImage := "microsoft/iis:windowsservercore-1803" // BUG: This should be set based on the host OS version + + By("Creating a deployment with 1 pod running IIS") + r := rand.New(rand.NewSource(time.Now().UnixNano())) + deploymentName := fmt.Sprintf("iis-%s-%v", cfg.Name, r.Intn(99999)) + iisDeploy, err := deployment.CreateWindowsDeploy(iisImage, deploymentName, "default", 80, -1) + Expect(err).NotTo(HaveOccurred()) + + By("Waiting on pod to be Ready") + running, err := pod.WaitOnReady(deploymentName, "default", 3, 30*time.Second, cfg.Timeout) + Expect(err).NotTo(HaveOccurred()) + Expect(running).To(Equal(true)) + + By("Exposing a LoadBalancer for the pod") + err = iisDeploy.Expose("LoadBalancer", 80, 80) + Expect(err).NotTo(HaveOccurred()) + iisService, err := service.Get(deploymentName, "default") + Expect(err).NotTo(HaveOccurred()) + + By("Verifying that the service is reachable and returns the default IIS start page") + valid := iisService.Validate("(IIS Windows Server)", 10, 10*time.Second, cfg.Timeout) + Expect(valid).To(BeTrue()) + + By("Checking that each pod can reach http://www.bing.com") + iisPods, err := iisDeploy.Pods() + Expect(err).NotTo(HaveOccurred()) + Expect(len(iisPods)).ToNot(BeZero()) + for _, iisPod := range iisPods { + pass, err := iisPod.CheckWindowsOutboundConnection("www.bing.com", 10*time.Second, cfg.Timeout) + Expect(err).NotTo(HaveOccurred()) + Expect(pass).To(BeTrue()) + } + + By("Scaling deployment to 5 pods") + err = iisDeploy.ScaleDeployment(5) + Expect(err).NotTo(HaveOccurred()) + _, err = iisDeploy.WaitForReplicas(5, 5, 2*time.Second, cfg.Timeout) + Expect(err).NotTo(HaveOccurred()) + + By("Waiting on 5 pods to be Ready") + running, err = pod.WaitOnReady(deploymentName, "default", 3, 30*time.Second, cfg.Timeout) + Expect(err).NotTo(HaveOccurred()) + Expect(running).To(Equal(true)) + iisPods, err = iisDeploy.Pods() + Expect(err).NotTo(HaveOccurred()) + Expect(len(iisPods)).To(Equal(5)) + + By("Verifying that the service is reachable and returns the default IIS start page") + valid = iisService.Validate("(IIS Windows Server)", 10, 10*time.Second, cfg.Timeout) + Expect(valid).To(BeTrue()) + + By("Checking that each pod can reach http://www.bing.com") + iisPods, err = iisDeploy.Pods() + Expect(err).NotTo(HaveOccurred()) + Expect(len(iisPods)).ToNot(BeZero()) + for _, iisPod := range iisPods { + pass, err := iisPod.CheckWindowsOutboundConnection("www.bing.com", 10*time.Second, cfg.Timeout) + Expect(err).NotTo(HaveOccurred()) + Expect(pass).To(BeTrue()) + } + + By("Checking that no pods restart") + for _, iisPod := range iisPods { + log.Printf("Checking %s", iisPod.Metadata.Name) + Expect(iisPod.Status.ContainerStatuses[0].Ready).To(BeTrue()) + Expect(iisPod.Status.ContainerStatuses[0].RestartCount).To(Equal(0)) + } + + By("Scaling deployment to 2 pods") + err = iisDeploy.ScaleDeployment(2) + Expect(err).NotTo(HaveOccurred()) + _, err = iisDeploy.WaitForReplicas(2, 2, 2*time.Second, cfg.Timeout) + Expect(err).NotTo(HaveOccurred()) + iisPods, err = iisDeploy.Pods() + Expect(err).NotTo(HaveOccurred()) + Expect(len(iisPods)).To(Equal(2)) + + By("Verifying that the service is reachable and returns the default IIS start page") + valid = iisService.Validate("(IIS Windows Server)", 10, 10*time.Second, cfg.Timeout) + Expect(valid).To(BeTrue()) + + By("Checking that each pod can reach http://www.bing.com") + iisPods, err = iisDeploy.Pods() + Expect(err).NotTo(HaveOccurred()) + Expect(len(iisPods)).ToNot(BeZero()) + for _, iisPod := range iisPods { + pass, err := iisPod.CheckWindowsOutboundConnection("www.bing.com", 10*time.Second, cfg.Timeout) + Expect(err).NotTo(HaveOccurred()) + Expect(pass).To(BeTrue()) + } + + By("Verifying pods & services can be deleted") + err = iisDeploy.Delete(deleteResourceRetries) + Expect(err).NotTo(HaveOccurred()) + err = iisService.Delete(deleteResourceRetries) + Expect(err).NotTo(HaveOccurred()) + } else { + Skip("No windows agent was provisioned for this Cluster Definition") + } + }) + It("should be able to resolve DNS across windows and linux deployments", func() { if eng.HasWindowsAgents() { iisImage := "microsoft/iis:windowsservercore-1803" // BUG: This should be set based on the host OS version