bouncer/internal/setup/integrations.go
William Petit 83fcb9a39d
All checks were successful
Cadoles/bouncer/pipeline/head This commit looks good
feat: add limited retry mechanism to prevent startup error if redis is not ready
2024-04-05 10:30:34 +02:00

47 lines
1.7 KiB
Go

package setup
import (
"context"
"time"
"forge.cadoles.com/cadoles/bouncer/internal/config"
"forge.cadoles.com/cadoles/bouncer/internal/integration"
"forge.cadoles.com/cadoles/bouncer/internal/integration/kubernetes"
"forge.cadoles.com/cadoles/bouncer/internal/lock/redis"
"github.com/pkg/errors"
)
func SetupIntegrations(ctx context.Context, conf *config.Config) ([]integration.Integration, error) {
integrations := make([]integration.Integration, 0)
if conf.Integrations.Kubernetes.Enabled {
kubernetes, err := setupKubernetesIntegration(ctx, conf)
if err != nil {
return nil, errors.Wrap(err, "could not setup kubernetes integration")
}
integrations = append(integrations, kubernetes)
}
return integrations, nil
}
func setupKubernetesIntegration(ctx context.Context, conf *config.Config) (*kubernetes.Integration, error) {
client := newRedisClient(conf.Redis)
locker := redis.NewLocker(client, 10)
integration := kubernetes.NewIntegration(
kubernetes.WithReaderTokenSecret(string(conf.Integrations.Kubernetes.ReaderTokenSecret)),
kubernetes.WithReaderTokenSecretNamespace(string(conf.Integrations.Kubernetes.ReaderTokenSecretNamespace)),
kubernetes.WithWriterTokenSecret(string(conf.Integrations.Kubernetes.WriterTokenSecret)),
kubernetes.WithWriterTokenSecretNamespace(string(conf.Integrations.Kubernetes.WriterTokenSecretNamespace)),
kubernetes.WithPrivateKeySecret(string(conf.Integrations.Kubernetes.PrivateKeySecret)),
kubernetes.WithPrivateKeySecretNamespace(string(conf.Integrations.Kubernetes.PrivateKeySecretNamespace)),
kubernetes.WithIssuer(string(conf.Admin.Auth.Issuer)),
kubernetes.WithLocker(locker),
kubernetes.WithLockTimeout(time.Duration(conf.Integrations.Kubernetes.LockTimeout)),
)
return integration, nil
}