Skip to content

Commit c0c9b9d

Browse files
[release-v0.15] RHOAIENG-24134: KServe Support secure access to the metrics server with TriggerAuthentication for KEDA autoscaling (#644)
* support for secure access to the metric server Signed-off-by: Andrews Arokiam <[email protected]> * precommit check Signed-off-by: Andrews Arokiam <[email protected]> * added field authmodes Signed-off-by: Andrews Arokiam <[email protected]> * added e2e tests Signed-off-by: Andrews Arokiam <[email protected]> --------- Signed-off-by: Andrews Arokiam <[email protected]> Co-authored-by: Andrews Arokiam <[email protected]>
1 parent db8f8f2 commit c0c9b9d

17 files changed

+424
-3
lines changed

config/crd/full/serving.kserve.io_inferenceservices.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,8 +1196,17 @@ spec:
11961196
properties:
11971197
external:
11981198
properties:
1199+
authenticationRef:
1200+
properties:
1201+
name:
1202+
type: string
1203+
required:
1204+
- name
1205+
type: object
11991206
metric:
12001207
properties:
1208+
authModes:
1209+
type: string
12011210
backend:
12021211
enum:
12031212
- prometheus
@@ -4336,8 +4345,17 @@ spec:
43364345
properties:
43374346
external:
43384347
properties:
4348+
authenticationRef:
4349+
properties:
4350+
name:
4351+
type: string
4352+
required:
4353+
- name
4354+
type: object
43394355
metric:
43404356
properties:
4357+
authModes:
4358+
type: string
43414359
backend:
43424360
enum:
43434361
- prometheus
@@ -18649,8 +18667,17 @@ spec:
1864918667
properties:
1865018668
external:
1865118669
properties:
18670+
authenticationRef:
18671+
properties:
18672+
name:
18673+
type: string
18674+
required:
18675+
- name
18676+
type: object
1865218677
metric:
1865318678
properties:
18679+
authModes:
18680+
type: string
1865418681
backend:
1865518682
enum:
1865618683
- prometheus

pkg/apis/serving/v1beta1/component.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ type ExternalMetricSource struct {
201201
// metric identifies the target metric by name and selector
202202
Metric ExternalMetrics `json:"metric"`
203203

204+
// authenticationRef is a reference to the authentication information
205+
// for more information see: https://keda.sh/docs/2.17/scalers/prometheus/#authentication-parameters
206+
// +optional
207+
AuthenticationRef ExtMetricAuth `json:"authenticationRef"`
208+
204209
// target specifies the target value for the given metric
205210
Target MetricTarget `json:"target"`
206211
}
@@ -217,6 +222,10 @@ type PodMetricSource struct {
217222
Target MetricTarget `json:"target"`
218223
}
219224

225+
type ExtMetricAuth struct {
226+
Name string `json:"name"`
227+
}
228+
220229
// MetricTarget defines the target value, average value, or average utilization of a specific metric
221230
type MetricTarget struct {
222231
// type represents whether the metric type is Utilization, Value, or AverageValue
@@ -268,6 +277,9 @@ type ExternalMetrics struct {
268277
// For namespaced query
269278
// +optional
270279
Namespace string `json:"namespace,omitempty"`
280+
// authModes defines the authentication modes for the metrics backend
281+
// +optional
282+
AuthModes string `json:"authModes,omitempty"`
271283
}
272284

273285
type PodMetrics struct {

pkg/apis/serving/v1beta1/zz_generated.deepcopy.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/controller/v1beta1/inferenceservice/reconcilers/keda/keda_reconciler.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ func getKedaMetrics(componentExt *v1beta1.ComponentExtensionSpec,
108108
case v1beta1.ExternalMetricSourceType:
109109
triggerType := string(metric.External.Metric.Backend)
110110
serverAddress := metric.External.Metric.ServerAddress
111+
authModes := metric.External.Metric.AuthModes
111112
query := metric.External.Metric.Query
113+
authRef := metric.External.AuthenticationRef
112114

113115
trigger := kedav1alpha1.ScaleTriggers{
114116
Type: triggerType,
@@ -118,9 +120,17 @@ func getKedaMetrics(componentExt *v1beta1.ComponentExtensionSpec,
118120
"threshold": fmt.Sprintf("%f", metric.External.Target.Value.AsApproximateFloat64()),
119121
},
120122
}
123+
if authModes != "" {
124+
trigger.Metadata["authModes"] = authModes
125+
}
121126
if triggerType == string(constants.AutoScalerMetricsSourcePrometheus) && metric.External.Metric.Namespace != "" {
122127
trigger.Metadata["namespace"] = metric.External.Metric.Namespace
123128
}
129+
if authRef.Name != "" {
130+
trigger.AuthenticationRef = &kedav1alpha1.AuthenticationRef{
131+
Name: authRef.Name,
132+
}
133+
}
124134
triggers = append(triggers, trigger)
125135
case v1beta1.PodMetricSourceType:
126136
otelConfig, err := v1beta1.NewOtelCollectorConfig(configMap)

pkg/openapi/openapi_generated.go

Lines changed: 36 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/openapi/swagger.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2791,13 +2791,27 @@
27912791
}
27922792
}
27932793
},
2794+
"v1beta1.ExtMetricAuth": {
2795+
"type": "object",
2796+
"properties": {
2797+
"name": {
2798+
"type": "string",
2799+
"default": ""
2800+
}
2801+
}
2802+
},
27942803
"v1beta1.ExternalMetricSource": {
27952804
"type": "object",
27962805
"required": [
27972806
"metric",
27982807
"target"
27992808
],
28002809
"properties": {
2810+
"authenticationRef": {
2811+
"description": "authenticationRef is a reference to the authentication information for more information see: https://keda.sh/docs/2.17/scalers/prometheus/#authentication-parameters",
2812+
"default": {},
2813+
"$ref": "#/definitions/v1beta1.ExtMetricAuth"
2814+
},
28012815
"metric": {
28022816
"description": "metric identifies the target metric by name and selector",
28032817
"default": {},
@@ -2813,6 +2827,10 @@
28132827
"v1beta1.ExternalMetrics": {
28142828
"type": "object",
28152829
"properties": {
2830+
"authModes": {
2831+
"description": "authModes defines the authentication modes for the metrics backend",
2832+
"type": "string"
2833+
},
28162834
"backend": {
28172835
"description": "MetricsBackend defines the scaling metric type watched by autoscaler possible values are prometheus, graphite.",
28182836
"type": "string",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# V1beta1ExtMetricAuth
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
**name** | **str** | | [optional] [default to '']
7+
8+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
9+
10+

python/kserve/docs/V1beta1ExternalMetricSource.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Properties
44
Name | Type | Description | Notes
55
------------ | ------------- | ------------- | -------------
6+
**authentication_ref** | [**V1beta1ExtMetricAuth**](V1beta1ExtMetricAuth.md) | | [optional]
67
**metric** | [**V1beta1ExternalMetrics**](V1beta1ExternalMetrics.md) | |
78
**target** | [**V1beta1MetricTarget**](V1beta1MetricTarget.md) | |
89

python/kserve/docs/V1beta1ExternalMetrics.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Properties
44
Name | Type | Description | Notes
55
------------ | ------------- | ------------- | -------------
6+
**auth_modes** | **str** | authModes defines the authentication modes for the metrics backend | [optional]
67
**backend** | **str** | MetricsBackend defines the scaling metric type watched by autoscaler possible values are prometheus, graphite. | [optional] [default to '']
78
**namespace** | **str** | For namespaced query | [optional]
89
**query** | **str** | Query to run to get metrics from MetricsBackend | [optional]

python/kserve/kserve/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,4 @@
114114
from .models.v1beta1_metrics_spec import V1beta1MetricsSpec
115115
from .models.v1beta1_pod_metric_source import V1beta1PodMetricSource
116116
from .models.v1beta1_pod_metrics import V1beta1PodMetrics
117+
from .models.v1beta1_ext_metric_auth import V1beta1ExtMetricAuth

0 commit comments

Comments
 (0)