Skip to content
Open
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
32 changes: 18 additions & 14 deletions internal/controller/controllerconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,23 @@ func (r *ControllerConfigReconciler) Reconcile(ctx context.Context, req ctrl.Req
}
}

// initialize LDAP client and cache if configured
// initialize cache client (used for LDAP and group membership caching)
if CacheClient == nil {
cc, err := pkgcache.New(&pkgcache.Config{
Driver: pkgcache.DriverMemory,
InMemory: &inmemory.Config{
DefaultExpiration: -1,
CleanupInterval: -1,
},
})
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed to create cache client: %w", err)
}
CacheClient = cc
logger.Info("Cache client initialized")
}

// initialize LDAP client if configured
if config.Spec.LDAPConfig != nil && config.Spec.LDAPConfig.Server != "" {
ldapCfg := *config.Spec.LDAPConfig
lc, err := ldap.InitLDAP(ldap.Config{
Expand All @@ -156,19 +172,7 @@ func (r *ControllerConfigReconciler) Reconcile(ctx context.Context, req ctrl.Req
return ctrl.Result{RequeueAfter: 10 * time.Second}, nil
}
LDAPClient = lc

cc, err := pkgcache.New(&pkgcache.Config{
Driver: pkgcache.DriverMemory,
InMemory: &inmemory.Config{
DefaultExpiration: -1,
CleanupInterval: -1,
},
})
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed to create cache client: %w", err)
}
CacheClient = cc
logger.Info("LDAP client and cache initialized")
logger.Info("LDAP client initialized")
}

GoogleDriveControllerCfg = config.Spec.GoogleDriveConfig
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/sourcecrawler_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"net/url"
"os"
"strings"
"time"

Expand Down Expand Up @@ -221,7 +222,7 @@ func (r *SourceCrawlerReconciler) buildGDriveSource(
return nil, fmt.Errorf("failed to create google client: %w", err)
}

if LDAPClient == nil {
if LDAPClient == nil && os.Getenv("CURRENT_ENV") != "e2e-test" {
return nil, errors.New("LDAP client not initialized in ControllerConfig")
}
if CacheClient == nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/gdrive/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (c *Client) GetFilePermissions(
logger.V(1).Info("user LDAP data found in cache",
"email", p.EmailAddress,
)
} else {
} else if c.ldapClient != nil {
// Cache miss - query LDAP
userData, err := c.ldapClient.GetUserByEmail(
ctx, p.EmailAddress)
Expand Down
Loading
Loading