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

feat(dex): use postgresql as backend #839

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open

feat(dex): use postgresql as backend #839

wants to merge 28 commits into from

Conversation

kengou
Copy link
Contributor

@kengou kengou commented Jan 9, 2025

Description

What type of PR is this? (check all applicable)

  • πŸ• Feature
  • πŸ› Bug Fix
  • πŸ“ Documentation Update
  • 🎨 Style
  • πŸ§‘β€πŸ’» Code Refactor
  • πŸ”₯ Performance Improvements
  • βœ… Test
  • πŸ€– Build
  • πŸ” CI
  • πŸ“¦ Chore (Release)
  • ⏩ Revert

Related Tickets & Documents

Added tests?

  • πŸ‘ yes
  • πŸ™… no, because they aren't needed
  • πŸ™‹ no, because I need help
  • Separate ticket for tests # (issue/pr)

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Added to documentation?

  • πŸ“œ README.md
  • 🀝 Documentation pages updated
  • πŸ™… no documentation needed
  • (if applicable) generated OpenAPI docs for CRD changes

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes

pkg/controllers/organization/dex.go Outdated Show resolved Hide resolved
pkg/controllers/organization/dex.go Outdated Show resolved Hide resolved
pkg/controllers/organization/dex.go Outdated Show resolved Hide resolved
pkg/controllers/organization/dex.go Outdated Show resolved Hide resolved
cmd/greenhouse/main.go Outdated Show resolved Hide resolved
cmd/greenhouse/main.go Outdated Show resolved Hide resolved
@kengou kengou requested a review from a team as a code owner January 16, 2025 13:21
@kengou kengou requested a review from a team as a code owner January 29, 2025 13:41
"github.com/cloudoperators/greenhouse/pkg/clientutil"
)

func GetOFClient(appName string) *openfeature.Client {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be helpful to have some context to what this client does. Maybe something like this?

Suggested change
func GetOFClient(appName string) *openfeature.Client {
// NewClient returns a open-feature client loading feature flags from a ConfigMap
func NewClient(appName string) *openfeature.Client {

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, we are not finished fully with this PR, will do some meaningful commenting into the new functions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added some comments to the code and renamed the func to better correlate in 4baeee0

}

goFeatureFlagConfig := &goffclient.Config{
PollingInterval: 30 * time.Second,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the polling continuously? In that case we could set the value very high, as this is only evaluated during startup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

30 * time.Minutes sounds better ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

increased in 42393b6

Comment on lines 77 to 103
evalCtx := openfeature.NewEvaluationContext(
"backend",
map[string]interface{}{},
)
postgresBackend, err := ofClient.BooleanValue(context.TODO(), "dex-sql-backend", false, evalCtx)
if err != nil {
log.Fatalf("Failed to initialize kubernetes storage: %s", err)
log.Fatalf("Failed to get dex-sql-backend value details: %s", err)
}

k8sBackend, err := ofClient.BooleanValue(context.TODO(), "dex-kubernetes-backend", false, evalCtx)
if err != nil {
log.Fatalf("Failed to get dex-kubernetes-backend value details: %s", err)
}

switch {
case postgresBackend:
dexStorage, err = idproxy.NewPostgresStorage(sql.SSL{Mode: "disable"}, postgresDB, logger.With("component", "storage"))
if err != nil {
log.Fatalf("Failed to initialize postgres storage: %s", err)
}
case k8sBackend:
dexStorage, err = idproxy.NewKubernetesStorage(kubeconfig, kubecontext, kubenamespace, logger.With("component", "storage"))
if err != nil {
log.Fatalf("Failed to initialize kubernetes storage: %s", err)
}
default:
log.Fatalf("Exactly one of dex-sql-backend or dex-kubernetes-backend must be true")
Copy link
Contributor

Choose a reason for hiding this comment

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

We have two flags for the same feature but only one may be toggled. Would it be possible to combine them into one flag with the value for either k8s or postgres?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not easily with this feature-flag

Comment on lines 95 to 96
if oidcConnector, err = r.dexStorage.GetConnector(org.Name); err != nil {
if err = r.dexStorage.CreateConnector(ctx, storage.Connector{
Copy link
Contributor

Choose a reason for hiding this comment

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

The error from line 95 must not always be a NotFound error. Directly trying to create a new connector could then lead to AlreadyExists error but obscurring the underlying issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in 7476913

Comment on lines 149 to 150
if oAuthClient, err = r.dexStorage.GetClient(org.Name); err != nil {
if err = r.dexStorage.CreateClient(ctx, storage.Client{
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above w.r.t. obscuring the error condition

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in 7476913

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants