Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ClusterIP to the services in the egctl test data #1758

Merged
merged 4 commits into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ metadata:
app: backend
service: backend
spec:
clusterIP: 7.7.7.7
ports:
- name: http
port: 3000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ metadata:
app: backend
service: backend
spec:
clusterIP: 7.7.7.7
ports:
- name: http
port: 3000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ metadata:
app: backend
service: backend
spec:
clusterIP: 7.7.7.7
ports:
- name: http
port: 3000
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/egctl/testdata/translate/in/quickstart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ metadata:
app: backend
service: backend
spec:
clusterIP: 7.7.7.7
ports:
- name: http
port: 3000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ metadata:
app: backend
service: backend
spec:
clusterIP: 7.7.7.7
ports:
- name: http
port: 3000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
"endpoint": {
"address": {
"socketAddress": {
"address": "7.7.7.7",
"portValue": 3000
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ xds:
- endpoint:
address:
socketAddress:
address: 7.7.7.7
portValue: 3000
loadBalancingWeight: 1
loadBalancingWeight: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ xds:
- endpoint:
address:
socketAddress:
address: "7.7.7.7"
portValue: 3000
loadBalancingWeight: 1
loadBalancingWeight: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
"endpoint": {
"address": {
"socketAddress": {
"address": "7.7.7.7",
"portValue": 3000
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ xds:
- endpoint:
address:
socketAddress:
address: 7.7.7.7
portValue: 3000
loadBalancingWeight: 1
loadBalancingWeight: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ xds:
- endpoint:
address:
socketAddress:
address: 7.7.7.7
portValue: 3000
loadBalancingWeight: 1
loadBalancingWeight: 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
tcp:
- name: "tcp-route-simple"
address: "0.0.0.0"
port: 10080
destinations:
- port: 50000
- host: "5.6.7.8"
port: 50001
3 changes: 3 additions & 0 deletions internal/xds/translator/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ func TestTranslateXdsNegative(t *testing.T) {
{
name: "tcp-route-invalid",
},
{
name: "tcp-route-invalid-endpoint",
},
{
name: "udp-route-invalid",
},
Expand Down
10 changes: 8 additions & 2 deletions internal/xds/types/resourceversiontable.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"

clusterv3 "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
endpointv3 "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3"
listenerv3 "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
routev3 "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
tlsv3 "github.com/envoyproxy/go-control-plane/envoy/extensions/transport_sockets/tls/v3"
Expand Down Expand Up @@ -107,8 +108,13 @@ func (t *ResourceVersionTable) AddXdsResource(rType resourcev3.Type, xdsResource
}

case resourcev3.EndpointType:
// TBD - ValidateAll() breaks existing test internal/cmd/egctl/translate_test
// authn-single-route-single-match-to-xds.endpoint expects address for socketAddress field, but this field currently only has port, does not have address
if resourceOfType, ok := xdsResource.(*endpointv3.ClusterLoadAssignment); ok {
if err := resourceOfType.ValidateAll(); err != nil {
return fmt.Errorf("validation failed for xds resource %+v, err:%v", xdsResource, err)
}
} else {
return fmt.Errorf("failed to cast xds resource %+v to ClusterLoadAssignment type", xdsResource)
}

case resourcev3.ClusterType:
// Handle specific operations
Expand Down
180 changes: 177 additions & 3 deletions internal/xds/types/resourceversiontable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,58 @@ func TestAddOrReplaceXdsResource(t *testing.T) {
},
},
}
testEndpoint := &endpointv3.ClusterLoadAssignment{
ClusterName: "test-cluster",
Endpoints: []*endpointv3.LocalityLbEndpoints{
{
LbEndpoints: []*endpointv3.LbEndpoint{
{
HostIdentifier: &endpointv3.LbEndpoint_Endpoint{
Endpoint: &endpointv3.Endpoint{
Address: &corev3.Address{
Address: &corev3.Address_SocketAddress{
SocketAddress: &corev3.SocketAddress{
Address: "exampleservice.examplenamespace.svc.cluster.local",
PortSpecifier: &corev3.SocketAddress_PortValue{
PortValue: 5000,
},
Protocol: corev3.SocketAddress_TCP,
},
},
},
},
},
},
},
},
},
}
updatedEndpoint := &endpointv3.ClusterLoadAssignment{
ClusterName: "test-cluster",
Endpoints: []*endpointv3.LocalityLbEndpoints{
{
LbEndpoints: []*endpointv3.LbEndpoint{
{
HostIdentifier: &endpointv3.LbEndpoint_Endpoint{
Endpoint: &endpointv3.Endpoint{
Address: &corev3.Address{
Address: &corev3.Address_SocketAddress{
SocketAddress: &corev3.SocketAddress{
Address: "modified.example.svc.cluster.local",
PortSpecifier: &corev3.SocketAddress_PortValue{
PortValue: 5000,
},
Protocol: corev3.SocketAddress_TCP,
},
},
},
},
},
},
},
},
},
}
testRouteConfig := &routev3.RouteConfiguration{
Name: "test-route-config",
VirtualHosts: []*routev3.VirtualHost{
Expand Down Expand Up @@ -274,6 +326,58 @@ func TestAddOrReplaceXdsResource(t *testing.T) {
},
},
},
{
name: "inject-new-endpoint",
tableIn: &ResourceVersionTable{
XdsResources: XdsResources{
resourcev3.EndpointType: []types.Resource{},
},
},
typeIn: resourcev3.EndpointType,
resourceIn: testEndpoint,
funcIn: func(existing types.Resource, new types.Resource) bool {
oldEndpoint := existing.(*endpointv3.ClusterLoadAssignment)
newEndpoint := new.(*endpointv3.ClusterLoadAssignment)
if newEndpoint == nil || oldEndpoint == nil {
return false
}
if oldEndpoint.ClusterName == newEndpoint.ClusterName {
return true
}
return false
},
tableOut: &ResourceVersionTable{
XdsResources: XdsResources{
resourcev3.EndpointType: []types.Resource{testEndpoint},
},
},
},
{
name: "replace-endpoint",
tableIn: &ResourceVersionTable{
XdsResources: XdsResources{
resourcev3.EndpointType: []types.Resource{testEndpoint},
},
},
typeIn: resourcev3.EndpointType,
resourceIn: updatedEndpoint,
funcIn: func(existing types.Resource, new types.Resource) bool {
oldEndpoint := existing.(*endpointv3.ClusterLoadAssignment)
newEndpoint := new.(*endpointv3.ClusterLoadAssignment)
if newEndpoint == nil || oldEndpoint == nil {
return false
}
if oldEndpoint.ClusterName == newEndpoint.ClusterName {
return true
}
return false
},
tableOut: &ResourceVersionTable{
XdsResources: XdsResources{
resourcev3.EndpointType: []types.Resource{updatedEndpoint},
},
},
},
{
name: "inject-new-listener",
tableIn: &ResourceVersionTable{
Expand Down Expand Up @@ -507,6 +611,32 @@ func TestInvalidAddXdsResource(t *testing.T) {
},
},
}
invalidEndpoint := &endpointv3.ClusterLoadAssignment{
ClusterName: "test-cluster",
Endpoints: []*endpointv3.LocalityLbEndpoints{
{
LbEndpoints: []*endpointv3.LbEndpoint{
{
HostIdentifier: &endpointv3.LbEndpoint_Endpoint{
Endpoint: &endpointv3.Endpoint{
Address: &corev3.Address{
Address: &corev3.Address_SocketAddress{
SocketAddress: &corev3.SocketAddress{
Address: "",
PortSpecifier: &corev3.SocketAddress_PortValue{
PortValue: 5000,
},
Protocol: corev3.SocketAddress_TCP,
},
},
},
},
},
},
},
},
},
}

invalidSecret := &tlsv3.Secret{
Name: "=*&",
Expand All @@ -532,7 +662,7 @@ func TestInvalidAddXdsResource(t *testing.T) {
tableOut *ResourceVersionTable
}{
{
name: "inject-new-listener",
name: "inject-invalid-listener",
tableIn: &ResourceVersionTable{
XdsResources: XdsResources{
resourcev3.ListenerType: []types.Resource{},
Expand All @@ -558,7 +688,7 @@ func TestInvalidAddXdsResource(t *testing.T) {
},
},
{
name: "inject-new-route-config",
name: "inject-invalid-route-config",
tableIn: &ResourceVersionTable{
XdsResources: XdsResources{
resourcev3.RouteType: []types.Resource{},
Expand All @@ -580,7 +710,7 @@ func TestInvalidAddXdsResource(t *testing.T) {
tableOut: nil,
},
{
name: "inject-new-cluster",
name: "inject-invalid-cluster",
tableIn: &ResourceVersionTable{
XdsResources: XdsResources{
resourcev3.ClusterType: []types.Resource{},
Expand Down Expand Up @@ -711,6 +841,50 @@ func TestInvalidAddXdsResource(t *testing.T) {
},
tableOut: nil,
},
{
name: "inject-invalid-endpoint",
tableIn: &ResourceVersionTable{
XdsResources: XdsResources{
resourcev3.EndpointType: []types.Resource{},
},
},
typeIn: resourcev3.EndpointType,
resourceIn: invalidEndpoint,
funcIn: func(existing types.Resource, new types.Resource) bool {
oldEndpoint := existing.(*endpointv3.ClusterLoadAssignment)
newEndpoint := new.(*endpointv3.ClusterLoadAssignment)
if newEndpoint == nil || oldEndpoint == nil {
return false
}
if oldEndpoint.ClusterName == newEndpoint.ClusterName {
return true
}
return false
},
tableOut: nil,
},
{
name: "cast-endpoint-type",
tableIn: &ResourceVersionTable{
XdsResources: XdsResources{
resourcev3.EndpointType: []types.Resource{},
},
},
typeIn: resourcev3.EndpointType,
resourceIn: invalidListener,
funcIn: func(existing types.Resource, new types.Resource) bool {
oldEndpoint := existing.(*endpointv3.ClusterLoadAssignment)
newEndpoint := new.(*endpointv3.ClusterLoadAssignment)
if newEndpoint == nil || oldEndpoint == nil {
return false
}
if oldEndpoint.ClusterName == newEndpoint.ClusterName {
return true
}
return false
},
tableOut: nil,
},
}
for _, tc := range testCases {
tc := tc
Expand Down