From edda3f46b194c990499d224f096d3a99aa6cdf49 Mon Sep 17 00:00:00 2001 From: Yu Liao Date: Thu, 30 Jan 2020 11:05:46 -0800 Subject: [PATCH] added test case TestBasicWindows that tests the basic ingress for 'windows' platform --- cmd/e2e-test/basic_test.go | 10 +++++++++- pkg/e2e/fixtures.go | 38 +++++++++++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/cmd/e2e-test/basic_test.go b/cmd/e2e-test/basic_test.go index 711c74ba1e..72e7439071 100644 --- a/cmd/e2e-test/basic_test.go +++ b/cmd/e2e-test/basic_test.go @@ -29,7 +29,15 @@ import ( "k8s.io/ingress-gce/pkg/utils/common" ) +func TestBasicWindows(t *testing.T) { + testBasicOS(t, e2e.Windows) +} + func TestBasic(t *testing.T) { + testBasicOS(t, e2e.Linux) +} + +func testBasicOS(t *testing.T, os e2e.OS) { t.Parallel() port80 := intstr.FromInt(80) @@ -64,7 +72,7 @@ func TestBasic(t *testing.T) { ctx := context.Background() - _, err := e2e.CreateEchoService(s, "service-1", nil) + _, err := e2e.CreateEchoServiceOS(s, "service-1", nil, os) if err != nil { t.Fatalf("error creating echo service: %v", err) } diff --git a/pkg/e2e/fixtures.go b/pkg/e2e/fixtures.go index 50b3730f35..45709514ea 100644 --- a/pkg/e2e/fixtures.go +++ b/pkg/e2e/fixtures.go @@ -48,8 +48,16 @@ import ( ) const ( - echoheadersImage = "gcr.io/k8s-ingress-image-push/ingress-gce-echo-amd64:master" - porterPort = 80 + echoheadersImage = "gcr.io/k8s-ingress-image-push/ingress-gce-echo-amd64:master" + echoheadersImageWindows = "gcr.io/gke-windows-testing/ingress-gce-echo-amd64-windows:master" + porterPort = 80 +) + +type OS int + +const ( + Linux OS = 0 + Windows OS = 1 ) var ErrSubnetExists = fmt.Errorf("ILB subnet in region already exists") @@ -81,9 +89,19 @@ func CreateEchoService(s *Sandbox, name string, annotations map[string]string) ( return EnsureEchoService(s, name, annotations, v1.ServiceTypeNodePort, 1) } +// CreateEchoServiceOS creates the pod and service serving echoheaders +// Todo: (shance) remove this and replace uses with EnsureEchoService() +func CreateEchoServiceOS(s *Sandbox, name string, annotations map[string]string, os OS) (*v1.Service, error) { + return ensureEchoServiceOS(s, name, annotations, v1.ServiceTypeNodePort, 1, os) +} + // EnsureEchoService that the Echo service with the given description is set up func EnsureEchoService(s *Sandbox, name string, annotations map[string]string, svcType v1.ServiceType, numReplicas int32) (*v1.Service, error) { - if err := EnsureEchoDeployment(s, name, numReplicas, NoopModify); err != nil { + return ensureEchoServiceOS(s, name, annotations, svcType, numReplicas, Linux) +} + +func ensureEchoServiceOS(s *Sandbox, name string, annotations map[string]string, svcType v1.ServiceType, numReplicas int32, os OS) (*v1.Service, error) { + if err := ensureEchoDeploymentOS(s, name, numReplicas, NoopModify, os); err != nil { return nil, err } @@ -135,6 +153,14 @@ func EnsureEchoService(s *Sandbox, name string, annotations map[string]string, s // EnsureEchoDeployment ensures that the Echo deployment with the given description is set up func EnsureEchoDeployment(s *Sandbox, name string, numReplicas int32, modify func(deployment *apps.Deployment)) error { + return ensureEchoDeploymentOS(s, name, numReplicas, modify, Linux) +} + +func ensureEchoDeploymentOS(s *Sandbox, name string, numReplicas int32, modify func(deployment *apps.Deployment), os OS) error { + image := echoheadersImage + if os == Windows { + image = echoheadersImageWindows + } podTemplate := v1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Name: name, @@ -144,7 +170,7 @@ func EnsureEchoDeployment(s *Sandbox, name string, numReplicas int32, modify fun Containers: []v1.Container{ { Name: "echoheaders", - Image: echoheadersImage, + Image: image, Ports: []v1.ContainerPort{ {ContainerPort: 8080, Name: "http-port"}, {ContainerPort: 8443, Name: "https-port"}, @@ -179,7 +205,9 @@ func EnsureEchoDeployment(s *Sandbox, name string, numReplicas int32, modify fun }, }, } - + if os == Windows { + podTemplate.Spec.NodeSelector = map[string]string{"kubernetes.io/os": "windows"} + } deployment := &apps.Deployment{ ObjectMeta: metav1.ObjectMeta{Name: name}, Spec: apps.DeploymentSpec{