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

[NATS JetStream] Allow dynamically pull AccountID from a secret #4586

Closed
martin31821 opened this issue May 30, 2023 · 2 comments · Fixed by #4588
Closed

[NATS JetStream] Allow dynamically pull AccountID from a secret #4586

martin31821 opened this issue May 30, 2023 · 2 comments · Fixed by #4588
Labels
feature-request All issues for new features that have not been committed to needs-discussion

Comments

@martin31821
Copy link
Contributor

Proposal

I propose a change to the Nats JetStream scaler, where the account ID can be specified from an external resource, such as a secret.

Use-Case

I'm running a NATS Cluster with several (dynamically created) tenants, running with a self-designed authentication server (github.com/deinstapel/nats-jwt-operator), where the Account IDs are not known in advance. My Operator dynamically creates NATS tenants and accounts with a kubernetes CRD and writes the account IDs into the .status of the CRD as well as to a secret.

I would like to be able to tell KEDA to scale based on these accounts, so I can include KEDA in my CD pipeline.

Is this a feature you are interested in implementing yourself?

Yes

Anything else?

Example:

Currently existing code:

triggers:
- type: nats-jetstream
  metadata:
    natsServerMonitoringEndpoint: "nats.nats.svc.cluster.local:8222"
    account: "$G"

Possible new implementation:

triggers:
- type: nats-jetstream
  metadata:
    natsServerMonitoringEndpoint: "nats.nats.svc.cluster.local:8222"
    accountRef:
      secretName: "my-accountSecret"
      secretKey: "account-id"
@martin31821 martin31821 added feature-request All issues for new features that have not been committed to needs-discussion labels May 30, 2023
@JorTurFer
Copy link
Member

JorTurFer commented May 30, 2023

Hi,
This is almost ready 😄
From KEDA pov, this is already implemented through TriggerAuthentication/ClusterTriggerAuthentication. Using one of them, you can read a secret and get the key.

Right now, NATS JetStream scaler doesn't read that value from TriggerAuthentication/ClusterTriggerAuthentication but it can be done changing this code:

	if config.TriggerMetadata["account"] == "" {
		return meta, errors.New("no account name given")
	}
	meta.account = config.TriggerMetadata["account"]

with this:

	account, err := GetFromAuthOrMeta(config, "account")
	if err != nil {
		return meta, err
	}
	meta.account = account

and obviously adding at least a unit test. From documentation pov, we should update it too

Are you willing to contribute with the feature?

@martin31821
Copy link
Contributor Author

Sounds good, will prepare a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request All issues for new features that have not been committed to needs-discussion
Projects
Status: Ready To Ship
Development

Successfully merging a pull request may close this issue.

2 participants