Initial commit
[ZITADOPER-1]
This commit is contained in:
72
src/pkg/controller/configmap/controller.go
Normal file
72
src/pkg/controller/configmap/controller.go
Normal file
@@ -0,0 +1,72 @@
|
||||
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
|
||||
ExternalDomain: %s
|
||||
ExternalPort: %d
|
||||
ExternalSecure: %t
|
||||
TLS:
|
||||
Enabled: false
|
||||
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: true,
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user