diff --git a/cmd/e2e-test/basic_test.go b/cmd/e2e-test/basic_test.go index 711c74ba1e..e645231a05 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) { + testBasic(t, true) +} + func TestBasic(t *testing.T) { + testBasic(t, false) +} + +func testBasic(t *testing.T, windows bool) { t.Parallel() port80 := intstr.FromInt(80) diff --git a/cmd/e2e-test/main_test.go b/cmd/e2e-test/main_test.go index 08f1e2477f..2a2516ce70 100644 --- a/cmd/e2e-test/main_test.go +++ b/cmd/e2e-test/main_test.go @@ -50,6 +50,7 @@ var ( gceEndpointOverride string createILBSubnet bool enableIstio bool + windows bool } Framework *e2e.Framework @@ -73,6 +74,7 @@ func init() { flag.StringVar(&flags.gceEndpointOverride, "gce-endpoint-override", "", "If set, talks to a different GCE API Endpoint. By default it talks to https://www.googleapis.com/compute/v1/") flag.BoolVar(&flags.createILBSubnet, "createILBSubnet", false, "If set, creates a proxy subnet for the L7 ILB") flag.BoolVar(&flags.enableIstio, "enable-istio", false, "set to true if Istio is enabled.") + flag.BoolVar(&flags.windows, "windows", false, "If set, run backend on windows node") } // TestMain is the entrypoint for the end-to-end test suite. This is where @@ -129,6 +131,7 @@ func TestMain(m *testing.M) { GceEndpointOverride: flags.gceEndpointOverride, CreateILBSubnet: flags.createILBSubnet, EnableIstio: flags.enableIstio, + Windows: flags.windows, }) if flags.handleSIGINT { Framework.CatchSIGINT() diff --git a/pkg/e2e/fixtures.go b/pkg/e2e/fixtures.go index 50b3730f35..bc12336661 100644 --- a/pkg/e2e/fixtures.go +++ b/pkg/e2e/fixtures.go @@ -48,8 +48,9 @@ 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 ) var ErrSubnetExists = fmt.Errorf("ILB subnet in region already exists") @@ -81,9 +82,19 @@ func CreateEchoService(s *Sandbox, name string, annotations map[string]string) ( return EnsureEchoService(s, name, annotations, v1.ServiceTypeNodePort, 1) } +// CreateEchoService 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 string) (*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, "") +} + +func ensureEchoServiceOS(s *Sandbox, name string, annotations map[string]string, svcType v1.ServiceType, numReplicas int32, os string) (*v1.Service, error) { + if err := ensureEchoDeploymentOS(s, name, numReplicas, NoopModify, os); err != nil { return nil, err } @@ -135,16 +146,25 @@ 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, "") +} + +func ensureEchoDeploymentOS(s *Sandbox, name string, numReplicas int32, modify func(deployment *apps.Deployment), os string) error { + image := echoheadersImage + if os == "windows" { + image = echoheadersImageWindows + } podTemplate := v1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Name: name, Labels: map[string]string{"app": name}, }, Spec: v1.PodSpec{ + NodeSelector: map[string]string{"kubernetes.io/os": "windows"}, Containers: []v1.Container{ { Name: "echoheaders", - Image: echoheadersImage, + Image: image, Ports: []v1.ContainerPort{ {ContainerPort: 8080, Name: "http-port"}, {ContainerPort: 8443, Name: "https-port"}, @@ -179,7 +199,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{ diff --git a/pkg/e2e/framework.go b/pkg/e2e/framework.go index 417bbed332..1a1cf56f60 100644 --- a/pkg/e2e/framework.go +++ b/pkg/e2e/framework.go @@ -51,6 +51,7 @@ type Options struct { GceEndpointOverride string CreateILBSubnet bool EnableIstio bool + Windows bool } const ( @@ -83,6 +84,7 @@ func NewFramework(config *rest.Config, options Options) *Framework { Rand: rand.New(rand.NewSource(options.Seed)), destroySandboxes: options.DestroySandboxes, CreateILBSubnet: options.CreateILBSubnet, + Windows: options.Windows, } f.statusManager = NewStatusManager(f) if options.EnableIstio { @@ -113,6 +115,7 @@ type Framework struct { destroySandboxes bool CreateILBSubnet bool + Windows bool lock sync.Mutex sandboxes []*Sandbox