mirror of https://github.com/status-im/consul.git
[NET-6899] Create name-aligned Service when reconciling MeshGateway resource (#19900)
* NET-6899 Create name-aligned Service when reconciling MeshGateway resource The Service has an owner reference added to it indicating that it belongs to a MeshGateway * Specify port list when creating Service * Use constants, add TODO w/ ticket reference * Include gateway-kind in metadata of Service resource
This commit is contained in:
parent
d0bc091a60
commit
874e68f1eb
|
@ -5,14 +5,22 @@ package meshgateways
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"google.golang.org/protobuf/types/known/anypb"
|
||||
|
||||
"github.com/hashicorp/consul/internal/controller"
|
||||
"github.com/hashicorp/consul/internal/resource"
|
||||
pbcatalog "github.com/hashicorp/consul/proto-public/pbcatalog/v2beta1"
|
||||
pbmesh "github.com/hashicorp/consul/proto-public/pbmesh/v2beta1"
|
||||
"github.com/hashicorp/consul/proto-public/pbresource"
|
||||
)
|
||||
|
||||
const (
|
||||
ControllerName = "consul.io/mesh-gateway"
|
||||
|
||||
meshPortName = "mesh"
|
||||
wanPort = 8443
|
||||
wanPortName = "wan"
|
||||
)
|
||||
|
||||
func Controller() *controller.Controller {
|
||||
|
@ -24,7 +32,48 @@ func Controller() *controller.Controller {
|
|||
|
||||
type reconciler struct{}
|
||||
|
||||
// Reconcile is responsible for creating a Service w/ a MeshGateway owner,
|
||||
// in addition to other things discussed in the RFC.
|
||||
func (r *reconciler) Reconcile(ctx context.Context, rt controller.Runtime, req controller.Request) error {
|
||||
rt.Logger = rt.Logger.With("resource-id", req.ID)
|
||||
rt.Logger.Trace("reconciling mesh gateway")
|
||||
|
||||
// TODO NET-6822 The ports and workload selector below are currently hardcoded
|
||||
// until they are added to the MeshGateway resource and pulled from there.
|
||||
service := &pbcatalog.Service{
|
||||
Workloads: &pbcatalog.WorkloadSelector{
|
||||
Prefixes: []string{req.ID.Name},
|
||||
},
|
||||
Ports: []*pbcatalog.ServicePort{
|
||||
{
|
||||
Protocol: pbcatalog.Protocol_PROTOCOL_TCP,
|
||||
TargetPort: wanPortName,
|
||||
VirtualPort: wanPort,
|
||||
},
|
||||
{
|
||||
Protocol: pbcatalog.Protocol_PROTOCOL_MESH,
|
||||
TargetPort: meshPortName,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
serviceData, err := anypb.New(service)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = rt.Client.Write(ctx, &pbresource.WriteRequest{
|
||||
Resource: &pbresource.Resource{
|
||||
Data: serviceData,
|
||||
Id: resource.ReplaceType(pbcatalog.ServiceType, req.ID),
|
||||
Metadata: map[string]string{"gateway-kind": "mesh-gateway"},
|
||||
Owner: req.ID,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO NET-6426, NET-6427, NET-6428, NET-6429, NET-6430, NET-6431, NET-6432
|
||||
return errors.New("not implemented")
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue