Skip to content

Commit

Permalink
Adapt to new service entry port (istio#42758)
Browse files Browse the repository at this point in the history
* Make use of new ServicePort

* update

* Import new api

* update crd

* Run `make gen`

Co-authored-by: Eric Van Norman <ericvn@us.ibm.com>
  • Loading branch information
hzxuzhonghu and Eric Van Norman authored Jan 17, 2023
1 parent 59b48ab commit 4d98919
Show file tree
Hide file tree
Showing 17 changed files with 102 additions and 103 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ require (
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
helm.sh/helm/v3 v3.10.3
istio.io/api v0.0.0-20230111221020-454de919bf29
istio.io/client-go v1.12.0-alpha.5.0.20230111221916-e63d8bceb4b4
istio.io/api v0.0.0-20230117160634-336f5919b446
istio.io/client-go v1.12.0-alpha.5.0.20230117161130-333be2df8e1a
istio.io/pkg v0.0.0-20230109165950-4d649447a1d7
k8s.io/api v0.26.0
k8s.io/apiextensions-apiserver v0.26.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1402,10 +1402,10 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
istio.io/api v0.0.0-20230111221020-454de919bf29 h1:Ms07MWO1zEZrwOoDG0G10xsyeI3DQYKrclCO45DXrIo=
istio.io/api v0.0.0-20230111221020-454de919bf29/go.mod h1:owGDRg9uqMob8CN1gxaOzk6nJxnbT8wrP7PmggpJHHY=
istio.io/client-go v1.12.0-alpha.5.0.20230111221916-e63d8bceb4b4 h1:hC6UCv3e0LKqkVVN3mXGiSH96I7jPfNh4eO+dxffPzY=
istio.io/client-go v1.12.0-alpha.5.0.20230111221916-e63d8bceb4b4/go.mod h1:dK/spOcGGZwTnz7X5O9rmODFr3dsGAtGN53tU+ZEjO0=
istio.io/api v0.0.0-20230117160634-336f5919b446 h1:C9N4MvkQvCZyJ8wbQhlOL2r+ljoXQfjFmLKm9OC51oU=
istio.io/api v0.0.0-20230117160634-336f5919b446/go.mod h1:owGDRg9uqMob8CN1gxaOzk6nJxnbT8wrP7PmggpJHHY=
istio.io/client-go v1.12.0-alpha.5.0.20230117161130-333be2df8e1a h1:WEA0Q21J/bk2pV3QveUoZ9w7QU2YNJAgpWW8ObaQqGc=
istio.io/client-go v1.12.0-alpha.5.0.20230117161130-333be2df8e1a/go.mod h1:aJflaNvPfWsMbqB56mFwksu4usHscq2wyHB4I67ytQo=
istio.io/pkg v0.0.0-20230109165950-4d649447a1d7 h1:Be5w+PI4gUtDDFGLNwX3z5ZzFFovA9Nz5XK1S/KBjMk=
istio.io/pkg v0.0.0-20230109165950-4d649447a1d7/go.mod h1:BrWkMDfL8n60pWeRnHoNBckpgBOzMFasZsGUGCP9grE=
k8s.io/api v0.18.2/go.mod h1:SJCWI7OLzhZSvbY7U8zwNl9UA4o1fizoug34OV/2r78=
Expand Down
4 changes: 2 additions & 2 deletions istioctl/cmd/add-to-mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,9 @@ func generateServiceEntry(u *unstructured.Unstructured, o *vmServiceOpts) error
if o == nil {
return fmt.Errorf("empty vm service options")
}
ports := make([]*v1alpha3.Port, 0, len(o.PortList))
ports := make([]*v1alpha3.ServicePort, 0, len(o.PortList))
for _, p := range o.PortList {
ports = append(ports, &v1alpha3.Port{
ports = append(ports, &v1alpha3.ServicePort{
Number: uint32(p.Port),
Protocol: string(p.Protocol),
Name: p.Name,
Expand Down
7 changes: 3 additions & 4 deletions pilot/pkg/networking/core/v1alpha3/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1425,10 +1425,9 @@ func TestCreateGatewayHTTPFilterChainOpts(t *testing.T) {
server: &networking.Server{
Name: "server1",
Port: &networking.Port{
Name: "https-app",
Number: 443,
TargetPort: 8443,
Protocol: "HTTPS",
Name: "https-app",
Number: 443,
Protocol: "HTTPS",
},
Hosts: []string{"example.org"},
Tls: &networking.ServerTLSSettings{
Expand Down
6 changes: 3 additions & 3 deletions pilot/pkg/serviceregistry/serviceentry/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ func TestServicesDiff(t *testing.T) {
},
Spec: &networking.ServiceEntry{
Hosts: []string{"*.google.com", "*.mail.com"},
Ports: []*networking.Port{
Ports: []*networking.ServicePort{
{Number: 80, Name: "http-port", Protocol: "http"},
{Number: 8080, Name: "http-alt-port", Protocol: "http"},
},
Expand Down Expand Up @@ -1412,9 +1412,9 @@ func TestServicesDiff(t *testing.T) {
updatedHTTPDNSPort := func() *config.Config {
c := updatedHTTPDNS.DeepCopy()
se := c.Spec.(*networking.ServiceEntry)
var ports []*networking.Port
var ports []*networking.ServicePort
ports = append(ports, se.Ports...)
ports = append(ports, &networking.Port{Number: 9090, Name: "http-new-port", Protocol: "http"})
ports = append(ports, &networking.ServicePort{Number: 9090, Name: "http-new-port", Protocol: "http"})
se.Ports = ports
return &c
}()
Expand Down
6 changes: 3 additions & 3 deletions pilot/pkg/serviceregistry/serviceentry/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
netutil "istio.io/istio/pkg/util/net"
)

func convertPort(port *networking.Port) *model.Port {
func convertPort(port *networking.ServicePort) *model.Port {
return &model.Port{
Name: port.Name,
Port: int(port.Number),
Expand Down Expand Up @@ -113,7 +113,7 @@ func ServiceToServiceEntry(svc *model.Service, proxy *model.Proxy) *config.Confi

// Port is mapped from ServicePort
for _, p := range svc.Ports {
se.Ports = append(se.Ports, &networking.Port{
se.Ports = append(se.Ports, &networking.ServicePort{
Number: uint32(p.Port),
Name: p.Name,
// Protocol is converted to protocol.Instance - reverse conversion will use the name.
Expand Down Expand Up @@ -250,7 +250,7 @@ func ensureCanonicalServiceLabels(name string, srcLabels map[string]string) map[
return srcLabels
}

func (s *Controller) convertEndpoint(service *model.Service, servicePort *networking.Port,
func (s *Controller) convertEndpoint(service *model.Service, servicePort *networking.ServicePort,
wle *networking.WorkloadEntry, configKey *configKey, clusterID cluster.ID,
) *model.ServiceInstance {
var instancePort uint32
Expand Down
44 changes: 22 additions & 22 deletions pilot/pkg/serviceregistry/serviceentry/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var (
},
Spec: &networking.ServiceEntry{
Hosts: []string{"*.google.com"},
Ports: []*networking.Port{
Ports: []*networking.ServicePort{
{Number: 80, Name: "http-number", Protocol: "http"},
{Number: 8080, Name: "http2-number", Protocol: "http2"},
},
Expand All @@ -71,7 +71,7 @@ var tcpNone = &config.Config{
Spec: &networking.ServiceEntry{
Hosts: []string{"tcpnone.com"},
Addresses: []string{"172.217.0.0/16"},
Ports: []*networking.Port{
Ports: []*networking.ServicePort{
{Number: 444, Name: "tcp-444", Protocol: "tcp"},
},
Location: networking.ServiceEntry_MESH_EXTERNAL,
Expand All @@ -88,7 +88,7 @@ var httpStatic = &config.Config{
},
Spec: &networking.ServiceEntry{
Hosts: []string{"*.google.com"},
Ports: []*networking.Port{
Ports: []*networking.ServicePort{
{Number: 80, Name: "http-port", Protocol: "http"},
{Number: 8080, Name: "http-alt-port", Protocol: "http"},
},
Expand Down Expand Up @@ -124,7 +124,7 @@ var httpStaticOverlay = &config.Config{
},
Spec: &networking.ServiceEntry{
Hosts: []string{"*.google.com"},
Ports: []*networking.Port{
Ports: []*networking.ServicePort{
{Number: 4567, Name: "http-port", Protocol: "http"},
},
Endpoints: []*networking.WorkloadEntry{
Expand All @@ -147,7 +147,7 @@ var httpDNSnoEndpoints = &config.Config{
},
Spec: &networking.ServiceEntry{
Hosts: []string{"google.com", "www.wikipedia.org"},
Ports: []*networking.Port{
Ports: []*networking.ServicePort{
{Number: 80, Name: "http-port", Protocol: "http"},
{Number: 8080, Name: "http-alt-port", Protocol: "http"},
},
Expand All @@ -166,7 +166,7 @@ var httpDNSRRnoEndpoints = &config.Config{
},
Spec: &networking.ServiceEntry{
Hosts: []string{"api.istio.io"},
Ports: []*networking.Port{
Ports: []*networking.ServicePort{
{Number: 80, Name: "http-port", Protocol: "http"},
{Number: 8080, Name: "http-alt-port", Protocol: "http"},
},
Expand All @@ -185,7 +185,7 @@ var dnsTargetPort = &config.Config{
},
Spec: &networking.ServiceEntry{
Hosts: []string{"google.com"},
Ports: []*networking.Port{
Ports: []*networking.ServicePort{
{Number: 80, Name: "http-port", Protocol: "http", TargetPort: 8080},
},
Location: networking.ServiceEntry_MESH_EXTERNAL,
Expand All @@ -202,7 +202,7 @@ var httpDNS = &config.Config{
},
Spec: &networking.ServiceEntry{
Hosts: []string{"*.google.com"},
Ports: []*networking.Port{
Ports: []*networking.ServicePort{
{Number: 80, Name: "http-port", Protocol: "http"},
{Number: 8080, Name: "http-alt-port", Protocol: "http"},
},
Expand Down Expand Up @@ -236,7 +236,7 @@ var httpDNSRR = &config.Config{
},
Spec: &networking.ServiceEntry{
Hosts: []string{"*.istio.io"},
Ports: []*networking.Port{
Ports: []*networking.ServicePort{
{Number: 80, Name: "http-port", Protocol: "http"},
{Number: 8080, Name: "http-alt-port", Protocol: "http"},
},
Expand All @@ -261,7 +261,7 @@ var tcpDNS = &config.Config{
},
Spec: &networking.ServiceEntry{
Hosts: []string{"tcpdns.com"},
Ports: []*networking.Port{
Ports: []*networking.ServicePort{
{Number: 444, Name: "tcp-444", Protocol: "tcp"},
},
Endpoints: []*networking.WorkloadEntry{
Expand Down Expand Up @@ -289,7 +289,7 @@ var tcpStatic = &config.Config{
Spec: &networking.ServiceEntry{
Hosts: []string{"tcpstatic.com"},
Addresses: []string{"172.217.0.1"},
Ports: []*networking.Port{
Ports: []*networking.ServicePort{
{Number: 444, Name: "tcp-444", Protocol: "tcp"},
},
Endpoints: []*networking.WorkloadEntry{
Expand All @@ -316,7 +316,7 @@ var httpNoneInternal = &config.Config{
},
Spec: &networking.ServiceEntry{
Hosts: []string{"*.google.com"},
Ports: []*networking.Port{
Ports: []*networking.ServicePort{
{Number: 80, Name: "http-number", Protocol: "http"},
{Number: 8080, Name: "http2-number", Protocol: "http2"},
},
Expand All @@ -335,7 +335,7 @@ var tcpNoneInternal = &config.Config{
Spec: &networking.ServiceEntry{
Hosts: []string{"tcpinternal.com"},
Addresses: []string{"172.217.0.0/16"},
Ports: []*networking.Port{
Ports: []*networking.ServicePort{
{Number: 444, Name: "tcp-444", Protocol: "tcp"},
},
Location: networking.ServiceEntry_MESH_INTERNAL,
Expand All @@ -353,7 +353,7 @@ var multiAddrInternal = &config.Config{
Spec: &networking.ServiceEntry{
Hosts: []string{"tcp1.com", "tcp2.com"},
Addresses: []string{"1.1.1.0/16", "2.2.2.0/16"},
Ports: []*networking.Port{
Ports: []*networking.ServicePort{
{Number: 444, Name: "tcp-444", Protocol: "tcp"},
},
Location: networking.ServiceEntry_MESH_INTERNAL,
Expand All @@ -371,7 +371,7 @@ var udsLocal = &config.Config{
},
Spec: &networking.ServiceEntry{
Hosts: []string{"uds.cluster.local"},
Ports: []*networking.Port{
Ports: []*networking.ServicePort{
{Number: 6553, Name: "grpc-1", Protocol: "grpc"},
},
Endpoints: []*networking.WorkloadEntry{
Expand All @@ -391,7 +391,7 @@ var selectorDNS = &config.Config{
},
Spec: &networking.ServiceEntry{
Hosts: []string{"selector.com"},
Ports: []*networking.Port{
Ports: []*networking.ServicePort{
{Number: 444, Name: "tcp-444", Protocol: "tcp"},
{Number: 445, Name: "http-445", Protocol: "http"},
},
Expand All @@ -412,7 +412,7 @@ var selector = &config.Config{
},
Spec: &networking.ServiceEntry{
Hosts: []string{"selector.com"},
Ports: []*networking.Port{
Ports: []*networking.ServicePort{
{Number: 444, Name: "tcp-444", Protocol: "tcp"},
{Number: 445, Name: "http-445", Protocol: "http"},
},
Expand All @@ -434,7 +434,7 @@ var dnsSelector = &config.Config{
},
Spec: &networking.ServiceEntry{
Hosts: []string{"dns.selector.com"},
Ports: []*networking.Port{
Ports: []*networking.ServicePort{
{Number: 444, Name: "tcp-444", Protocol: "tcp"},
{Number: 445, Name: "http-445", Protocol: "http"},
},
Expand All @@ -456,7 +456,7 @@ var dnsRoundRobinLBSE1 = &config.Config{
},
Spec: &networking.ServiceEntry{
Hosts: []string{"example.com"},
Ports: []*networking.Port{
Ports: []*networking.ServicePort{
{Number: 445, Name: "http-445", Protocol: "http"},
{Number: 446, Name: "http-446", Protocol: "http"},
},
Expand All @@ -474,7 +474,7 @@ var dnsRoundRobinLBSE2 = &config.Config{
},
Spec: &networking.ServiceEntry{
Hosts: []string{"example.com"},
Ports: []*networking.Port{
Ports: []*networking.ServicePort{
{Number: 445, Name: "http-445", Protocol: "http"},
},
Resolution: networking.ServiceEntry_DNS_ROUND_ROBIN,
Expand Down Expand Up @@ -554,7 +554,7 @@ const (

// nolint: unparam
func makeInstanceWithServiceAccount(cfg *config.Config, address string, port int,
svcPort *networking.Port, svcLabels map[string]string, serviceAccount string,
svcPort *networking.ServicePort, svcLabels map[string]string, serviceAccount string,
) *model.ServiceInstance {
i := makeInstance(cfg, address, port, svcPort, svcLabels, MTLSUnlabelled)
i.Endpoint.ServiceAccount = spiffe.MustGenSpiffeURI(i.Service.Attributes.Namespace, serviceAccount)
Expand All @@ -563,7 +563,7 @@ func makeInstanceWithServiceAccount(cfg *config.Config, address string, port int

// nolint: unparam
func makeInstance(cfg *config.Config, address string, port int,
svcPort *networking.Port, svcLabels map[string]string, mtlsMode MTLSMode,
svcPort *networking.ServicePort, svcLabels map[string]string, mtlsMode MTLSMode,
) *model.ServiceInstance {
services := convertServices(*cfg)
svc := services[0] // default
Expand Down
6 changes: 3 additions & 3 deletions pilot/pkg/serviceregistry/serviceentry/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestGetWorkloadServiceEntries(t *testing.T) {
Meta: config.Meta{GroupVersionKind: gvk.ServiceEntry, Namespace: "default", Name: "se-1"},
Spec: &networking.ServiceEntry{
Hosts: []string{"*.google.com"},
Ports: []*networking.Port{
Ports: []*networking.ServicePort{
{Number: 80, Name: "http-number", Protocol: "http"},
{Number: 8080, Name: "http2-number", Protocol: "http2"},
},
Expand All @@ -43,7 +43,7 @@ func TestGetWorkloadServiceEntries(t *testing.T) {
Meta: config.Meta{GroupVersionKind: gvk.ServiceEntry, Namespace: "default", Name: "se-2"},
Spec: &networking.ServiceEntry{
Hosts: []string{"*.google.com"},
Ports: []*networking.Port{
Ports: []*networking.ServicePort{
{Number: 80, Name: "http-number", Protocol: "http"},
{Number: 8080, Name: "http2-number", Protocol: "http2"},
},
Expand All @@ -57,7 +57,7 @@ func TestGetWorkloadServiceEntries(t *testing.T) {
Meta: config.Meta{GroupVersionKind: gvk.ServiceEntry, Namespace: "default", Name: "se-3"},
Spec: &networking.ServiceEntry{
Hosts: []string{"www.wikipedia.org"},
Ports: []*networking.Port{
Ports: []*networking.ServicePort{
{Number: 80, Name: "http-number", Protocol: "http"},
{Number: 8080, Name: "http2-number", Protocol: "http2"},
},
Expand Down
14 changes: 7 additions & 7 deletions pilot/pkg/serviceregistry/serviceregistry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func setupTest(t *testing.T) (
// external service registry, which have cross-references by workload instances.
func TestWorkloadInstances(t *testing.T) {
istiotest.SetForTest(t, &features.WorkloadEntryHealthChecks, true)
port := &networking.Port{
port := &networking.ServicePort{
Name: "http",
Number: 80,
Protocol: "http",
Expand All @@ -118,7 +118,7 @@ func TestWorkloadInstances(t *testing.T) {
},
Spec: &networking.ServiceEntry{
Hosts: []string{"service.namespace.svc.cluster.local"},
Ports: []*networking.Port{port},
Ports: []*networking.ServicePort{port},
WorkloadSelector: &networking.WorkloadSelector{
Labels: labels,
},
Expand Down Expand Up @@ -344,7 +344,7 @@ func TestWorkloadInstances(t *testing.T) {
},
Spec: &networking.ServiceEntry{
Hosts: []string{"service.namespace.svc.cluster.local"},
Ports: []*networking.Port{{
Ports: []*networking.ServicePort{{
Name: "http",
Number: 80,
Protocol: "http",
Expand Down Expand Up @@ -377,7 +377,7 @@ func TestWorkloadInstances(t *testing.T) {
},
Spec: &networking.ServiceEntry{
Hosts: []string{"service.namespace.svc.cluster.local"},
Ports: []*networking.Port{{
Ports: []*networking.ServicePort{{
Name: "http",
Number: 80,
Protocol: "http",
Expand Down Expand Up @@ -739,7 +739,7 @@ func TestWorkloadInstances(t *testing.T) {
},
Spec: &networking.ServiceEntry{
Hosts: []string{"service.namespace.svc.cluster.local"},
Ports: []*networking.Port{{
Ports: []*networking.ServicePort{{
Name: "http",
Number: 80,
Protocol: "http",
Expand Down Expand Up @@ -869,7 +869,7 @@ func TestWorkloadInstances(t *testing.T) {
expectEndpoints(t, s, "outbound|80||service.namespace.svc.cluster.local", []string{"1.2.3.4:80"})

newSE := serviceEntry.DeepCopy()
newSE.Spec.(*networking.ServiceEntry).Ports = []*networking.Port{{
newSE.Spec.(*networking.ServiceEntry).Ports = []*networking.ServicePort{{
Name: "http",
Number: 80,
Protocol: "http",
Expand All @@ -879,7 +879,7 @@ func TestWorkloadInstances(t *testing.T) {
expectEndpoints(t, s, "outbound|80||service.namespace.svc.cluster.local", []string{"1.2.3.4:8080"})

newSE = newSE.DeepCopy()
newSE.Spec.(*networking.ServiceEntry).Ports = []*networking.Port{{
newSE.Spec.(*networking.ServiceEntry).Ports = []*networking.ServicePort{{
Name: "http",
Number: 9090,
Protocol: "http",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var selector = &config.Config{
},
Spec: &networking.ServiceEntry{
Hosts: []string{"selector.com"},
Ports: []*networking.Port{
Ports: []*networking.ServicePort{
{Number: 444, Name: "tcp-444", Protocol: "tcp"},
{Number: 445, Name: "http-445", Protocol: "http"},
},
Expand Down
Loading

0 comments on commit 4d98919

Please sign in to comment.