Skip to content

Commit

Permalink
Made BackendEndpoint embedded in the ExtensionService structure.
Browse files Browse the repository at this point in the history
Signed-off-by: Lior Okman <[email protected]>
  • Loading branch information
liorokman authored and Alice-Lilith committed May 30, 2024
1 parent ef40cdd commit 90a4b99
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 25 deletions.
10 changes: 5 additions & 5 deletions api/v1alpha1/envoygateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,23 +482,23 @@ type XDSTranslatorHooks struct {

// ExtensionService defines the configuration for connecting to a registered extension service.
type ExtensionService struct {
// BackendEndpoint points to where the extension server can be found.
BackendEndpoint `json:",inline"`

// Host define the extension service hostname.
// Deprecated: use the backend attribute instead
// Deprecated: use the appropriate transport attribute instead (FQDN,IPv4,Unix)
//
// +optional
Host string `json:"host,omitempty"`

// Port defines the port the extension service is exposed on.
// Deprecated: use the backend attribute instead
// Deprecated: use the appropriate transport attribute instead (FQDN,IPv4,Unix)
//
// +optional
// +kubebuilder:validation:Minimum=0
// +kubebuilder:default=80
Port int32 `json:"port,omitempty"`

// Backend points to where the extension server can be found.
Backend BackendEndpoint `json:"backend"`

// TLS defines TLS configuration for communication between Envoy Gateway and
// the extension service.
//
Expand Down
8 changes: 4 additions & 4 deletions api/v1alpha1/validation/envoygateway_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ func ValidateEnvoyGateway(eg *v1alpha1.EnvoyGateway) error {
}

switch {
case eg.ExtensionManager.Service.Host == "" && eg.ExtensionManager.Service.Backend.FQDN == nil && eg.ExtensionManager.Service.Backend.Unix == nil && eg.ExtensionManager.Service.Backend.IPv4 == nil:
case eg.ExtensionManager.Service.Host == "" && eg.ExtensionManager.Service.FQDN == nil && eg.ExtensionManager.Service.Unix == nil && eg.ExtensionManager.Service.IPv4 == nil:
return fmt.Errorf("extension service must contain a configured target")

case eg.ExtensionManager.Service.Backend.FQDN != nil && (eg.ExtensionManager.Service.Backend.IPv4 != nil || eg.ExtensionManager.Service.Backend.Unix != nil || eg.ExtensionManager.Service.Host != ""),
eg.ExtensionManager.Service.Backend.IPv4 != nil && (eg.ExtensionManager.Service.Backend.FQDN != nil || eg.ExtensionManager.Service.Backend.Unix != nil || eg.ExtensionManager.Service.Host != ""),
eg.ExtensionManager.Service.Backend.Unix != nil && (eg.ExtensionManager.Service.Backend.IPv4 != nil || eg.ExtensionManager.Service.Backend.FQDN != nil || eg.ExtensionManager.Service.Host != ""):
case eg.ExtensionManager.Service.FQDN != nil && (eg.ExtensionManager.Service.IPv4 != nil || eg.ExtensionManager.Service.Unix != nil || eg.ExtensionManager.Service.Host != ""),
eg.ExtensionManager.Service.IPv4 != nil && (eg.ExtensionManager.Service.FQDN != nil || eg.ExtensionManager.Service.Unix != nil || eg.ExtensionManager.Service.Host != ""),
eg.ExtensionManager.Service.Unix != nil && (eg.ExtensionManager.Service.IPv4 != nil || eg.ExtensionManager.Service.FQDN != nil || eg.ExtensionManager.Service.Host != ""):

return fmt.Errorf("only one backend target can be configured for the extension manager")

Expand Down
6 changes: 3 additions & 3 deletions api/v1alpha1/validation/envoygateway_validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ func TestValidateEnvoyGateway(t *testing.T) {
},
},
Service: &v1alpha1.ExtensionService{
Backend: v1alpha1.BackendEndpoint{
BackendEndpoint: v1alpha1.BackendEndpoint{
FQDN: &v1alpha1.FQDNEndpoint{
Hostname: "foo.example.com",
Port: 8080,
Expand Down Expand Up @@ -614,7 +614,7 @@ func TestValidateEnvoyGateway(t *testing.T) {
},
},
Service: &v1alpha1.ExtensionService{
Backend: v1alpha1.BackendEndpoint{
BackendEndpoint: v1alpha1.BackendEndpoint{
FQDN: &v1alpha1.FQDNEndpoint{
Hostname: "foo.example.com",
Port: 8080,
Expand Down Expand Up @@ -647,7 +647,7 @@ func TestValidateEnvoyGateway(t *testing.T) {
Service: &v1alpha1.ExtensionService{
Host: "foo.example.com",
Port: 8080,
Backend: v1alpha1.BackendEndpoint{
BackendEndpoint: v1alpha1.BackendEndpoint{
FQDN: &v1alpha1.FQDNEndpoint{
Hostname: "foo.example.com",
Port: 8080,
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

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

12 changes: 6 additions & 6 deletions internal/extension/registry/extension_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ func (m *Manager) HasExtension(g v1.Group, k v1.Kind) bool {
func getExtensionServerAddress(service *v1alpha1.ExtensionService) string {
var serverAddr string
switch {
case service.Backend.FQDN != nil:
serverAddr = fmt.Sprintf("%s:%d", service.Backend.FQDN.Hostname, service.Backend.FQDN.Port)
case service.Backend.IPv4 != nil:
serverAddr = fmt.Sprintf("%s:%d", service.Backend.IPv4.Address, service.Backend.IPv4.Port)
case service.Backend.Unix != nil:
serverAddr = fmt.Sprintf("unix://%s", service.Backend.Unix.Path)
case service.FQDN != nil:
serverAddr = fmt.Sprintf("%s:%d", service.FQDN.Hostname, service.FQDN.Port)
case service.IPv4 != nil:
serverAddr = fmt.Sprintf("%s:%d", service.IPv4.Address, service.IPv4.Port)
case service.Unix != nil:
serverAddr = fmt.Sprintf("unix://%s", service.Unix.Path)
case service.Host != "":
serverAddr = fmt.Sprintf("%s:%d", service.Host, service.Port)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/extension/registry/extension_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestGetExtensionServerAddress(t *testing.T) {
{
Name: "has an FQDN",
Service: &v1alpha1.ExtensionService{
Backend: v1alpha1.BackendEndpoint{
BackendEndpoint: v1alpha1.BackendEndpoint{
FQDN: &v1alpha1.FQDNEndpoint{
Hostname: "extserver.svc.cluster.local",
Port: 5050,
Expand All @@ -34,7 +34,7 @@ func TestGetExtensionServerAddress(t *testing.T) {
{
Name: "has an IPv4",
Service: &v1alpha1.ExtensionService{
Backend: v1alpha1.BackendEndpoint{
BackendEndpoint: v1alpha1.BackendEndpoint{
IPv4: &v1alpha1.IPv4Endpoint{
Address: "10.10.10.10",
Port: 5050,
Expand All @@ -46,7 +46,7 @@ func TestGetExtensionServerAddress(t *testing.T) {
{
Name: "has a Unix path",
Service: &v1alpha1.ExtensionService{
Backend: v1alpha1.BackendEndpoint{
BackendEndpoint: v1alpha1.BackendEndpoint{
Unix: &v1alpha1.UnixSocket{
Path: "/some/path",
},
Expand Down
11 changes: 8 additions & 3 deletions site/content/en/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -1515,9 +1515,11 @@ _Appears in:_

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `host` | _string_ | false | Host define the extension service hostname.<br />Deprecated: use the backend attribute instead |
| `port` | _integer_ | false | Port defines the port the extension service is exposed on.<br />Deprecated: use the backend attribute instead |
| `backend` | _[BackendEndpoint](#backendendpoint)_ | true | Backend points to where the extension server can be found. |
| `fqdn` | _[FQDNEndpoint](#fqdnendpoint)_ | false | FQDN defines a FQDN endpoint |
| `ipv4` | _[IPv4Endpoint](#ipv4endpoint)_ | false | IPv4 defines an IPv4 endpoint |
| `unix` | _[UnixSocket](#unixsocket)_ | false | Unix defines the unix domain socket endpoint |
| `host` | _string_ | false | Host define the extension service hostname.<br />Deprecated: use the appropriate transport attribute instead (FQDN,IPv4,Unix) |
| `port` | _integer_ | false | Port defines the port the extension service is exposed on.<br />Deprecated: use the appropriate transport attribute instead (FQDN,IPv4,Unix) |
| `tls` | _[ExtensionTLS](#extensiontls)_ | false | TLS defines TLS configuration for communication between Envoy Gateway and<br />the extension service. |


Expand All @@ -1544,6 +1546,7 @@ https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/core/v3/address.proto#

_Appears in:_
- [BackendEndpoint](#backendendpoint)
- [ExtensionService](#extensionservice)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
Expand Down Expand Up @@ -1927,6 +1930,7 @@ https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/core/v3/address.proto#

_Appears in:_
- [BackendEndpoint](#backendendpoint)
- [ExtensionService](#extensionservice)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
Expand Down Expand Up @@ -3522,6 +3526,7 @@ https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/core/v3/address.proto#

_Appears in:_
- [BackendEndpoint](#backendendpoint)
- [ExtensionService](#extensionservice)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
Expand Down

0 comments on commit 90a4b99

Please sign in to comment.