v1.Service{
    ObjectMeta: metav1.ObjectMeta{Name: “foo”, Namespace: ns},
    Spec: v1.ServiceSpec{
    Selector: map[string]string{“foo”: “bar”},
    Ports: []v1.ServicePort{
    {Name: “port0”, Port: 80, Protocol: “TCP”, TargetPort: intstr.FromInt(8080)},
    {Name: “port1”, Port: 88, Protocol: “TCP”, TargetPort: intstr.FromInt(8088)},
    },
    },
    }

    从service构建endpoint

    1. 先构建多条EndpointSubset,每一条对应: 一个servicePort+ podId +targetPort
    2. 再按照EndpointPort 的 port聚合一下 Address信息
    3. 再按照Address 信息 聚合一下 EndpointPort

    expectedSubsets := []v1.EndpointSubset{{
    Addresses: []v1.EndpointAddress{
    {IP: “1.2.3.4”, NodeName: &emptyNodeName, TargetRef: &v1.ObjectReference{Kind: “Pod”, Name: “pod0”, Namespace: ns}},
    {IP: “1.2.3.5”, NodeName: &emptyNodeName, TargetRef: &v1.ObjectReference{Kind: “Pod”, Name: “pod1”, Namespace: ns}},
    {IP: “1.2.3.6”, NodeName: &emptyNodeName, TargetRef: &v1.ObjectReference{Kind: “Pod”, Name: “pod2”, Namespace: ns}},
    },
    Ports: []v1.EndpointPort{
    //这里的Port是targetPort,name对应的是ServicePort的name
    {Name: “port0”, Port: 8080, Protocol: “TCP”},
    {Name: “port1”, Port: 8088, Protocol: “TCP”},
    },
    }}