Skip to content

Commit

Permalink
chore: Update skipscaledobjectcreation annotation to align with KEDA …
Browse files Browse the repository at this point in the history
…annotations (#1008)

* chore: Update skip-scaledobject-creation to align with KEDA annotations

Signed-off-by: Jorge Turrado <[email protected]>

* use magic string during test to prevent not detected chained changes

Signed-off-by: Jorge Turrado <[email protected]>

---------

Signed-off-by: Jorge Turrado <[email protected]>
  • Loading branch information
JorTurFer authored Apr 30, 2024
1 parent 7feda00 commit e3d2e81
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
9 changes: 8 additions & 1 deletion docs/ref/v0.8.0/http_scaled_object.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ kind: HTTPScaledObject
apiVersion: http.keda.sh/v1alpha1
metadata:
name: xkcd
annotations:
httpscaledobject.keda.sh/skip-scaledobject-creation: "false"
spec:
hosts:
- myhost.com
Expand All @@ -33,7 +35,12 @@ spec:
targetValue: 100
```
This document is a narrated reference guide for the `HTTPScaledObject`, and we'll focus on the `spec` field.
This document is a narrated reference guide for the `HTTPScaledObject`.

## `httpscaledobject.keda.sh/skip-scaledobject-creation` annotation

This annotation will disable the ScaledObject generation and management but keeping the routing and metrics available. This is done removing the current ScaledObject if it has been already created, allowing to use user managed ScaledObjects pointing the add-on scaler directly (supporting all the ScaledObject configurations and multiple triggers). You can read more about this [here](./../../walkthrough.md#integrating-http-add-on-scaler-with-other-keda-scalers)


## `hosts`

Expand Down
8 changes: 4 additions & 4 deletions docs/walkthrough.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ curl -H "Host: myhost.com" localhost:8080/path1

### Integrating HTTP Add-On Scaler with other KEDA scalers

For scenerios where you want to integrate HTTP Add-On scaler with other keda scalers, you can set the `SkipScaledObjectCreation` annotation to true on your `HTTPScaledObject`. The reconciler will then skip the KEDA core ScaledObject creation which will allow you to create your own `ScaledObject` and add HTTP scaler as one of your triggers.
For scenerios where you want to integrate HTTP Add-On scaler with other keda scalers, you can set the `"httpscaledobject.keda.sh/skip-scaledobject-creation"` annotation to true on your `HTTPScaledObject`. The reconciler will then skip the KEDA core ScaledObject creation which will allow you to create your own `ScaledObject` and add HTTP scaler as one of your triggers.

> 💡 Ensure that your ScaledObject is created with a different name than the `HTTPScaledObject` to ensure your ScaledObject is not removed by the reconciler.
Expand All @@ -101,7 +101,7 @@ If you don't know how to set the external scaler in the ScaledObject, you can de

```console
annotations:
skipScaledObjectCreation: false
httpscaledobject.keda.sh/skip-scaledobject-creation: "false"
```

2. Take copy of the current generated external-push trigger spec on the generated ScaledObject.
Expand All @@ -116,11 +116,11 @@ For example:
scalerAddress: keda-http-add-on-external-scaler.keda:9090
```

3. Apply the `skipScaledObjectCreation` annotation with `true` and apply the change. This will remove the originally created `ScaledObject` allowing you to create your own.
3. Apply the `"httpscaledobject.keda.sh/skip-scaledobject-creation"` annotation with `true` and apply the change. This will remove the originally created `ScaledObject` allowing you to create your own.

```console
annotations:
skipScaledObjectCreation: true
httpscaledobject.keda.sh/skip-scaledobject-creation: "true"
```

4. Add the `external-push` trigger taken from step 2 to your own ScaledObject and apply this.
Expand Down
10 changes: 7 additions & 3 deletions operator/controllers/http/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (
"github.com/kedacore/http-add-on/operator/controllers/http/config"
)

var (
SkipScaledObjectCreationAnnotation = "httpscaledobject.keda.sh/skip-scaledobject-creation"
)

func (r *HTTPScaledObjectReconciler) createOrUpdateApplicationResources(
ctx context.Context,
logger logr.Logger,
Expand Down Expand Up @@ -45,12 +49,12 @@ func (r *HTTPScaledObjectReconciler) createOrUpdateApplicationResources(
)

// We want to integrate http scaler with other
// scalers. when SkipScaledObjectCreation is set to true,
// scalers. when "httpscaledobject.keda.sh/skip-scaledobject-creation" is set to true,
// reconciler will skip the KEDA core ScaledObjects creation or delete scaledObject if it already exists.
// you can then create your own SO, and add http scaler as one of your triggers.
if httpso.Annotations["skipScaledObjectCreation"] == "true" {
if httpso.Annotations[SkipScaledObjectCreationAnnotation] == "true" {
logger.Info(
"Skip scaled objects creation with flag SkipScaledObjectCreation=true",
"Skip scaled objects creation with flag 'httpscaledobject.keda.sh/skip-scaledobject-creation'=true",
"HTTPScaledObject", httpso.Name)
err := r.deleteScaledObject(ctx, cl, logger, httpso)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion operator/controllers/http/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func newCommonTestInfraWithSkipScaledObjectCreation(namespace, appName string) *
Namespace: namespace,
Name: appName,
Annotations: map[string]string{
"skipScaledObjectCreation": "true",
"httpscaledobject.keda.sh/skip-scaledobject-creation": "true",
},
},
Spec: httpv1alpha1.HTTPScaledObjectSpec{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ metadata:
name: {{.HTTPScaledObjectName}}
namespace: {{.TestNamespace}}
annotations:
skipScaledObjectCreation: "true"
httpscaledobject.keda.sh/skip-scaledobject-creation: "true"
spec:
hosts:
- {{.Host}}
Expand Down

0 comments on commit e3d2e81

Please sign in to comment.