Skip to content

feat(healthz-server): add option to customize port #5151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions api/v1alpha1/envoygateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,14 @@ type EnvoyGatewayCustomProvider struct {
// No infrastructure provider is available.
// +optional
Infrastructure *EnvoyGatewayInfrastructureProvider `json:"infrastructure,omitempty"`

// HealthzServerPort defines the port for the healthz probe server.
// By default, when this field is unset or empty, Envoy Gateway will use the port 8081 for the healthz server.
// +optional
// +kubebuilder:default=8081
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=65535
HealthzServerPort *int `json:"healthzServerPort,omitempty"`
}

// ResourceProviderType defines the types of custom resource providers supported by Envoy Gateway.
Expand Down
26 changes: 24 additions & 2 deletions api/v1alpha1/validation/envoygateway_validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import (
)

var (
TLSSecretKind = gwapiv1.Kind("Secret")
TLSUnrecognizedKind = gwapiv1.Kind("Unrecognized")
TLSSecretKind = gwapiv1.Kind("Secret")
TLSUnrecognizedKind = gwapiv1.Kind("Unrecognized")
MockHealthzServerPort = 1234
)

func TestValidateEnvoyGateway(t *testing.T) {
Expand Down Expand Up @@ -93,6 +94,27 @@ func TestValidateEnvoyGateway(t *testing.T) {
},
expect: false,
},
{
name: "custom provider with file provider with custom healthz probe port",
eg: &egv1a1.EnvoyGateway{
EnvoyGatewaySpec: egv1a1.EnvoyGatewaySpec{
Gateway: egv1a1.DefaultGateway(),
Provider: &egv1a1.EnvoyGatewayProvider{
Type: egv1a1.ProviderTypeCustom,
Custom: &egv1a1.EnvoyGatewayCustomProvider{
Resource: egv1a1.EnvoyGatewayResourceProvider{
Type: egv1a1.ResourceProviderTypeFile,
File: &egv1a1.EnvoyGatewayFileResourceProvider{
Paths: []string{"foo", "bar"},
},
},
HealthzServerPort: &MockHealthzServerPort,
},
},
},
},
expect: true,
},
{
name: "custom provider with file resource provider and host infra provider",
eg: &egv1a1.EnvoyGateway{
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

25 changes: 16 additions & 9 deletions internal/provider/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ import (
)

type Provider struct {
paths []string
logger logr.Logger
watcher filewatcher.FileWatcher
resourcesStore *resourcesStore
paths []string
logger logr.Logger
watcher filewatcher.FileWatcher
resourcesStore *resourcesStore
healthzServerPort int

// ready indicates whether the provider can start watching filesystem events.
ready atomic.Bool
Expand All @@ -44,11 +45,17 @@ func New(svr *config.Server, resources *message.ProviderResources) (*Provider, e
paths.Insert(svr.EnvoyGateway.Provider.Custom.Resource.File.Paths...)
}

healthzServerPort := 8081 // Default healthz server port.
if svr.EnvoyGateway.Provider.Custom.HealthzServerPort != nil {
healthzServerPort = *svr.EnvoyGateway.Provider.Custom.HealthzServerPort
}

return &Provider{
paths: paths.UnsortedList(),
logger: logger,
watcher: filewatcher.NewWatcher(),
resourcesStore: newResourcesStore(svr.EnvoyGateway.Gateway.ControllerName, resources, logger),
paths: paths.UnsortedList(),
logger: logger,
watcher: filewatcher.NewWatcher(),
resourcesStore: newResourcesStore(svr.EnvoyGateway.Gateway.ControllerName, resources, logger),
healthzServerPort: healthzServerPort,
}, nil
}

Expand Down Expand Up @@ -168,7 +175,7 @@ func (p *Provider) startHealthProbeServer(ctx context.Context, readyzChecker hea

mux := http.NewServeMux()
srv := &http.Server{
Addr: ":8081",
Addr: fmt.Sprintf(":%d", p.healthzServerPort),
Handler: mux,
MaxHeaderBytes: 1 << 20,
IdleTimeout: 90 * time.Second, // matches http.DefaultTransport keep-alive timeout
Expand Down
6 changes: 5 additions & 1 deletion internal/provider/file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package file

import (
"context"
"fmt"
"html/template"
"io"
"net/http"
Expand All @@ -31,6 +32,8 @@ const (
resourcesUpdateTick = 1 * time.Second
)

var healthzServerPort = 8082

type resourcesParam struct {
GatewayClassName string
GatewayName string
Expand Down Expand Up @@ -64,6 +67,7 @@ func newFileProviderConfig(paths []string) (*config.Server, error) {
Paths: paths,
},
},
HealthzServerPort: &healthzServerPort,
},
}
return cfg, nil
Expand Down Expand Up @@ -195,7 +199,7 @@ func writeResourcesFile(t *testing.T, tmpl, dst string, params *resourcesParam)

func waitFileProviderReady(t *testing.T) {
require.Eventually(t, func() bool {
resp, err := http.Get("http://localhost:8081/readyz")
resp, err := http.Get(fmt.Sprintf("http://localhost:%d/readyz", healthzServerPort))
if err != nil {
t.Logf("failed to get from heathlz server")
return false
Expand Down
1 change: 1 addition & 0 deletions release-notes/current.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ security updates: |

# New features or capabilities added in this release.
new features: |
Added support to configure custom port for healthz server for EnvoyGatewayCustomProvider.

bug fixes: |

Expand Down
1 change: 1 addition & 0 deletions site/content/en/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,7 @@ _Appears in:_
| --- | --- | --- | --- | --- |
| `resource` | _[EnvoyGatewayResourceProvider](#envoygatewayresourceprovider)_ | true | | Resource defines the desired resource provider.<br />This provider is used to specify the provider to be used<br />to retrieve the resource configurations such as Gateway API<br />resources |
| `infrastructure` | _[EnvoyGatewayInfrastructureProvider](#envoygatewayinfrastructureprovider)_ | false | | Infrastructure defines the desired infrastructure provider.<br />This provider is used to specify the provider to be used<br />to provide an environment to deploy the out resources like<br />the Envoy Proxy data plane.<br /><br />Infrastructure is optional, if provider is not specified,<br />No infrastructure provider is available. |
| `healthzServerPort` | _integer_ | false | 8081 | HealthzServerPort defines the port for the healthz probe server.<br />By default, when this field is unset or empty, Envoy Gateway will use the port 8081 for the healthz server. |


#### EnvoyGatewayFileResourceProvider
Expand Down
1 change: 1 addition & 0 deletions site/content/zh/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,7 @@ _Appears in:_
| --- | --- | --- | --- | --- |
| `resource` | _[EnvoyGatewayResourceProvider](#envoygatewayresourceprovider)_ | true | | Resource defines the desired resource provider.<br />This provider is used to specify the provider to be used<br />to retrieve the resource configurations such as Gateway API<br />resources |
| `infrastructure` | _[EnvoyGatewayInfrastructureProvider](#envoygatewayinfrastructureprovider)_ | false | | Infrastructure defines the desired infrastructure provider.<br />This provider is used to specify the provider to be used<br />to provide an environment to deploy the out resources like<br />the Envoy Proxy data plane.<br /><br />Infrastructure is optional, if provider is not specified,<br />No infrastructure provider is available. |
| `healthzServerPort` | _integer_ | false | 8081 | HealthzServerPort defines the port for the healthz probe server.<br />By default, when this field is unset or empty, Envoy Gateway will use the port 8081 for the healthz server. |


#### EnvoyGatewayFileResourceProvider
Expand Down
Loading