mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
fix todo: use the ServiceTestJig replace of service
This commit is contained in:
parent
230726ffbe
commit
7c7be149d9
@ -211,6 +211,20 @@ func (j *ServiceTestJig) CreateExternalNameServiceOrFail(namespace string, tweak
|
|||||||
return result
|
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) {
|
func (j *ServiceTestJig) ChangeServiceType(namespace, name string, newType v1.ServiceType, timeout time.Duration) {
|
||||||
ingressIP := ""
|
ingressIP := ""
|
||||||
svc := j.UpdateServiceOrFail(namespace, name, func(s *v1.Service) {
|
svc := j.UpdateServiceOrFail(namespace, name, func(s *v1.Service) {
|
||||||
|
@ -84,9 +84,9 @@ var _ = SIGDescribe("Services", func() {
|
|||||||
valid/accessible endpoints (same port number for service and pods).
|
valid/accessible endpoints (same port number for service and pods).
|
||||||
*/
|
*/
|
||||||
framework.ConformanceIt("should serve a basic endpoint from pods ", func() {
|
framework.ConformanceIt("should serve a basic endpoint from pods ", func() {
|
||||||
// TODO: use the ServiceTestJig here
|
|
||||||
serviceName := "endpoint-test2"
|
serviceName := "endpoint-test2"
|
||||||
ns := f.Namespace.Name
|
ns := f.Namespace.Name
|
||||||
|
jig := framework.NewServiceTestJig(cs, serviceName)
|
||||||
labels := map[string]string{
|
labels := map[string]string{
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
"baz": "blah",
|
"baz": "blah",
|
||||||
@ -97,20 +97,12 @@ var _ = SIGDescribe("Services", func() {
|
|||||||
err := cs.CoreV1().Services(ns).Delete(serviceName, nil)
|
err := cs.CoreV1().Services(ns).Delete(serviceName, nil)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
}()
|
}()
|
||||||
|
ports := []v1.ServicePort{{
|
||||||
|
Port: 80,
|
||||||
|
TargetPort: intstr.FromInt(80),
|
||||||
|
}}
|
||||||
|
_, err := jig.CreateServiceWithServicePort(labels, ns, ports)
|
||||||
|
|
||||||
service := &v1.Service{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Name: serviceName,
|
|
||||||
},
|
|
||||||
Spec: v1.ServiceSpec{
|
|
||||||
Selector: labels,
|
|
||||||
Ports: []v1.ServicePort{{
|
|
||||||
Port: 80,
|
|
||||||
TargetPort: intstr.FromInt(80),
|
|
||||||
}},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
_, err := cs.CoreV1().Services(ns).Create(service)
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
framework.ValidateEndpointsOrFail(cs, ns, serviceName, framework.PortsByPodName{})
|
framework.ValidateEndpointsOrFail(cs, ns, serviceName, framework.PortsByPodName{})
|
||||||
@ -149,10 +141,10 @@ var _ = SIGDescribe("Services", func() {
|
|||||||
valid/accessible endpoints (different port number for pods).
|
valid/accessible endpoints (different port number for pods).
|
||||||
*/
|
*/
|
||||||
framework.ConformanceIt("should serve multiport endpoints from pods ", func() {
|
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.
|
// repacking functionality is intentionally not tested here - it's better to test it in an integration test.
|
||||||
serviceName := "multi-endpoint-test"
|
serviceName := "multi-endpoint-test"
|
||||||
ns := f.Namespace.Name
|
ns := f.Namespace.Name
|
||||||
|
jig := framework.NewServiceTestJig(cs, serviceName)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
err := cs.CoreV1().Services(ns).Delete(serviceName, nil)
|
err := cs.CoreV1().Services(ns).Delete(serviceName, nil)
|
||||||
@ -165,27 +157,19 @@ var _ = SIGDescribe("Services", func() {
|
|||||||
svc2port := "svc2"
|
svc2port := "svc2"
|
||||||
|
|
||||||
By("creating service " + serviceName + " in namespace " + ns)
|
By("creating service " + serviceName + " in namespace " + ns)
|
||||||
service := &v1.Service{
|
ports := []v1.ServicePort{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
{
|
||||||
Name: serviceName,
|
Name: "portname1",
|
||||||
|
Port: 80,
|
||||||
|
TargetPort: intstr.FromString(svc1port),
|
||||||
},
|
},
|
||||||
Spec: v1.ServiceSpec{
|
{
|
||||||
Selector: labels,
|
Name: "portname2",
|
||||||
Ports: []v1.ServicePort{
|
Port: 81,
|
||||||
{
|
TargetPort: intstr.FromString(svc2port),
|
||||||
Name: "portname1",
|
|
||||||
Port: 80,
|
|
||||||
TargetPort: intstr.FromString(svc1port),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "portname2",
|
|
||||||
Port: 81,
|
|
||||||
TargetPort: intstr.FromString(svc2port),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_, err := cs.CoreV1().Services(ns).Create(service)
|
_, err := jig.CreateServiceWithServicePort(labels, ns, ports)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
port1 := 100
|
port1 := 100
|
||||||
port2 := 101
|
port2 := 101
|
||||||
|
Loading…
Reference in New Issue
Block a user