
Instead of endpoints being a flat list, it is now a list of "subsets" where each is a struct of {Addresses, Ports}. To generate the list of endpoints you need to take union of the Cartesian products of the subsets. This is compact in the vast majority of cases, yet still represents named ports and corner cases (e.g. each pod has a different port number). This also stores subsets in a deterministic order (sorted by hash) to avoid spurious updates and comparison problems. This is a fully compatible change - old objects and clients will keepworking as long as they don't need the new functionality. This is the prep for multi-port Services, which will add API to produce endpoints in this new structure.
69 lines
2.2 KiB
Go
69 lines
2.2 KiB
Go
/*
|
|
Copyright 2015 Google Inc. All rights reserved.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package client
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
|
)
|
|
|
|
func TestListEndpoints(t *testing.T) {
|
|
ns := api.NamespaceDefault
|
|
c := &testClient{
|
|
Request: testRequest{Method: "GET", Path: testapi.ResourcePath("endpoints", ns, ""), Query: buildQueryValues(ns, nil)},
|
|
Response: Response{StatusCode: 200,
|
|
Body: &api.EndpointsList{
|
|
Items: []api.Endpoints{
|
|
{
|
|
ObjectMeta: api.ObjectMeta{Name: "endpoint-1"},
|
|
Subsets: []api.EndpointSubset{{
|
|
Addresses: []api.EndpointAddress{{IP: "10.245.1.2"}, {IP: "10.245.1.3"}},
|
|
Ports: []api.EndpointPort{{Port: 8080}},
|
|
}},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
receivedEndpointsList, err := c.Setup().Endpoints(ns).List(labels.Everything())
|
|
c.Validate(t, receivedEndpointsList, err)
|
|
}
|
|
|
|
func TestGetEndpoints(t *testing.T) {
|
|
ns := api.NamespaceDefault
|
|
c := &testClient{
|
|
Request: testRequest{Method: "GET", Path: testapi.ResourcePath("endpoints", ns, "endpoint-1"), Query: buildQueryValues(ns, nil)},
|
|
Response: Response{StatusCode: 200, Body: &api.Endpoints{ObjectMeta: api.ObjectMeta{Name: "endpoint-1"}}},
|
|
}
|
|
response, err := c.Setup().Endpoints(ns).Get("endpoint-1")
|
|
c.Validate(t, response, err)
|
|
}
|
|
|
|
func TestGetEndpointWithNoName(t *testing.T) {
|
|
ns := api.NamespaceDefault
|
|
c := &testClient{Error: true}
|
|
receivedPod, err := c.Setup().Endpoints(ns).Get("")
|
|
if (err != nil) && (err.Error() != nameRequiredError) {
|
|
t.Errorf("Expected error: %v, but got %v", nameRequiredError, err)
|
|
}
|
|
|
|
c.Validate(t, receivedPod, err)
|
|
}
|