diff --git a/pkg/fleetautoscalers/fleetautoscalers.go b/pkg/fleetautoscalers/fleetautoscalers.go index 27063e8f79..2e292556f0 100644 --- a/pkg/fleetautoscalers/fleetautoscalers.go +++ b/pkg/fleetautoscalers/fleetautoscalers.go @@ -91,14 +91,19 @@ func buildURLFromWebhookPolicy(w *autoscalingv1.WebhookPolicy) (u *url.URL, err w.Service.Namespace = "default" } - return createURL(scheme, w.Service.Name, w.Service.Namespace, *w.Service.Path), nil + return createURL(scheme, w.Service.Name, w.Service.Namespace, *w.Service.Path, w.Service.Port), nil } // moved to a separate method to cover it with unit tests and check that URL corresponds to a proper pattern -func createURL(scheme, name, namespace, path string) *url.URL { +func createURL(scheme, name, namespace, path string, port *int32) *url.URL { + var hostPort int32 = 8000 + if port != nil { + hostPort = *port + } + return &url.URL{ Scheme: scheme, - Host: fmt.Sprintf("%s.%s.svc:8000", name, namespace), + Host: fmt.Sprintf("%s.%s.svc:%d", name, namespace, hostPort), Path: path, } } diff --git a/pkg/fleetautoscalers/fleetautoscalers_test.go b/pkg/fleetautoscalers/fleetautoscalers_test.go index 0c5971c0b5..415e2cc2c1 100644 --- a/pkg/fleetautoscalers/fleetautoscalers_test.go +++ b/pkg/fleetautoscalers/fleetautoscalers_test.go @@ -578,6 +578,7 @@ func TestApplyWebhookPolicyNilFleet(t *testing.T) { func TestCreateURL(t *testing.T) { t.Parallel() + var nonStandardPort int32 = 8888 var testCases = []struct { description string @@ -585,6 +586,7 @@ func TestCreateURL(t *testing.T) { name string namespace string path string + port *int32 expected string }{ { @@ -611,11 +613,20 @@ func TestCreateURL(t *testing.T) { path: "", expected: "http://service1.default.svc:8000", }, + { + description: "OK, port specified", + scheme: "http", + name: "service1", + namespace: "default", + path: "scale", + port: &nonStandardPort, + expected: "http://service1.default.svc:8888/scale", + }, } for _, tc := range testCases { t.Run(tc.description, func(t *testing.T) { - res := createURL(tc.scheme, tc.name, tc.namespace, tc.path) + res := createURL(tc.scheme, tc.name, tc.namespace, tc.path, tc.port) if assert.NotNil(t, res) { assert.Equal(t, tc.expected, res.String()) diff --git a/site/content/en/docs/Reference/fleetautoscaler.md b/site/content/en/docs/Reference/fleetautoscaler.md index 3dc6284904..62511f8f8f 100644 --- a/site/content/en/docs/Reference/fleetautoscaler.md +++ b/site/content/en/docs/Reference/fleetautoscaler.md @@ -92,6 +92,9 @@ The `spec` field is the actual `FleetAutoscaler` specification and it is compose - `namespace` is the kubernetes namespace where webhook is deployed. Optional If not specified, the "default" would be used - `path` is an optional URL path which will be sent in any request to this service. (i. e. /scale) +{{% feature publishVersion="1.9.0" %}} + - `port` is optional, it is the port for the service which is hosting the webhook. The default is 8000 for backward compatibility. If given, it should be a valid port number (1-65535, inclusive). +{{% /feature %}} - `url` gives the location of the webhook, in standard URL form (`[scheme://]host:port/path`). Exactly one of `url` or `service` must be specified. The `host` should not refer to a service running in the cluster; use the `service` field instead. (optional, instead of service) - `caBundle` is a PEM encoded certificate authority bundle which is used to issue and then validate the webhook's server certificate. Base64 encoded PEM string. Required only for HTTPS. If not present HTTP client would be used.