Skip to content

Commit 96c2ba3

Browse files
SpiritZhouJorTurFerzroubalik
authored
Show full triggers and authentications in status (#6232)
Co-authored-by: Jorge Turrado Ferrero <[email protected]> Co-authored-by: Zbynek Roubalik <[email protected]>
1 parent 2f66865 commit 96c2ba3

File tree

11 files changed

+400
-21
lines changed

11 files changed

+400
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Here is an overview of all new **experimental** features:
7777
### Improvements
7878

7979
- **General**: Prevent multiple ScaledObjects managing one HPA ([#6130](https://github.com/kedacore/keda/issues/6130))
80+
- **General**: Show full triggers'types and authentications'types in status ([#6187](https://github.com/kedacore/keda/issues/6187))
8081
- **AWS CloudWatch Scaler**: Add support for ignoreNullValues ([#5352](https://github.com/kedacore/keda/issues/5352))
8182
- **Elasticsearch Scaler**: Support Query at the Elasticsearch scaler ([#6216](https://github.com/kedacore/keda/issues/6216))
8283
- **Etcd Scaler**: Add username and password support for etcd ([#6199](https://github.com/kedacore/keda/pull/6199))

apis/keda/v1alpha1/scaledjob_types.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ const (
3232
// +kubebuilder:resource:path=scaledjobs,scope=Namespaced,shortName=sj
3333
// +kubebuilder:printcolumn:name="Min",type="integer",JSONPath=".spec.minReplicaCount"
3434
// +kubebuilder:printcolumn:name="Max",type="integer",JSONPath=".spec.maxReplicaCount"
35-
// +kubebuilder:printcolumn:name="Triggers",type="string",JSONPath=".spec.triggers[*].type"
36-
// +kubebuilder:printcolumn:name="Authentication",type="string",JSONPath=".spec.triggers[*].authenticationRef.name"
3735
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].status"
3836
// +kubebuilder:printcolumn:name="Active",type="string",JSONPath=".status.conditions[?(@.type==\"Active\")].status"
3937
// +kubebuilder:printcolumn:name="Paused",type="string",JSONPath=".status.conditions[?(@.type==\"Paused\")].status"
38+
// +kubebuilder:printcolumn:name="Triggers",type="string",JSONPath=".status.triggersTypes"
39+
// +kubebuilder:printcolumn:name="Authentications",type="string",JSONPath=".status.authenticationsTypes"
4040
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
4141

4242
// ScaledJob is the Schema for the scaledjobs API
@@ -81,6 +81,10 @@ type ScaledJobStatus struct {
8181
Conditions Conditions `json:"conditions,omitempty"`
8282
// +optional
8383
Paused string `json:"Paused,omitempty"`
84+
// +optional
85+
TriggersTypes *string `json:"triggersTypes,omitempty"`
86+
// +optional
87+
AuthenticationsTypes *string `json:"authenticationsTypes,omitempty"`
8488
}
8589

8690
// ScaledJobList contains a list of ScaledJob

apis/keda/v1alpha1/scaledobject_types.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ import (
3333
// +kubebuilder:printcolumn:name="ScaleTargetName",type="string",JSONPath=".spec.scaleTargetRef.name"
3434
// +kubebuilder:printcolumn:name="Min",type="integer",JSONPath=".spec.minReplicaCount"
3535
// +kubebuilder:printcolumn:name="Max",type="integer",JSONPath=".spec.maxReplicaCount"
36-
// +kubebuilder:printcolumn:name="Triggers",type="string",JSONPath=".spec.triggers[*].type"
37-
// +kubebuilder:printcolumn:name="Authentication",type="string",JSONPath=".spec.triggers[*].authenticationRef.name"
3836
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].status"
3937
// +kubebuilder:printcolumn:name="Active",type="string",JSONPath=".status.conditions[?(@.type==\"Active\")].status"
4038
// +kubebuilder:printcolumn:name="Fallback",type="string",JSONPath=".status.conditions[?(@.type==\"Fallback\")].status"
4139
// +kubebuilder:printcolumn:name="Paused",type="string",JSONPath=".status.conditions[?(@.type==\"Paused\")].status"
40+
// +kubebuilder:printcolumn:name="Triggers",type="string",JSONPath=".status.triggersTypes"
41+
// +kubebuilder:printcolumn:name="Authentications",type="string",JSONPath=".status.authenticationsTypes"
4242
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
4343

4444
// ScaledObject is a specification for a ScaledObject resource
@@ -177,6 +177,10 @@ type ScaledObjectStatus struct {
177177
PausedReplicaCount *int32 `json:"pausedReplicaCount,omitempty"`
178178
// +optional
179179
HpaName string `json:"hpaName,omitempty"`
180+
// +optional
181+
TriggersTypes *string `json:"triggersTypes,omitempty"`
182+
// +optional
183+
AuthenticationsTypes *string `json:"authenticationsTypes,omitempty"`
180184
}
181185

182186
// +kubebuilder:object:root=true

apis/keda/v1alpha1/scaletriggers_types.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package v1alpha1
1818

1919
import (
2020
"fmt"
21+
"slices"
22+
"strings"
2123

2224
autoscalingv2 "k8s.io/api/autoscaling/v2"
2325
)
@@ -80,3 +82,18 @@ func ValidateTriggers(triggers []ScaleTriggers) error {
8082

8183
return nil
8284
}
85+
86+
// CombinedTriggersAndAuthenticationsTypes returns a comma separated string of all trigger types and authentication types
87+
func CombinedTriggersAndAuthenticationsTypes(triggers []ScaleTriggers) (string, string) {
88+
var triggersTypes []string
89+
var authTypes []string
90+
for _, trigger := range triggers {
91+
if !slices.Contains(triggersTypes, trigger.Type) {
92+
triggersTypes = append(triggersTypes, trigger.Type)
93+
}
94+
if trigger.AuthenticationRef != nil && !slices.Contains(authTypes, trigger.AuthenticationRef.Name) {
95+
authTypes = append(authTypes, trigger.AuthenticationRef.Name)
96+
}
97+
}
98+
return strings.Join(triggersTypes, ","), strings.Join(authTypes, ",")
99+
}

apis/keda/v1alpha1/zz_generated.deepcopy.go

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

config/crd/bases/keda.sh_scaledjobs.yaml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ spec:
2323
- jsonPath: .spec.maxReplicaCount
2424
name: Max
2525
type: integer
26-
- jsonPath: .spec.triggers[*].type
27-
name: Triggers
28-
type: string
29-
- jsonPath: .spec.triggers[*].authenticationRef.name
30-
name: Authentication
31-
type: string
3226
- jsonPath: .status.conditions[?(@.type=="Ready")].status
3327
name: Ready
3428
type: string
@@ -38,6 +32,12 @@ spec:
3832
- jsonPath: .status.conditions[?(@.type=="Paused")].status
3933
name: Paused
4034
type: string
35+
- jsonPath: .status.triggersTypes
36+
name: Triggers
37+
type: string
38+
- jsonPath: .status.authenticationsTypes
39+
name: Authentications
40+
type: string
4141
- jsonPath: .metadata.creationTimestamp
4242
name: Age
4343
type: date
@@ -8062,6 +8062,8 @@ spec:
80628062
properties:
80638063
Paused:
80648064
type: string
8065+
authenticationsTypes:
8066+
type: string
80658067
conditions:
80668068
description: Conditions an array representation to store multiple
80678069
Conditions
@@ -8089,6 +8091,8 @@ spec:
80898091
lastActiveTime:
80908092
format: date-time
80918093
type: string
8094+
triggersTypes:
8095+
type: string
80928096
type: object
80938097
type: object
80948098
served: true

config/crd/bases/keda.sh_scaledobjects.yaml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ spec:
2929
- jsonPath: .spec.maxReplicaCount
3030
name: Max
3131
type: integer
32-
- jsonPath: .spec.triggers[*].type
33-
name: Triggers
34-
type: string
35-
- jsonPath: .spec.triggers[*].authenticationRef.name
36-
name: Authentication
37-
type: string
3832
- jsonPath: .status.conditions[?(@.type=="Ready")].status
3933
name: Ready
4034
type: string
@@ -47,6 +41,12 @@ spec:
4741
- jsonPath: .status.conditions[?(@.type=="Paused")].status
4842
name: Paused
4943
type: string
44+
- jsonPath: .status.triggersTypes
45+
name: Triggers
46+
type: string
47+
- jsonPath: .status.authenticationsTypes
48+
name: Authentications
49+
type: string
5050
- jsonPath: .metadata.creationTimestamp
5151
name: Age
5252
type: date
@@ -309,6 +309,8 @@ spec:
309309
status:
310310
description: ScaledObjectStatus is the status for a ScaledObject resource
311311
properties:
312+
authenticationsTypes:
313+
type: string
312314
compositeScalerName:
313315
type: string
314316
conditions:
@@ -387,6 +389,8 @@ spec:
387389
type: object
388390
scaleTargetKind:
389391
type: string
392+
triggersTypes:
393+
type: string
390394
type: object
391395
required:
392396
- spec

controllers/keda/scaledjob_controller.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ func (r *ScaledJobReconciler) reconcileScaledJob(ctx context.Context, logger log
191191
return "ScaledJob doesn't have correct triggers specification", err
192192
}
193193

194+
err = r.updateStatusWithTriggersAndAuthsTypes(ctx, logger, scaledJob)
195+
if err != nil {
196+
return "Cannot update ScaledJob status with triggers'names and authentications'names", err
197+
}
198+
194199
// nosemgrep: trailofbits.go.invalid-usage-of-modified-variable.invalid-usage-of-modified-variable
195200
msg, err := r.deletePreviousVersionScaleJobs(ctx, logger, scaledJob)
196201
if err != nil {
@@ -404,3 +409,14 @@ func (r *ScaledJobReconciler) updateTriggerAuthenticationStatusOnDelete(ctx cont
404409
return triggerAuthenticationStatus
405410
})
406411
}
412+
413+
func (r *ScaledJobReconciler) updateStatusWithTriggersAndAuthsTypes(ctx context.Context, logger logr.Logger, scaledJob *kedav1alpha1.ScaledJob) error {
414+
triggersTypes, authsTypes := kedav1alpha1.CombinedTriggersAndAuthenticationsTypes(scaledJob.Spec.Triggers)
415+
status := scaledJob.Status.DeepCopy()
416+
status.TriggersTypes = &triggersTypes
417+
status.AuthenticationsTypes = &authsTypes
418+
419+
logger.V(1).Info("Updating ScaledJob status with triggers and authentications types", "triggersTypes", triggersTypes, "authenticationsTypes", authsTypes)
420+
421+
return kedastatus.UpdateScaledJobStatus(ctx, r.Client, logger, scaledJob, status)
422+
}

controllers/keda/scaledobject_controller.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,11 @@ func (r *ScaledObjectReconciler) reconcileScaledObject(ctx context.Context, logg
282282
return "ScaledObject doesn't have correct triggers specification", err
283283
}
284284

285+
err = r.updateStatusWithTriggersAndAuthsTypes(ctx, logger, scaledObject)
286+
if err != nil {
287+
return "Cannot update ScaledObject status with triggers'types and authentications'types", err
288+
}
289+
285290
// Create a new HPA or update existing one according to ScaledObject
286291
newHPACreated, err := r.ensureHPAForScaledObjectExists(ctx, logger, scaledObject, &gvkr)
287292
if err != nil {
@@ -621,3 +626,14 @@ func (r *ScaledObjectReconciler) updateTriggerAuthenticationStatusOnDelete(ctx c
621626
return triggerAuthenticationStatus
622627
})
623628
}
629+
630+
func (r *ScaledObjectReconciler) updateStatusWithTriggersAndAuthsTypes(ctx context.Context, logger logr.Logger, scaledObject *kedav1alpha1.ScaledObject) error {
631+
triggersTypes, authsTypes := kedav1alpha1.CombinedTriggersAndAuthenticationsTypes(scaledObject.Spec.Triggers)
632+
status := scaledObject.Status.DeepCopy()
633+
status.TriggersTypes = &triggersTypes
634+
status.AuthenticationsTypes = &authsTypes
635+
636+
logger.V(1).Info("Updating ScaledObject status with triggers and authentications types", "triggersTypes", triggersTypes, "authenticationsTypes", authsTypes)
637+
638+
return kedastatus.UpdateScaledObjectStatus(ctx, r.Client, logger, scaledObject, status)
639+
}

pkg/status/status.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,35 @@ func SetStatusConditions(ctx context.Context, client runtimeclient.StatusClient,
5555

5656
// UpdateScaledObjectStatus patches the given ScaledObject with the updated status passed to it or returns an error.
5757
func UpdateScaledObjectStatus(ctx context.Context, client runtimeclient.StatusClient, logger logr.Logger, scaledObject *kedav1alpha1.ScaledObject, status *kedav1alpha1.ScaledObjectStatus) error {
58+
return updateObjectStatus(ctx, client, logger, scaledObject, status)
59+
}
60+
61+
// UpdateScaledJobStatus patches the given ScaledObject with the updated status passed to it or returns an error.
62+
func UpdateScaledJobStatus(ctx context.Context, client runtimeclient.StatusClient, logger logr.Logger, scaledJob *kedav1alpha1.ScaledJob, status *kedav1alpha1.ScaledJobStatus) error {
63+
return updateObjectStatus(ctx, client, logger, scaledJob, status)
64+
}
65+
66+
// updateObjectStatus patches the given ScaledObject with the updated status passed to it or returns an error.
67+
func updateObjectStatus(ctx context.Context, client runtimeclient.StatusClient, logger logr.Logger, object interface{}, status interface{}) error {
5868
transform := func(runtimeObj runtimeclient.Object, target interface{}) error {
59-
status, ok := target.(*kedav1alpha1.ScaledObjectStatus)
60-
if !ok {
61-
return fmt.Errorf("transform target is not kedav1alpha1.ScaledObjectStatus type %v", target)
62-
}
6369
switch obj := runtimeObj.(type) {
6470
case *kedav1alpha1.ScaledObject:
71+
status, ok := target.(*kedav1alpha1.ScaledObjectStatus)
72+
if !ok {
73+
return fmt.Errorf("transform target is not kedav1alpha1.ScaledObjectStatus type %v", target)
74+
}
75+
obj.Status = *status
76+
case *kedav1alpha1.ScaledJob:
77+
status, ok := target.(*kedav1alpha1.ScaledJobStatus)
78+
if !ok {
79+
return fmt.Errorf("transform target is not kedav1alpha1.ScaledJobStatus type %v", target)
80+
}
6581
obj.Status = *status
6682
default:
6783
}
6884
return nil
6985
}
70-
return TransformObject(ctx, client, logger, scaledObject, status, transform)
86+
return TransformObject(ctx, client, logger, object, status, transform)
7187
}
7288

7389
// getTriggerAuth returns TriggerAuthentication/ClusterTriggerAuthentication object and its status from AuthenticationRef or returns an error.

0 commit comments

Comments
 (0)