Skip to content

Commit

Permalink
feat(MeshService): add port names (#10287)
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Beaumont <mjboamail@gmail.com>
  • Loading branch information
michaelbeaumont authored May 21, 2024
1 parent ad2c42d commit 612e625
Show file tree
Hide file tree
Showing 19 changed files with 243 additions and 193 deletions.
340 changes: 175 additions & 165 deletions api/mesh/v1alpha1/dataplane.pb.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions api/mesh/v1alpha1/dataplane.proto
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ message Dataplane {

// State describes the current state of the listener.
State state = 9;

// Name adds another way of referencing this port, usable with MeshService
string name = 10;
}

// Outbound describes a service consumed by the data plane proxy.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4606,8 +4606,10 @@ spec:
description: Protocol identifies a protocol supported by a service.
type: string
targetPort:
format: int32
type: integer
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
required:
- port
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4606,8 +4606,10 @@ spec:
description: Protocol identifies a protocol supported by a service.
type: string
targetPort:
format: int32
type: integer
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
required:
- port
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4626,8 +4626,10 @@ spec:
description: Protocol identifies a protocol supported by a service.
type: string
targetPort:
format: int32
type: integer
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
required:
- port
type: object
Expand Down
6 changes: 4 additions & 2 deletions app/kumactl/cmd/install/testdata/install-crds.all.golden.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6030,8 +6030,10 @@ spec:
description: Protocol identifies a protocol supported by a service.
type: string
targetPort:
format: int32
type: integer
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
required:
- port
type: object
Expand Down
6 changes: 4 additions & 2 deletions deployments/charts/kuma/crds/kuma.io_meshservices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ spec:
description: Protocol identifies a protocol supported by a service.
type: string
targetPort:
format: int32
type: integer
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
required:
- port
type: object
Expand Down
6 changes: 4 additions & 2 deletions docs/generated/raw/crds/kuma.io_meshservices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ spec:
description: Protocol identifies a protocol supported by a service.
type: string
targetPort:
format: int32
type: integer
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
required:
- port
type: object
Expand Down
4 changes: 4 additions & 0 deletions docs/generated/raw/protos/Dataplane.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@
}
],
"title": "State"
},
"name": {
"type": "string",
"description": "Name adds another way of referencing this port, usable with MeshService"
}
},
"additionalProperties": true,
Expand Down
4 changes: 4 additions & 0 deletions docs/generated/raw/protos/DataplaneOverview.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@
}
],
"title": "State"
},
"name": {
"type": "string",
"description": "Name adds another way of referencing this port, usable with MeshService"
}
},
"additionalProperties": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
package v1alpha1

import (
"k8s.io/apimachinery/pkg/util/intstr"

core_mesh "github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
)

Expand All @@ -12,8 +14,8 @@ type Selector struct {
}

type Port struct {
Port uint32 `json:"port"`
TargetPort uint32 `json:"targetPort,omitempty"`
Port uint32 `json:"port"`
TargetPort intstr.IntOrString `json:"targetPort,omitempty"`
// +kubebuilder:default=tcp
Protocol core_mesh.Protocol `json:"protocol,omitempty"`
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/core/resources/apis/meshservice/api/v1alpha1/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ properties:
description: Protocol identifies a protocol supported by a service.
type: string
targetPort:
format: int32
type: integer
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
required:
- port
type: object
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ spec:
description: Protocol identifies a protocol supported by a service.
type: string
targetPort:
format: int32
type: integer
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
required:
- port
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ var _ = Describe("MeshHTTPRoute", func() {
Selector: meshservice_api.Selector{},
Ports: []meshservice_api.Port{{
Port: 80,
TargetPort: 8084,
TargetPort: intstr.FromInt(8084),
Protocol: core_mesh.ProtocolHTTP,
}},
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/plugins/runtime/k8s/controllers/meshservice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/pkg/errors"
kube_core "k8s.io/api/core/v1"
kube_apierrs "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kube_runtime "k8s.io/apimachinery/pkg/runtime"
kube_types "k8s.io/apimachinery/pkg/types"
kube_ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -126,7 +126,7 @@ func (r *MeshServiceReconciler) Reconcile(ctx context.Context, req kube_ctrl.Req
}
ms.Spec.Ports = append(ms.Spec.Ports, meshservice_api.Port{
Port: uint32(port.Port),
TargetPort: uint32(port.TargetPort.IntVal), // todo(jakubdyszkiewicz): update after API changes
TargetPort: port.TargetPort,
Protocol: core_mesh.Protocol(pointer.DerefOr(port.AppProtocol, "tcp")),
})
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/test/store/store_test_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/util/intstr"

"github.com/kumahq/kuma/api/mesh/v1alpha1"
core_mesh "github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
Expand Down Expand Up @@ -125,7 +126,7 @@ func ExecuteStoreTests(
Ports: []meshservice_api.Port{
{
Port: 80,
TargetPort: 80,
TargetPort: intstr.FromInt(80),
Protocol: "http",
},
},
Expand Down Expand Up @@ -235,7 +236,7 @@ func ExecuteStoreTests(
Ports: []meshservice_api.Port{
{
Port: 80,
TargetPort: 80,
TargetPort: intstr.FromInt(80),
Protocol: "http",
},
},
Expand Down
12 changes: 10 additions & 2 deletions pkg/xds/topology/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strconv"

"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/util/intstr"

mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
"github.com/kumahq/kuma/api/system/v1alpha1"
Expand Down Expand Up @@ -162,8 +163,15 @@ func fillLocalMeshServices(
continue
}
for _, port := range meshSvc.Spec.Ports {
if port.TargetPort != inbound.Port {
continue
switch port.TargetPort.Type {
case intstr.Int:
if uint32(port.TargetPort.IntVal) != inbound.Port {
continue
}
case intstr.String:
if port.TargetPort.StrVal != inbound.Name {
continue
}
}

inboundTags := maps.Clone(inbound.GetTags())
Expand Down
7 changes: 4 additions & 3 deletions pkg/xds/topology/outbound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/util/intstr"

mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
"github.com/kumahq/kuma/pkg/core/datasource"
Expand Down Expand Up @@ -1192,12 +1193,12 @@ var _ = Describe("TrafficRoute", func() {
Ports: []v1alpha1.Port{
{
Port: 80,
TargetPort: 8080,
TargetPort: intstr.FromInt(8080),
Protocol: "http",
},
{
Port: 8081,
TargetPort: 8081,
TargetPort: intstr.FromInt(8081),
Protocol: "http",
},
},
Expand All @@ -1217,7 +1218,7 @@ var _ = Describe("TrafficRoute", func() {
Ports: []v1alpha1.Port{
{
Port: 6379,
TargetPort: 6379,
TargetPort: intstr.FromInt(6379),
},
},
},
Expand Down

0 comments on commit 612e625

Please sign in to comment.