Merge pull request #59299 from hanxiaoshuai/fixtodo0203

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

fix todo: use the ServiceTestJig replace of service in e2e/network/service.go

**What this PR does / why we need it**:
fix todo: use the ServiceTestJig replace of service in e2e/network/service.go
**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes #

**Special notes for your reviewer**:

**Release note**:

```release-note
NONE
```
pull/8/head
Kubernetes Submit Queue 2018-03-23 23:34:25 -07:00 committed by GitHub
commit 122122c7fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 33 deletions

View File

@ -211,6 +211,20 @@ func (j *ServiceTestJig) CreateExternalNameServiceOrFail(namespace string, tweak
return result
}
// CreateServiceWithServicePort creates a new Service with ServicePort.
func (j *ServiceTestJig) CreateServiceWithServicePort(labels map[string]string, namespace string, ports []v1.ServicePort) (*v1.Service, error) {
service := &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: j.Name,
},
Spec: v1.ServiceSpec{
Selector: labels,
Ports: ports,
},
}
return j.Client.CoreV1().Services(namespace).Create(service)
}
func (j *ServiceTestJig) ChangeServiceType(namespace, name string, newType v1.ServiceType, timeout time.Duration) {
ingressIP := ""
svc := j.UpdateServiceOrFail(namespace, name, func(s *v1.Service) {

View File

@ -84,9 +84,9 @@ var _ = SIGDescribe("Services", func() {
valid/accessible endpoints (same port number for service and pods).
*/
framework.ConformanceIt("should serve a basic endpoint from pods ", func() {
// TODO: use the ServiceTestJig here
serviceName := "endpoint-test2"
ns := f.Namespace.Name
jig := framework.NewServiceTestJig(cs, serviceName)
labels := map[string]string{
"foo": "bar",
"baz": "blah",
@ -97,20 +97,12 @@ var _ = SIGDescribe("Services", func() {
err := cs.CoreV1().Services(ns).Delete(serviceName, nil)
Expect(err).NotTo(HaveOccurred())
}()
service := &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: serviceName,
},
Spec: v1.ServiceSpec{
Selector: labels,
Ports: []v1.ServicePort{{
ports := []v1.ServicePort{{
Port: 80,
TargetPort: intstr.FromInt(80),
}},
},
}
_, err := cs.CoreV1().Services(ns).Create(service)
}}
_, err := jig.CreateServiceWithServicePort(labels, ns, ports)
Expect(err).NotTo(HaveOccurred())
framework.ValidateEndpointsOrFail(cs, ns, serviceName, framework.PortsByPodName{})
@ -149,10 +141,10 @@ var _ = SIGDescribe("Services", func() {
valid/accessible endpoints (different port number for pods).
*/
framework.ConformanceIt("should serve multiport endpoints from pods ", func() {
// TODO: use the ServiceTestJig here
// repacking functionality is intentionally not tested here - it's better to test it in an integration test.
serviceName := "multi-endpoint-test"
ns := f.Namespace.Name
jig := framework.NewServiceTestJig(cs, serviceName)
defer func() {
err := cs.CoreV1().Services(ns).Delete(serviceName, nil)
@ -165,13 +157,7 @@ var _ = SIGDescribe("Services", func() {
svc2port := "svc2"
By("creating service " + serviceName + " in namespace " + ns)
service := &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: serviceName,
},
Spec: v1.ServiceSpec{
Selector: labels,
Ports: []v1.ServicePort{
ports := []v1.ServicePort{
{
Name: "portname1",
Port: 80,
@ -182,10 +168,8 @@ var _ = SIGDescribe("Services", func() {
Port: 81,
TargetPort: intstr.FromString(svc2port),
},
},
},
}
_, err := cs.CoreV1().Services(ns).Create(service)
_, err := jig.CreateServiceWithServicePort(labels, ns, ports)
Expect(err).NotTo(HaveOccurred())
port1 := 100
port2 := 101