service.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. Copyright 2019 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package windows
  14. import (
  15. "fmt"
  16. v1 "k8s.io/api/core/v1"
  17. clientset "k8s.io/client-go/kubernetes"
  18. "k8s.io/kubernetes/test/e2e/framework"
  19. e2enode "k8s.io/kubernetes/test/e2e/framework/node"
  20. e2eservice "k8s.io/kubernetes/test/e2e/framework/service"
  21. e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
  22. "github.com/onsi/ginkgo"
  23. )
  24. var _ = SIGDescribe("Services", func() {
  25. f := framework.NewDefaultFramework("services")
  26. var cs clientset.Interface
  27. ginkgo.BeforeEach(func() {
  28. //Only for Windows containers
  29. e2eskipper.SkipUnlessNodeOSDistroIs("windows")
  30. cs = f.ClientSet
  31. })
  32. ginkgo.It("should be able to create a functioning NodePort service for Windows", func() {
  33. serviceName := "nodeport-test"
  34. ns := f.Namespace.Name
  35. jig := e2eservice.NewTestJig(cs, ns, serviceName)
  36. nodeIP, err := e2enode.PickIP(jig.Client)
  37. framework.ExpectNoError(err)
  38. ginkgo.By("creating service " + serviceName + " with type=NodePort in namespace " + ns)
  39. svc, err := jig.CreateTCPService(func(svc *v1.Service) {
  40. svc.Spec.Type = v1.ServiceTypeNodePort
  41. })
  42. framework.ExpectNoError(err)
  43. nodePort := int(svc.Spec.Ports[0].NodePort)
  44. ginkgo.By("creating Pod to be part of service " + serviceName)
  45. _, err = jig.Run(nil)
  46. framework.ExpectNoError(err)
  47. //using hybrid_network methods
  48. ginkgo.By("creating Windows testing Pod")
  49. windowsPod := createTestPod(f, windowsBusyBoximage, windowsOS)
  50. ginkgo.By(fmt.Sprintf("checking connectivity Pod to curl http://%s:%d", nodeIP, nodePort))
  51. assertConsistentConnectivity(f, windowsPod.ObjectMeta.Name, windowsOS, windowsCheck(fmt.Sprintf("http://%s:%d", nodeIP, nodePort)))
  52. })
  53. })