Skip to content
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

Add config as parameter to help validate scaler meta data #5819

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ To learn more about active deprecations, we recommend checking [GitHub Discussio

### New


- TODO ([#XXX](https://github.com/kedacore/keda/issues/XXX))
- **General**: Declarative parsing of scaler config ([#5037](https://github.com/kedacore/keda/issues/5037)|[#5797](https://github.com/kedacore/keda/issues/5797))

Expand Down
2 changes: 1 addition & 1 deletion pkg/scalers/activemq_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type activeMQMetadata struct {
ActivationTargetQueueSize int64 `keda:"name=activationTargetQueueSize, order=triggerMetadata, optional, default=0"`
}

func (a *activeMQMetadata) Validate() error {
func (a *activeMQMetadata) Validate(_ scalersconfig.ScalerConfig) error {
Copy link
Member

@wozniakjan wozniakjan May 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given there are currently two configs that implement Validate() and both would ignore this argument, I would like to wait for a little bit before merging the PR.

I understand it will be useful for #5808 but I think it makes sense for now to first see a few more configs refactored and then make a decision. If a good number of configs find it useful, then I'm happy to add it. But if it's just a handful of configs, then perhaps we can consider a different pattern for those that need it without putting restrictions on scaler configs that don't need it, wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Let's wait for other scalers or find another way to do it.

if a.RestAPITemplate != "" {
// parse restAPITemplate to provide managementEndpoint, brokerName, destinationName
u, err := url.ParseRequestURI(a.RestAPITemplate)
Expand Down
4 changes: 3 additions & 1 deletion pkg/scalers/authentication/authentication_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"net/url"
"time"

"github.com/kedacore/keda/v2/pkg/scalers/scalersconfig"
)

// Type describes the authentication type used in a scaler
Expand Down Expand Up @@ -131,7 +133,7 @@ func (c *Config) GetBearerToken() string {
}

// Validate validates the Config and returns an error if it is invalid
func (c *Config) Validate() error {
func (c *Config) Validate(_ scalersconfig.ScalerConfig) error {
if c.Disabled() {
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/scalers/scalersconfig/typed_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (

// CustomValidator is an interface that can be implemented to validate the configuration of the typed config
type CustomValidator interface {
Validate() error
Validate(sc ScalerConfig) error
}

// ParsingOrder is a type that represents the order in which the parameters are parsed
Expand Down Expand Up @@ -170,7 +170,7 @@ func (sc *ScalerConfig) parseTypedConfig(typedConfig any, parentOptional bool) e
}
}
if validator, ok := typedConfig.(CustomValidator); ok {
if err := validator.Validate(); err != nil {
if err := validator.Validate(*sc); err != nil {
errs = append(errs, err)
}
}
Expand Down
Loading