forked from istio/istio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Determine ServiceInstances from Proxy labels (istio#16483)
- Loading branch information
1 parent
73d3f87
commit 2e789b9
Showing
74 changed files
with
728 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ import ( | |
"testing" | ||
"time" | ||
|
||
"github.com/envoyproxy/go-control-plane/envoy/api/v2/core" | ||
coreV1 "k8s.io/api/core/v1" | ||
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/util/intstr" | ||
|
@@ -496,6 +497,42 @@ func TestGetProxyServiceInstances(t *testing.T) { | |
t.Errorf("GetProxyServiceInstances() wrong service instance returned => hostname %q, want %q", | ||
services[0].Service.Hostname, hostname) | ||
} | ||
|
||
// Test that we can look up instances just by Proxy metadata | ||
metaServices, err := controller.GetProxyServiceInstances(&model.Proxy{ | ||
Type: "sidecar", | ||
IPAddresses: []string{"1.1.1.1"}, | ||
Locality: &core.Locality{Region: "r", Zone: "z"}, | ||
ConfigNamespace: "nsa", | ||
Metadata: map[string]string{model.NodeMetadataServiceAccount: "account"}, | ||
WorkloadLabels: labels.Collection{labels.Instance{"app": "prod-app"}}, | ||
}) | ||
if err != nil { | ||
t.Fatalf("got err getting service instances") | ||
} | ||
|
||
expected := &model.ServiceInstance{ | ||
Endpoint: model.NetworkEndpoint{Family: 0, | ||
Address: "1.1.1.1", | ||
ServicePort: &model.Port{Name: "tcp-port", Port: 8080, Protocol: protocol.TCP}, | ||
Locality: "r/z", | ||
}, | ||
Service: &model.Service{ | ||
Hostname: "svc1.nsa.svc.company.com", | ||
Address: "10.0.0.1", | ||
Ports: []*model.Port{{Name: "tcp-port", Port: 8080, Protocol: protocol.TCP}}, | ||
ServiceAccounts: []string{"[email protected]", "spiffe://cluster.local/ns/nsa/sa/acct4"}, | ||
Attributes: model.ServiceAttributes{Name: "svc1", Namespace: "nsa", UID: "istio://nsa/services/svc1"}, | ||
}, | ||
Labels: labels.Instance{"app": "prod-app"}, | ||
ServiceAccount: "account", | ||
} | ||
if len(metaServices) != 1 { | ||
t.Fatalf("expected 1 instance, got %v", len(metaServices)) | ||
} | ||
if !reflect.DeepEqual(expected, metaServices[0]) { | ||
t.Fatalf("expected instance %v, got %v", expected, metaServices[0]) | ||
} | ||
} | ||
|
||
func TestGetProxyServiceInstancesWithMultiIPs(t *testing.T) { | ||
|
Oops, something went wrong.