84 lines
2.4 KiB
Go
84 lines
2.4 KiB
Go
package configmap
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
zitadelv1alpha1 "bitbucket.org/topmanage-software-engineering/zitadel-k8s-operator/src/api/v1alpha1"
|
|
builder "bitbucket.org/topmanage-software-engineering/zitadel-k8s-operator/src/pkg/builder"
|
|
"bitbucket.org/topmanage-software-engineering/zitadel-k8s-operator/src/pkg/deployment"
|
|
"bitbucket.org/topmanage-software-engineering/zitadel-k8s-operator/src/pkg/masterkey"
|
|
crdbv1alpha1 "github.com/cockroachdb/cockroach-operator/apis/v1alpha1"
|
|
corev1 "k8s.io/api/core/v1"
|
|
"k8s.io/apimachinery/pkg/types"
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
)
|
|
|
|
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.ZitadelCluster, crdb *crdbv1alpha1.CrdbCluster, base64key string) error {
|
|
config := make(map[string]string)
|
|
config["zitadel-config-yaml"] =
|
|
fmt.Sprintf(`
|
|
Database:
|
|
Cockroach:
|
|
Host: %s
|
|
User:
|
|
Username: root
|
|
SSL:
|
|
Mode: verify-full
|
|
Admin:
|
|
SSL:
|
|
Mode: verify-full
|
|
ExternalDomain: %s
|
|
ExternalPort: %d
|
|
ExternalSecure: %t
|
|
TLS:
|
|
Enabled: false
|
|
Projections:
|
|
Customizations:
|
|
smtp_configs:
|
|
BulkLimit: 2000
|
|
SystemAPIUsers:
|
|
- %s:
|
|
KeyData: %s
|
|
Memberships:
|
|
- MemberType: System
|
|
Roles:
|
|
- "SYSTEM_OWNER"
|
|
- "IAM_OWNER"
|
|
- "ORG_OWNER"
|
|
`, deployment.ServiceFQDNWithService(crdb.ObjectMeta, crdb.Name), zitadel.Spec.Host, zitadel.Spec.ExternalPort, zitadel.Spec.ExternalSecure, masterkey.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
|
|
}
|