Some checks failed
Build and Publish / build-release (push) Failing after 26s
93 lines
2.6 KiB
Go
93 lines
2.6 KiB
Go
package configmap
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
zitadelv1alpha1 "gitea.corredorconect.com/software-engineering/zitadel-k8s-operator/api/v1alpha1"
|
|
builder "gitea.corredorconect.com/software-engineering/zitadel-k8s-operator/pkg/builder"
|
|
"gitea.corredorconect.com/software-engineering/zitadel-k8s-operator/pkg/deployment"
|
|
systemapiaccount "gitea.corredorconect.com/software-engineering/zitadel-k8s-operator/pkg/systemapi"
|
|
corev1 "k8s.io/api/core/v1"
|
|
"k8s.io/apimachinery/pkg/types"
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
|
|
cloudnativepgv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1"
|
|
)
|
|
|
|
type ConfigMapReconciler struct {
|
|
client.Client
|
|
Builder *builder.Builder
|
|
}
|
|
|
|
func NewConfigMapReconciler(client client.Client, builder *builder.Builder) *ConfigMapReconciler {
|
|
return &ConfigMapReconciler{
|
|
Client: client,
|
|
Builder: builder,
|
|
}
|
|
}
|
|
|
|
func (r *ConfigMapReconciler) ReconcileZitadelConfiguration(ctx context.Context, key types.NamespacedName, zitadel *zitadelv1alpha1.Cluster, postgres *cloudnativepgv1.Cluster, base64key string) error {
|
|
config := make(map[string]string)
|
|
config["zitadel-config-yaml"] =
|
|
fmt.Sprintf(`Database:
|
|
Postgres:
|
|
Host: %s
|
|
Port: 5432
|
|
Database: zitadel
|
|
MaxOpenConns: 20
|
|
MaxIdleConns: 10
|
|
MaxConnLifetime: 30m
|
|
MaxConnIdleTime: 5m
|
|
User:
|
|
Username: zitadel
|
|
SSL:
|
|
Mode: disable
|
|
Admin:
|
|
Username: postgres
|
|
SSL:
|
|
Mode: disable
|
|
ExternalDomain: %s
|
|
ExternalPort: %d
|
|
ExternalSecure: %t
|
|
TLS:
|
|
Enabled: false
|
|
Projections:
|
|
Customizations:
|
|
smtp_configs:
|
|
BulkLimit: 2000
|
|
FirstInstance:
|
|
Skip: true
|
|
SystemAPIUsers:
|
|
- %s:
|
|
KeyData: %s
|
|
Memberships:
|
|
- MemberType: System
|
|
Roles:
|
|
- "SYSTEM_OWNER"
|
|
- "IAM_OWNER"
|
|
- "ORG_OWNER"
|
|
`, deployment.ServiceFQDNWithService(postgres.ObjectMeta, postgres.Name+"-rw"), zitadel.Spec.Host, zitadel.Spec.ExternalPort, zitadel.Spec.ExternalSecure, systemapiaccount.OwnerName, base64key)
|
|
|
|
opts := builder.ConfigMapOpts{
|
|
Zitadel: zitadel,
|
|
Key: key,
|
|
Immutable: false,
|
|
Data: config,
|
|
}
|
|
configmap, err := r.Builder.BuildConfigMap(opts, zitadel)
|
|
if err != nil {
|
|
return fmt.Errorf("error building replication password ConfigMap: %v", err)
|
|
}
|
|
var existingConfigMap corev1.ConfigMap
|
|
if err := r.Get(ctx, key, &existingConfigMap); err == nil {
|
|
patch := client.MergeFrom(existingConfigMap.DeepCopy())
|
|
existingConfigMap.Data = configmap.Data
|
|
return r.Patch(ctx, &existingConfigMap, patch)
|
|
}
|
|
if err := r.Create(ctx, configmap); err != nil {
|
|
return fmt.Errorf("error creating replication password ConfigMap: %v", err)
|
|
}
|
|
return nil
|
|
}
|